Skip to content Skip to sidebar Skip to footer

Renaming Columns From Pivot_table

I run a pivot_table on a dataframe and the resulting column names are: ('firstvar', 8001) ('firstvar', 8002) ('secondvar', 8001) ('secondvar', 8002) But before I can use

Solution 1:

Late answer but can be helpful for others...

my_colnames = []
for i, a in enumerate(my_pivoted_table.columns.get_level_values(1)):
    my_colnames.append(str(a) + '_' + str(my_pivoted_table.columns.get_level_values(0)[i]))
my_pivoted_table.columns = my_colnames

Post a Comment for "Renaming Columns From Pivot_table"