How to remove levels from a multi-indexed dataframe?

前端 未结 3 503
温柔的废话
温柔的废话 2020-12-04 10:38

For example, I have:

In [1]: df = pd.DataFrame([8, 9],
                          index=pd.MultiIndex.from_tuples([(1, 1, 1),
                                         


        
3条回答
  •  独厮守ぢ
    2020-12-04 11:11

    If your index has names like

           A
    X Y Z
    1 1 1  8
      3 2  9
    

    Then you can also remove by specifying the index name

    df.index = df.index.droplevel(Z)

提交回复
热议问题