位置:- 正文

python中series排序的两种方法(python列表排序sorted)

编辑:rootadmin

推荐整理分享python中series排序的两种方法(python列表排序sorted),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:python排序列表,python排序sort,python排序列表,python 数据排序,python列表排序reverse,python中列表排序sort,python中列表排序sort,python列表排序reverse,内容如对您有帮助,希望把文章链接给更多的朋友!

在python的pandas库中,Series 是一个类似于带有标签或者索引数组的数据结构,如果想要对series排序,可以通过两种形式进行排序,即使用sort_index方法通过索引进行排序和使用sort_values方法通过值进行排序。

python中series排序的两种方法(python列表排序sorted)

方法一:series使用sort_index方法通过索引进行排序

使用格式

series.sort_index()

具体实例

frompandasimportDataFrame,Series#####Series按索引排序sort_index方法返回新对象obj=Series([1,3,2,5,6],index=list('dabce'))obj.sort_index()obj.sort_index(ascending=False)

方法二:series使用sort_values方法通过值进行排序

使用格式

series.sort_values()

具体实例

frompandasimportDataFrame,Series#####Series按值排序sort_values方法返回新对象obj.sort_values()obj.sort_values(ascending=False)

以上就是python中series排序的两种方法,大家可以根据具体内容通过索引或者值进行排序哦~更多python学习推荐:python教程。

本文链接地址:https://www.jiuchutong.com/zhishi/309192.html 转载请保留说明!
下一篇链接:https://www.jiuchutong.com/zhishi/309193.html
免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

鄂ICP备2023003026号

友情链接: 武汉网站建设 电脑维修 湖南楚通运网络