源数据:
import pandas as pd
frame=pd.DataFrame(
np.arange(12).reshape((4,3)),
columns=['c','a','b'],
index=['D','B','C','A'])
frame
'''
c a b
D 0 1 2
B 3 4 5
C 6 7 8
A 9 10 11
'''
按照行索引名称排序(默认)
frame.sort_index(axis=0)
'''
c a b
A 9 10 11
B 3 4 5
C 6 7 8
D 0 1 2
'''
按照列索引名称排序
frame.sort_index(axis=1)
a b c
D 1 2 0
B 4 5 3
C 7 8 6
A 10 11 9