将索引转换为列Pandas数据框

16

我有以下的Pandas数据框:

                    |     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']),但结果没有改变。 有什么想法吗?

我想要将日期时间索引转化为数据框的一列。我尝试了df.reset_index(level=['datetime']),但是结果并没有改变。你有任何想法吗?

1个回答

37

需要将输出赋回或使用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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接