我有一个带多重索引的数据帧。这些列看起来像:
示例Df:
index date Text Text Text Text Text
OtherText OtherText1 OtherText1 OtherText1 OtherText1 OtherText1
Col Col1 Col2 Col3 Col4 Col5
0 17-Jun-14 1 2 3 4 5
要创建的代码:
^{pr2}$列名:
[('date', '', ''),
('text', 'somemoretext', 'Col1'),
('text', 'somemoretext', 'Col2'),
('text', 'somemoretext', 'Col3')...]
我想要么重命名,要么交换第一列的级别。这不会产生错误,但也不会更改列。在
df.rename(columns={"('date', '', '')" : "('', '' 'date')"}, inplace=True)
如何重新排序和/或重命名多重索引中的特定列?在
期望输出:
index Text Text Text Text Text
OtherText OtherText1 OtherText1 OtherText1 OtherText1 OtherText1
Col date Col1 Col2 Col3 Col4 Col5
0 17-Jun-14 1 2 3 4 5
你能做到的。在
我不知道为什么要用这种方式使用多索引列。好吧。在
相关问题 更多 >
编程相关推荐