How do I change order/grouping/level of pandas MultiIndex columns?

前端 未结 2 866
天涯浪人
天涯浪人 2021-01-31 16:40

I\'m trying to reorder/swaplevel/pivot/something columns in a pandas dataframe. The columns are a MultiIndex, but I can\'t find the sauce to do what I want.

The fastest

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-31 17:08

    Since levels indices are no more mandatory you can have even more simple way to achieve the level swapping of multi-index dataframe:

    df = df.swaplevel(axis='columns')
    

提交回复
热议问题