题解 | #统计运动会项目报名人数(二)#
统计运动会项目报名人数(二)
https://www.nowcoder.com/practice/737d224c9cce482fb56ff812d04e79ab
模拟数据
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
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') items = pd.read_csv('items.csv') df_all = pd.merge(signup, items, how='right', left_on=signup['item_id'], right_on=items['item_id']) print(df_all.groupby('item_name')['employee_id'].count())