I have a pandas dataframe like:
I have the data frame as like below one,
Input DataFrame
id ratio
0 1 5.00%
1 2 9.00%
2 3 6.00%
3 2 13.00%
4 1 19.00%
5 4 30.00%
6 3 5.5%
7 2 22.00%
How can I then group this like
id ratio
0 1 5.00%
4 1 19.00%
6 3 5.5%
2 3 6.00%
1 2 9.00%
3 2 13.00%
7 2 22.00%
5 4 30.00%
So essentially first looks at the ratio, takes the lowest for that value and groups the rest of the rows for which it has the same id. Then looks for the second lowest ratio and groups the rest of the ids again etc.