pandas pivot_table column names

Using clues from @chrisb’s answer, this gave me exactly what I was after:

df2.reset_index(inplace=True)

which gives:

id     Cost1    Cost2     Cost3 Value1   Value2   Value3   
1       124      214      1234    12        23       15
2      1324       0       234     45         0       34

and in case of multiple index columns, this post explains it well. just to be complete, here is how:

df2.columns = [' '.join(col).strip() for col in df2.columns.values]

Leave a Comment