【对比python】外键关联1 | 润乾 -欧洲杯在线开户
任务:找出员工中夫妻工资和超过10000的员工
python
1 | import pandas as pd |
2 | emp_file = "e:\\txt\\employees.txt" |
3 | rel_file = "e:\\txt\\emprel.txt" |
4 | emp_info = pd.read_csv(emp_file,sep='\t') |
5 | rel_info = pd.read_csv(rel_file,sep='\t') |
6 | rel_info = rel_info[rel_info['relationship']=="spouse"] |
7 | emp1_join = pd.merge(rel_info,emp_info,left_on='emp1',right_on='id') |
8 | emp2_join = pd.merge(emp1_join,emp_info,left_on='emp2',right_on='id') |
9 | res = emp2_join[emp2_join['basepay_x'] emp2_join['basepay_y']>=10000] |
10 | r = res[['name_x','name_x']] |
11 | print(r) |
pandas只能进行两次连接得到两列的信息,而后进行筛选。
集算器
a | |
1 | =file("e:\\txt\\employees.txt").import@t().keys(id) |
2 | =file("e:\\txt\\emprel.txt").import@t() |
3 | =a2.select(relationship=="spouse") |
4 | >a3.switch(emp1,a1;emp2,a1) |
5 | =a3.select(emp1.basepay emp2.basepay>=10000) |
6 | >a5.run(emp1=emp1.name,emp2=emp2.name) |
集算器通过外键对象化,把外键字段转换成外键表中对应的引用,这样就可以当单表来处理了。