I have a Pandas DataFrame like this
df = pd.DataFrame(
{
'OrderID': ['o1','o2','o3','o4','o5'],
'CustomerID': ['c1','c1','c2','c2','c3'],
'CustomerRating': [5,1,3, NaN,NaN]
}
)
I want to sort it by CustomerID first, and then by CustomerRating and in a such way that NaNs in Customer Rating come last. I know about the df.sort_values(na_position = 'last'), but that just works for the primary sort. How do I make it work for the secondary sort?
So just like I specify ascending argument as a list where each element corresponds to one sort level, I need something similar for na_position argument, so something like this:
df.sort_values(['CustomerID', 'CustomerRating', ascending = [False, False], na_position =['last', 'last']]
How do I do it?
Thanks