Sort grouped results

Task:Find out the two departments with the largest number and the smallest number of employees.

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]])

esProc

  A  
1 E:\\txt\\employee.txt  
2 =file(A1).import@t()  
3 =A2.group(DEPT).sort(~.len()).m([1,-1]).(~.DEPT)  

With esProc, the grouping, sorting and filtering are completed by one line.