daysago line_race rating rw wrating
line_date
2007-03-31 62 11 56 1.000000 56.000000
2007-03-10 83 11 67 1.000000 67.000000
2007-02-10 111 9 66 1.000000 66.000000S
我正在对 pandas.dataframe 进行分析,最后我得到了一个数据框 df,如上所示。
我想同时显示 line_date 和 rating。我想做一个 df['line_date','rating']
但我做不到,因为 line_date 在技术上位于第二行。
我如何将 line_date 推到像其他行一样的第一个标题行?
我的理想输出:
line_date daysago line_race rating rw wrating
2007-03-31 62 11 56 1.000000 56.000000
2007-03-10 83 11 67 1.000000 67.000000
2007-02-10 111 9 66 1.000000 66.000000S
直觉上,我会删除第 2 行,这样数据就会刷新到标题正下方的顶部,然后我将更改第 0 列的名称。 有更好的方法吗?
最佳答案
这不是真正的两行。左列“第二行”的'line_date'
实际上是被索引的列名。
试试df.reset_index()
(假设你的DataFrame是df
); df.reset_index(inplace=True)
会就地修改它(正如参数所暗示的那样)。
关于python - Pandas 数据框 : Removing redundant rows in headers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35777748/