Turn Pandas Multi-Index into column

后端 未结 5 1991
天涯浪人
天涯浪人 2020-11-29 16:52

I have a dataframe with 2 index levels:

                         value
Trial    measurement
    1              0        13
                   1         3
            


        
5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-29 17:05

    The reset_index() is a pandas DataFrame method that will transfer index values into the DataFrame as columns. The default setting for the parameter is drop=False (which will keep the index values as columns).

    All you have to do add .reset_index(inplace=True) after the name of the DataFrame:

    df.reset_index(inplace=True)  
    

提交回复
热议问题