pythonbeginner

Pandas Rank with Tie-Breaking Methods

Apply different ranking strategies (min, dense, average) and handle ties in pandas.

python
import pandas as pd

df = pd.DataFrame({'name':['Alice','Bob','Carol','Dave','Eve'],'score':[90,85,90,75,85]})

for method in ['average','min','max','dense','first']:
    df[f'rank_{method}'] = df['score'].rank(method=method, ascending=False)

print(df)

Use Cases

  • leaderboards
  • percentile ranking
  • competition scoring

Tags

Related Snippets

Similar patterns you can reuse in the same workflow.