The rank() function returns a DataFrame with the rank of each value that was estimated along the specified axis. Ranking takes place in ascending order by default:
sales_df.rank()
The following is the output:
Ranking function result
The rank() method can be applied as shown here:
sales_df.rank(ascending = False)
The following is the output:
Ranking in descending order
Ranking can also be obtained as a percentage, as shown here:
sales_df.rank(pct = True)
The following is the output:
Ranking with percentiles
The method() argument helps settle ties. By default, the average of the range of ranks that could possibly be occupied by items in a tie is shown in the result. It can also be modified to show the minimum rank, maximum rank, the order in which values appear, or dense ranking:
sales_df.rank(method = "min")
The following is the output:
Using the ranking method to find the minimum value for a tiebreaker