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

Time:12-07

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

CodePudding user response:

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
  • Related