Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何展开多索引?_Python_Pandas_Multi Index - Fatal编程技术网

Python 如何展开多索引?

Python 如何展开多索引?,python,pandas,multi-index,Python,Pandas,Multi Index,我有一个多索引的数据帧,并且level=[0,1]似乎不起作用 MultiIndex([('Datetime', ''), ( 'Value', 'A'), ( 'Value', 'B')], names=[None, 'Col1']) Datetime Value Col1 A B 0

我有一个多索引的数据帧,并且level=[0,1]似乎不起作用

MultiIndex([('Datetime',    ''),
            (   'Value', 'A'),
            (   'Value', 'B')],
           names=[None, 'Col1'])



        Datetime               Value
Col1                           A          B
0       2017-10-14 00:00:00   -0.540774   0.870280
1       2017-10-14 01:00:00   -0.426617   0.720261
2       2017-10-14 02:00:00   -0.053588   0.746738
3       2017-10-14 03:00:00   0.318062    0.871044
4       2017-10-14 04:00:00   0.478168    1.060897
我尝试使用.reset_indexlevel=[0,1],正如在许多类似问题中建议的那样,但它不起作用。

df.columns=[col[1]if col[0]==else col[0]for col in df.columns]
您希望如何展平多索引*新索引是什么样子的?@HenryEcker我想得到Col1,Datetime,A,B:都在同一级别。所以完全删除值?@HenryEcker:是的。请显示用于设置多重索引的命令。还要说明.reset_indexlevel=[0,1]的结果是如何错误的,不要只是说它不起作用。否则这是不可复制的,对其他用户来说也不是很可重用的。您还可以对df.columns中的col执行df.columns=[col[1]或col[0]