Home > Blockchain >  How to add a new column rank on based on increasing value of other column in Pandas
How to add a new column rank on based on increasing value of other column in Pandas

Time:03-28

I have this dataframe with which i am trying to create a new column rank on basis of increasing values of column Opportunity with pandas

State   Brand       DYA     Opportunity
Delhi   Pampers     -8.58   -1.24139
Delhi   Ariel       0.53    0.04800
Delhi   Fusion      0.68    0.00492
Delhi   Gillette    1.56    0.02073

required output --

State   Brand       DYA     Opportunity Rank
Delhi   Pampers     -8.58   -1.24139     1
Delhi   Ariel       0.53    0.04800      4      
Delhi   Fusion      0.68    0.00492      2
Delhi   Gillette    1.56    0.02073      3

CodePudding user response:

You can use rank function:

df['Rank'] = df['Opportunity'].rank()

enter image description here

  • Related