Sepehr
Sepehr

Reputation: 452

Reshaping a pandas pivoted dataframe

I have the following pivoted dataframe:

variable           A         B         C         D
date                                              
2000-01-03  0.469112 -1.135632  0.119209 -2.104569
2000-01-04 -0.282863  1.212112 -1.044236 -0.494929
2000-01-05 -1.509059 -0.173215 -0.861849  1.071804

How can I convert it to a new dataframe of the following format:

date           A         B         C         D
2000-01-03  0.469112 -1.135632  0.119209 -2.104569
2000-01-04 -0.282863  1.212112 -1.044236 -0.494929
2000-01-05 -1.509059 -0.173215 -0.861849  1.071804

where "date" is not an index in the second dataframe. Any help is greatly appreciated.

I've read Trouble pivoting / reshaping a pandas dataframe but it didn't help.

Upvotes: 0

Views: 88

Answers (1)

hvedrung
hvedrung

Reputation: 467

Try reset the index

df.reset_index()

Upvotes: 2

Related Questions