問題:
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