题解 | #多报名表的运动项目人数统计#
多报名表的运动项目人数统计
https://www.nowcoder.com/practice/423da9d9768243c89e3c724ba7e2ff4d
模拟 数据
signup.csv
employee_id,name,sex,department,item_id NC001,liming,f,functional,N100 NC002,zhangsan,f,functional,N101 NC003,sunli,m,functional,N103 NC004,lina,m,functional,N103 NC005,wanger,m,technology,N101 NC006,shenteng,m,functional,N100 NC007,mali,f,functional,N102 NC008,reba,f,functional,N102 NC009,ailun,m,functional,N102 NC010,changyuan,m,functional,N102 NC011,geyou,m,functional,N103 NC012,cls,f,functional,N103
signup1.csv
employee_id,name,sex,department,item_id NC013,zhangwei,m,education,N102 NC014,liufang,m,education,N102 NC015,wanglei,m,education,N104 NC016,zhangli,f,education,N104 NC017,wangyan,m,education,N101 NC018,liangfeifan,m,education,N101
items.csv
item_id,item_name,location N100,athletics,area01 N101,longJump,area02 N102,highJump,area03 N103,javelin,area04 N104,pingPong,area05 N105,relayRace,area06
实现代码
import pandas as pd signup = pd.read_csv('signup.csv') signup1 = pd.read_csv('signup1.csv') items = pd.read_csv('items.csv') signup = signup.append(signup1,ignore_index=True) df_all = pd.merge(signup, items, how='left', left_on=signup['item_id'], right_on=items['item_id']) print(df_all.groupby('item_name')['employee_id'].count())