网络编程
位置:首页>> 网络编程>> 网络编程>> 浅谈Series和DataFrame中的sort_index方法

浅谈Series和DataFrame中的sort_index方法

作者:有一种宿命叫无能为力  发布时间:2022-07-01 05:53:22 

标签:Series,sort,index

Series 的 sort_index(ascending=True) 方法可以对 index 进行排序操作,ascending 参数用于控制升序或降序,默认为升序。

若要按值对 Series 进行排序,当使用 .order(na_last=True, ascending=True, kind='mergesort') 方法,任何缺失值默认都会被放到 Series 的末尾。

在 DataFrame 上,.sort_index(axis=0, by=None, ascending=True) 方法多了一个轴向的选择参数与一个 by 参数,by 参数的作用是针对某一(些)列进行排序(不能对行使用 by 参数)。

注意在使用sort_index对DataFrame进行排序的时候,不能直接对index和columns都含有的字段进行排序,会报错。

来源:https://blog.csdn.net/You_are_my_dream/article/details/70586915

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com