首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >pandas排序 按索引和值排序

pandas排序 按索引和值排序

作者头像
AI拉呱
发布于 2021-01-14 11:33:13
发布于 2021-01-14 11:33:13
5.3K0
举报

pandas 排序

代码语言:javascript
复制
import pandas as pd
import numpy as np

unsorted_df=pd.DataFrame(np.random.randn(10,2),index=[1,4,6,2,3,5,9,8,0,7],columns=['col2','col1'])
print (unsorted_df)

# 按标签排序
sorted_df = unsorted_df.sort_index(ascending=False)  # 降序
print (sorted_df)
sorted_df = unsorted_df.sort_index(ascending=True)   # 升序
print (sorted_df)

# 按值排序
sorted_df = unsorted_df.sort_values(by=['col1','col2'])
print(sorted_df)
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020/12/29 ,如有侵权请联系 cloudcommunity@tencent.com 删除
目录
  • pandas 排序
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档