【对比python】外键关联2 | 润乾 -pg游戏官网登录入口
任务:找出部门经理最年轻的部门
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) |
集算器
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 |
同样是外键对象化的应用。