I am a bit stuck with sorting a pandas MultiIndex that is used for the columns of one of my datasets:
MultiIndex(levels=[['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], ['Number of Visitors', 'Profit']],
labels=[[2, 2, 5, 5, 8, 8, 11, 11], [0, 1, 0, 1, 0, 1, 0, 1]],
names=['Month', None])
I want profit to be displayed before number of visitors for each month, so in general I am happy with the levels as they are, but want the labels for the second level to be [1,0,1,0,1,0,1,0] instead of [0,1,0,1,0,1,0,1]. What is a way to obtain this? I have tried sort_index, but cannot get it to work the way I want.
Thank you in advance!
df = df.sort_index(level=1, ascending=False)it not working?