Reputation: 23
I'm using sort_values() to sort values in a pandas Series from largest to smallest. I wonder if there is an easy way of randomizing the order of ties(?). It appears that the indexes of ties come in the descending order given as argument in this case:
s = pd.Series([3.0, 15.0, 1.0, 22.0, 11.0, 12.0, 2.0, 5.0, 3.0, 12.0, 2.0, 3.0])
s.sort_values(ascending=False)
Out:
3 22.0
1 15.0
9 12.0
5 12.0
4 11.0
7 5.0
11 3.0
8 3.0
0 3.0
10 2.0
6 2.0
2 1.0
I have read the documentation that there are different kinds of sort that can be given as argument: ‘quicksort’, ‘mergesort’, ‘heapsort’. However, as far as I understand none of them will randomize the order of ties.
I guess I could write a custom function, but curious to know if something exists.
Upvotes: 2
Views: 510