Pandas GroupBy Rank, Is Revisited to Build Pricing Intelligence

A step by step guide to use pandas in exploratory data analysis

When a retail store follows a value-based pricing technique, it always ensures that the products having better features and ratings are always priced higher than their close alternatives, irrespective of their brand and model.

Pandas GroupBy Rank

As the name suggests, the Rank method provides the rank of an element in a numeric series. Let’s see with an example, how we can leverage this method in implementing value-based pricing.

The dataframe contains the list of products of various brands and models. Against each product mentioned are its price in dollars and the feature score. An expert looks into the features of each product and assigns a numeric score. A higher feature score means that the printer has better features like wifi connectivity, duplex printing, etc.

Present Price

Now the task is to make sure that the printers having better features are always priced higher than the other printers. Irrespective of the brand and the model.

It’s a four-step process

  1. First group by the product title.
  2. Calculate the price rank of the product.
  3. Then calculate the feature rank of the product.
  4. Now compare both the price rank and the feature rank, for each product.
Source Code

Ideally, both the ranks should be the same. Indicating that the current pricing is already following the value-based pricing model. High price for better features, low price for lower features.

But it’s not ideal. So you’ve to suggest where changes are required.

Generate suggestions

Wherever you see the price rank is better than the feature rank, which means that the product is overpriced. Customers may not opt to buy this product as there are better alternatives. So, suggest the store manager decrease the price. By the way, a better rank means the numeric value of the rank is low.

On the other hand, if the price rank is inferior to the feature rank, that indicates there is a leak in the profit margin. The product has more potential to be sold at a higher price because the customers will be willing to pay more price to this product than its close alternatives.

Upon adding the ranks and suggestions now the final dataframe would look like this:

Ranks Compared and Price Changes Recommended


That makes our pricing exploration complete. It validates the current price against the value-based pricing strategy and concludes by providing suggestions on price alignment.

What Next?

If you would like to share your use case, relevant to this discussion, please send the details to Our editorial team will get in touch to add your contribution to this story.

An example speaks a thousand paragraphs. Let’s build together a new generation of fast learners.

Also Read

Practical Guide to GroupBy Aggregate in Pandas: Solving a Retail Problem

An Excellent Method for Instant Data Transformation, DF GroupBy Transform

Write a Comment