import pandas as pd
import numpy as np
df = pd.DataFrame({'Country': ['China', 'China', 'India', 'India', 'America', 'Japan', 'China', 'India'],
'Income': [10000, 10000, 5000, 5002, 40000, 50000, 8000, 5000],
'Age': [50, 43, 34, 40, 25, 25, 45, 32]})
order=df['Country'].value_counts().reset_index() #计算数量,并且重新设置 index,oder 的第一列的名字是’index‘
sorted_list = order['index'].values.tolist()
print(sorted_list)#返回的就是按照数量排列好的list
#如何按照一个 list 排序,后续再说
#一种思路是遍历order['index'].values.tolist(),通过 df[df['Country'] == sorted_list[k]]
07-30
4771
03-28
1947
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交