I have a Series that looks like:
146tf150p 1.000000
havent 1.000000
home 1.000000
okie 1.000000
thanx 1.000000
er 1.000000
anything 1.000000
lei 1.000000
nite 1.000000
yup 1.000000
thank 1.000000
ok 1.000000
where 1.000000
beerage 1.000000
anytime 1.000000
too 1.000000
done 1.000000
645 1.000000
tick 0.980166
blank 0.932702
dtype: float64
I would like to order it by value, but also by index. So I would have smallest numbers at top but respecting the alphabetical order of the indexes.
duplicated() function Indicate duplicate index values. Duplicated values are indicated as True values in the resulting array. Either all duplicates, all except the first, or all except the last occurrence of duplicates can be indicated.
pandas Series. sort_values() function is used to sort values on Series object. It sorts the series in ascending order or descending order, by default it does in ascending order. You can specify your preference using the ascending parameter which is True by default.
To sort by index / columns (row/column names), use the sort_index() method.
Use np.lexsort
to get the ordered positions and pass to iloc
ser.iloc[np.lexsort([ser.index, ser.values])]
blank 0.932702
tick 0.980166
146tf150p 1.000000
645 1.000000
anything 1.000000
anytime 1.000000
beerage 1.000000
done 1.000000
er 1.000000
havent 1.000000
home 1.000000
lei 1.000000
nite 1.000000
ok 1.000000
okie 1.000000
thank 1.000000
thanx 1.000000
too 1.000000
where 1.000000
yup 1.000000
dtype: float64
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With