pandas pivot_table column names pandas pivot_table column names python python

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       152      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]


'id' is the index name, which you can set to None to remove.

In [35]: df2.index.name = NoneIn [36]: df2Out[36]:    Cost1  Cost2  Cost3  Value1  Value2  Value31    124    214   1234      12      23      152   1324      0    234      45       0      34