I have a multiindexed pandas.Dataframe which is something like this:
BAZ PAL
Foo Bar
124 1 A B
2 C D
134 1 E F
2 G H
I need to swap level-one from index with columns in appropriate way. I need to end up with something like this:
124 134
Coo Bar
BAZ 1 A E
2 C G
PAL 1 B F
2 D H
You need to unstack your existing index level
Foo
, stack your desired column 'Coo', and then rearrange the index levels. After swapping your index levels, you probably want to sort it. As a final touch, you may want to drop the column name of all the values (val
).