I would like to sort the col2 in descending order based on col1. I have the feeling that the answer is very simple, but I can't find a correct way. I would appreciate a lot some help.
The dataframe looks like:
Col1 Col2 Col3
AB 5 Blue
AB 1 Red
AB 2 Green
AC 1 Red
AC 4 Blue
AD 9 Red
AD 5 Blue
AD 7 Green
The desired output:
Col1 Col2 Col3
AB 5 Blue
AB 2 Green
AB 1 Red
AC 4 Blue
AC 1 Red
AD 9 Red
AD 7 Green
AD 5 Blue
What I tried:
df = pd.read_csv('data.csv')
df.sort_values(['Col1','Col2'], ascending = False)
df.groupby(['Col1'])['Col2'].sort_values(ascending = False)
None of the above methods gives the desired output.