【对比Python】对分组结果排序
任务:找出人数最多和最少的两个部门
Python
1 | import pandas as pd |
2 | emp_file = 'E:\\txt\\employee.txt' |
3 | emp_info = pd.read_csv(emp_file,sep='\t') |
4 | emp_g = emp_info.groupby(by='DEPT') |
5 | size = emp_g.size().sort_values() |
6 | sorted_dept = size.index.values |
7 | print(sorted_dept[[0,-1]]) |
集算器
|
A |
|
1 |
E:\\txt\\employee.txt |
|
2 |
=file(A1).import@t() |
|
3 |
=A2.group(DEPT).sort(~.len()).m([1,-1]).(~.DEPT) |
|
集算器分组排序筛选一行搞定