Sometimes you need to re-adjust to a shaft above the level of the order, swaplever accept the two-level number or name, and returns a new object-level interchange.
frame = DataFrame(np.arange(12).reshape((4,3)),
index = [['a','a','b','b'],[1,1,3,4]],
columns=[['OH','OH','DH'],
['RE','RE','FE']])
frame.index.names = ['key1','key2']
frame.columns.names = ['state','color']
print(frame.swaplevel('key1','key2'))
And sortlever (or sort_index (1) according to the data value of a single level sorting, exchange level, often used sortlever, so that the end result is ordered.
Many of DataFrame and Series have a description and summary level option to specify the arbor above a certain sum level, we can be summed according to the row or column.
print (frame.sum(level='key2'))
print (frame.sum(level='color',axis=1))