Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.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_Dataframe - Fatal编程技术网

Python 如何将数据帧转换为动态表

Python 如何将数据帧转换为动态表,python,pandas,dataframe,Python,Pandas,Dataframe,我使用多索引,根据优化结果生成以下数据帧: hour 0 1 2 Scenario plant 0 A 0,0831 0,08124 0,08124 B 0,5 0,5 0,5 C 0,4599 0,31246 0,16786 D 0 0 0 但是,由于我可能

我使用多索引,根据优化结果生成以下数据帧:

    hour         0       1        2
Scenario plant          
0        A       0,0831  0,08124  0,08124
         B       0,5     0,5      0,5
         C       0,4599  0,31246  0,16786
         D       0       0        0
但是,由于我可能希望在Excel中的透视表中转换它,因此最好在每一行中都有索引“Scenario”,如:

    hour         0       1        2
Scenario plant          
0        A       0,0831  0,08124  0,08124
0        B       0,5     0,5      0,5
0        C       0,4599  0,31246  0,16786
0        D       0       0        0

有人知道如何解决这个问题吗?

按照注释中的说明使用
.reset\u index()

您只需使用
.rest\u index()
即可