dense rank in pandas code example Example: dense rank in pandas df['Rank'] = df.Year.rank(method='dense').astype(int) df