pandas笔记:根据列索引名称/行索引名称 对列重新排序
Posted UQI-LIUWJ
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pandas笔记:根据列索引名称/行索引名称 对列重新排序相关的知识,希望对你有一定的参考价值。
源数据:
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
以上是关于pandas笔记:根据列索引名称/行索引名称 对列重新排序的主要内容,如果未能解决你的问题,请参考以下文章