Alex
Alex

Reputation: 167

Pandas -> DataFrame -> rank

I have the DataFrame, where I am trying to add a new "rank" column to determine the price rating relative to the "name" and "country" columns by comparing prices (column 'price'). But with no success. I need the following result, screenshot below. Help please, I will be grateful enter image description here

Upvotes: 0

Views: 168

Answers (1)

gtomer
gtomer

Reputation: 6564

Try this:

df['rank'] = df.groupby('name')['price'].rank(ascending=False)

Upvotes: 2

Related Questions