Python 将索引转换为列数据帧
我有以下数据帧:Python 将索引转换为列数据帧,python,pandas,dataframe,Python,Pandas,Dataframe,我有以下数据帧: | id | LocTime |ZPos | XPos datetime | 2017-01-02 00:14:39 |20421902611| 12531245409231| 0 | -6 2017-01-02 00:14:40 |30453291020| 28332479673070| 0 | -2
| id | LocTime |ZPos | XPos
datetime |
2017-01-02 00:14:39 |20421902611| 12531245409231| 0 | -6
2017-01-02 00:14:40 |30453291020| 28332479673070| 0 | -2
我想将日期时间索引转换为数据帧的列。
我尝试了df.reset_index(level=['datetime'])
,但结果没有改变。
有什么想法吗 需要将输出分配回原位或
inplace=True
参数:
df = df.reset_index()
df.reset_index(inplace=True)
print (df)
datetime id LocalTime ZPosition XPosition
0 2017-01-02 00:14:39 10453190861 1483312478909238 0 -9
1 2017-01-02 00:14:40 10453191020 1483312479673076 0 -8