I am trying to "reshape" a pivot table:
I would like to remove those MultiIndex:
This should be my output:
I have already tried stack, unstack, melt, but I am not getting the result.
At the moment I am saving the Pivot in a CSV, opening the Excel file and deleting manually those extra cells and lines to re-upload on my jupyter (I know it's not a descent job)
Can anybody help please?
CodePudding user response:
Try:
brincando3 = df4.pivot_table('OCCUPANCY %', 'NAME', 'NEW_TIME', aggfunc='median') \
.rename_axis(columns=None)
Don't use
['OCCUPANCY %']
if you don't want an outer level, prefer'OCCUPANCY %'
if you have only one variable to pivot.NEW_TIME
is the column label. To remove it, userename_axis(columns=None)
.