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
JavaScript
x
6
1
State Brand DYA Opportunity
2
Delhi Pampers -8.58 -1.24139
3
Delhi Ariel 0.53 0.04800
4
Delhi Fusion 0.68 0.00492
5
Delhi Gillette 1.56 0.02073
6
required output —
JavaScript
1
6
1
State Brand DYA Opportunity Rank
2
Delhi Pampers -8.58 -1.24139 1
3
Delhi Ariel 0.53 0.04800 4
4
Delhi Fusion 0.68 0.00492 2
5
Delhi Gillette 1.56 0.02073 3
6
Advertisement
Answer
You can use rank
function:
JavaScript
1
2
1
df['Rank'] = df['Opportunity'].rank()
2