Trying to re-sort 3-level pandas multiindex column names

48 Views Asked by At

I have the following pivoted dataframe:

enter image description here

I need the output to be like this:

enter image description here

This report will be run daily, and the first two levels will change over time, so I can't do it by hard-coding the actual numerical values. They will need to be dynamic based on the results of the pivot-table process.

Note that the first level will always be sorted in ascending order. The second level is month number, so it's ascending after the year level is sorted. And then the third level has to be ROOMS first followed by REVENUE, which is descending alphabetical order.

Thank-you, AF

0

There are 0 best solutions below