I have a dataframe that looks like this -
P_id Sim no_of_occurance
0 1 0.00 4
1 2 0.25 3
2 3 0.25 5
3 4 0.25 5
4 5 0.25 6
5 6 0.25 4
6 7 0.50 6
7 8 0.50 2
8 9 0.50 5
9 10 0.25 4
10 11 0.25 6
11 12 0.50 4
12 13 0.50 4
13 14 0.25 4
I want to sort P_id based on the corresponding descending values in Sim' column for each row and for rows where Sim values are same, I want that P_id to come first whose no_of_occurance is higher.
Desired output-
P_id Sim no_occurance
7 0.50 6
9 0.50 5
12 0.50 4
13 0.50 4
8 0.50 2
5 0.25 6
11 0.25 6
.
.
.
pandas.DataFrame.sort_values. Here is a link