I want to sort a multi-index pandas dataframe by a column but don't want the entire dataframe to be sorted at once. But rather want 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
And What I want is:
first second
bar two 0.476720
one 0.361041
baz two 0.848519
one 0.565781
foo two 0.882497
one 0.405524
qux two 0.488229
one 0.303862
I want to sort the dataframe based on the third column i.e the numbers and keep the level 0 index constant. How can we do that?