Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert index to column pandas dataframe

I have following 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  

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?

like image 956
Safariba Avatar asked Jun 27 '17 06:06

Safariba


1 Answers

Need assign output back or inplace=True parameter:

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
like image 126
jezrael Avatar answered Sep 23 '22 14:09

jezrael