Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Two row header to one row header for a data frame in Pandas, most simple way

I have this Python Pandas Dataframe:

             OBS_VALUE         Y_MA
TIME_PERIOD                        
2000-W02          1698  1654.500000
2000-W03          1578  1629.000000
2000-W04          1520  1601.750000
2000-W05          1429  1567.200000

I am looking for the most simple way to get:

TIME_PERIOD  OBS_VALUE         Y_MA                        
2000-W02          1698  1654.500000
2000-W03          1578  1629.000000
2000-W04          1520  1601.750000
2000-W05          1429  1567.200000

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try this:

df = df.reset_index(drop=False)

Output:

>>> df
  TIME_PERIOD  OBS_VALUE     Y_MA
0    2000-W02       1698  1654.50
1    2000-W03       1578  1629.00
2    2000-W04       1520  1601.75
3    2000-W05       1429  1567.20
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading