I would like to sort a multi-index pandas dataframe by a column, but do not want the entire dataframe to be sorted at once. But rather would like to sort by one of the indices. Here is an example of what I mean: Below is an example of a multi-index dataframe.
first second
bar one 0.361041
two 0.476720
baz one 0.565781
two 0.848519
foo one 0.405524
two 0.882497
qux one 0.488229
two 0.303862
What I want to do is to get the following:
first second
bar one 0.476720
two 0.361041
baz one 0.848519
two 0.565781
foo one 0.882497
two 0.405524
qux one 0.488229
two 0.303862
These are generated by hand to show what I want. Notice that the second dataframe is not completely sorted. But within each multi-index, it is sorted in descending order. I have a large dataframe. Is there a simpler way of do it (such as a function) instead of grouping the dataframe based on the indices, and then concatenate the individually sorted dataframes.