python - How to swap the column header in pandas pivot table? -
following question
i got datframe after pivoting .
avg grossprofit avg pmv loss% sales parentauction copart iaa copart iaa copart iaa copart iaa make acura 112.99 nan -15.53 nan 36.46 nan 96.0 nan
how change column levels format of columns ?
parentauction copart iaa avg grossprofit avg pmv loss% sales avg grossprofit avg pmv loss% sales make acura 112.99 -15.53 36.46 96.0 nan nan nan nan
use swaplevel
sort_index
sorting multiindex
:
df = df.swaplevel(0,1, axis=1).sort_index(axis=1) print (df) parentauction copart iaa \ avg grossprofit avg pmv loss% sales avg grossprofit avg pmv make acura 112.99 -15.53 36.46 96.0 nan nan parentauction loss% sales make acura nan nan
Comments
Post a Comment