將 Pandas Multi-Index 轉成列 - Turn Pandas Multi-Index into column

問題:

I have a dataframe with 2 index levels:我有一個具有 2 個索引級別的數據框:

                         value
Trial    measurement
    1              0        13
                   1         3
                   2         4
    2              0       NaN
                   1        12
    3              0        34 

Which I want to turn into this:我想變成這個:

Trial    measurement       value

    1              0        13
    1              1         3
    1              2         4
    2              0       NaN
    2              1        12
    3              0        34 

How can I best do this?我怎樣才能最好地做到這一點?

I need this because I want to aggregate the data as instructed here , but I can't select my columns like that if they are in use as indices.我需要這個,因爲我想按照此處的說明聚合數據,但如果它們用作索引,我無法選擇這樣的列。


解決方案:

參考一: https://en.stackoom.com/question/1MNZa
參考二: https://stackoom.com/question/1MNZa
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章