Skip to content
Advertisement

change dataframe pivot_table headers to save it in an excel file

I have a nested hearders in a dataframe after pivoting it and I’d like to make it flat, with repeated item on each rows (like in a excel) May you help me ?

JavaScript

where I’d like to get a flat header and reapeated rows :

JavaScript

many thanks

Nico

Advertisement

Answer

You need to use droplevel(0) which will remove the top level (Sales). Setting columns.name to None will remove the Products. So, after df2 is created, add these lines…

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement