Foreign key join 2
Task:Find out the department with the youngest department manager.
Python
1 | import pandas as pd |
2 | import datetime |
3 | emp_file = "E:/txt/EMPLOYEE.txt" |
4 | manager_file = "E:/txt/DEPARTMENT.txt" |
5 | emp_info = pd.read_csv(emp_file,sep='\t') |
6 | manager_info = pd.read_csv(manager_file,sep='\t') |
7 | manager_join = pd.merge(manager_info,emp_info,left_on='MANAGER',right_on='EID') |
8 | today = datetime.datetime.today().year |
9 | arr = pd.to_datetime(manager_join['BIRTHDAY']) |
10 | manager_join['AGE'] = today-arr.dt.year |
11 | min_age = manager_join['AGE'].min() |
12 | young = manager_join[manager_join['AGE']==min_age]['DEPT'] |
13 | print(young) |
esProc
A | |
1 | =file("E:/txt/EMPLOYEE.txt").import@t() |
2 | =file("E:/txt/DEPARTMENT.txt").import@t() |
3 | =A2.join(MANAGER,A1:EID,~:manager) |
4 | =A3.minp(manager.(age(BIRTHDAY))).manager.DEPT |
It is also the application of foreign key objectification.