【Python学习】 - Pandas学习 sort_value( ),sort_index( )排序函数的区别与使用
生活随笔
收集整理的這篇文章主要介紹了
【Python学习】 - Pandas学习 sort_value( ),sort_index( )排序函数的区别与使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
按索引對DataFrame或Series進行排序(注意ascending=false的意思是按照降序排序,若不寫參數則默認升序排序)
DataFrame的構造函數默認參數是(值,列名,行索引),行索引不填則默認0,1,2,3這樣?
In [101]: frame=pd.DataFrame(np.arange(12).reshape((4,3)),columns=['c','a','b'],index=['D','B','C','A'])c a b D 0 1 2 B 3 4 5 C 6 7 8 A 9 10 11In [102]: frame.sort_index(axis=0) Out[102]:c a b A 9 10 11 B 3 4 5 C 6 7 8 D 0 1 2In [103]: frame.sort_index(axis=1) Out[103]:a b c D 1 2 0 B 4 5 3 C 7 8 6 A 10 11 9In [105]: frame.sort_index(axis=1,ascending=False) Out[105]:c b a D 0 2 1 B 3 5 4 C 6 8 7 A 9 11 10?按指定的值對DataFrame進行排序
In [133]: frame.sort_index(by=['b'],ascending=False) Out[133]:c a b A 9 10 11 C 6 7 8 B 3 4 5 D 0 1 2按值對Series進行排序
In [125]: obj=pd.Series([4,7,-3,2])In [126]: obj.sort_values() Out[126]: 2 -3 3 2 0 4 1 7 dtype: int64?部分內容參考博文
?
總結
以上是生活随笔為你收集整理的【Python学习】 - Pandas学习 sort_value( ),sort_index( )排序函数的区别与使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql mybatis类型对应_My
- 下一篇: 【Python学习】 - 如何将Pand