将索引转换为列pandas数据框 [英] convert index to column pandas dataframe

查看:110
本文介绍了将索引转换为列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']),但结果没有改变. 任何的想法?

I want to convert datetime index to column of the data frame. I tried df.reset_index(level=['datetime']) but the result does not change. any idea?

推荐答案

需要分配输出或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

这篇关于将索引转换为列pandas数据框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆