pandas通过索引和某列的值排序
- sort_index()
- sort_values()
示例:
原始表:
pd.set_option('display.max_row', None)
df = pd.read_csv(
'https://labfile.oss.aliyuncs.com/courses/1283/telecom_churn.csv')
df.head()
1、按照索引排序:
df.sort_index(ascending=False,inplace=True)
df.head()
2、按照某一列的数值排序:
df.sort_values(by='Account length', ascending=False,inplace=True)
df.head()
3、按照某几列的数值排序:
df.sort_values(by=['Account length', 'Total day calls'], ascending=[False,True],inplace=True)