Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.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 将未堆叠的dataframe转换为pandas中的dataframe_Python_Pandas - Fatal编程技术网

Python 将未堆叠的dataframe转换为pandas中的dataframe

Python 将未堆叠的dataframe转换为pandas中的dataframe,python,pandas,Python,Pandas,我有一个如下所示的数据帧: 此数据帧是取消堆叠另一个数据帧的结果 cost 10 20 30 ------------------------------------------- cycles -------------------------------------------- 1 2 4 6 2 1 2

我有一个如下所示的数据帧:

此数据帧是取消堆叠另一个数据帧的结果

cost                 10        20        30
-------------------------------------------
cycles
--------------------------------------------
1                     2         4         6
2                     1         2         3
3                     3         6         9
4                     1         0         5
我想要这样的东西:

cycles                10        20        30
-----------------------------------------------
1                     2         4         6
2                     1         2         3
3                     3         6         9
4                     1         0         5
我对在未堆叠的数据帧中旋转有点困惑。我浏览了其他几个类似的帖子,但我真的不明白。我希望在此数据帧的每一列上执行回归。我认为在第一个数据帧中访问cycles列是很困难的,因此如果有人能对此有所了解,我将不胜感激。提前谢谢

你想要这个吗

df.reset_index()
编辑:要删除轴名称
成本
,您需要使用:

df.rename_axis(None, axis=1).reset_index()
这仍然会返回一个索引,这正是pandas的工作方式,但它不会有一个标签漂浮在上面。如果您想将
周期
作为没有
成本
的索引,您可以使用第一部分:

df.rename_axis(None, axis=1)

:这肯定管用。但在这种情况下,索引列将是“成本”。还有什么我能处理掉的吗?