【说站】python中pandas排序的两种形式
2024-12-24
47
python中pandas排序的两种形式
说明
1、排序有两种形式,一种对内容进行排序,一种对索引进行排序
内容排序:
2、使用df.sort_values(key=,ascending=)对内容进行排序,单个键或者多个键进行排序,默认升序,ascending=False:降序 True:升序
索引排序:
3、使用df.sort_index对索引进行排序
实例
data.sort_values(by="high", ascending=False) # DataFrame内容排序 data.sort_values(by=["high", "p_change"], ascending=False).head() # 多个列内容排序 data.sort_index().head() sr = data["price_change"] sr.sort_values(ascending=False).head() sr.sort_index().head()
以上就是python中pandas排序的两种形式,希望对大家有所帮助。更多Python学习指路:python基础教程
本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。
更新于:28天前赞一波!2
相关文章
- 【说站】Python kmeans聚类的使用
- 【说站】Python中concurrent.futures模块如何使用
- 【说站】Python curses库如何使用
- 【说站】Python字典常用方法汇总
- 【说站】Python字符串方法如何使用
- 【说站】Python列表操作方法的整理
- 【说站】Python中os模块的功能介绍
- 【说站】python模块的搜索顺序分析
- 【说站】python抛出raise异常的注意点
- 【说站】Python psd-tools如何转换文件
- 【说站】python异常的传递
- 【说站】python自定义日志如何实现
- 【说站】python有哪些注释的种类
- 【说站】python中__new__的重写
- 【说站】python如何解决初始化执行次数
- 【说站】python错误类型捕获的方法
- 【说站】python数据结构堆的介绍
- 【说站】python参数调用的注意点
- 【说站】mysql表导出的两种方法
- 【说站】python Pandas读取数据文件的优点
文章评论
评论问答