DA39. 多报名表的运动项目人数统计
描述
某公司计划举办一场运动会,现有部分运动会项目数据集items.csv。 包含以下字段:
有员工报名情况数据集signup.csv。包含以下字段:
另有signup1.csv,是education部门的报名情况,包含字段同signup.csv。
请你将signup.csv与signup1.csv的数据集合并后,统计各类型项目的报名人数。
Python 3 解法, 执行用时: 770ms, 内存消耗: 524288KB, 提交时间: 2022-07-05
import pandas as pd signup = pd.read_csv('signup.csv') signup1 = pd.read_csv('signup1.csv') items = pd.read_csv('items.csv') signup2=pd.concat([signup,signup1],axis=0) result1=pd.merge(items,signup2,how='inner',on='item_id') result=result1.groupby('item_name') print(result.size())
Python 3 解法, 执行用时: 779ms, 内存消耗: 524288KB, 提交时间: 2022-07-13
import pandas as pd signup = pd.read_csv('signup.csv') signup1 = pd.read_csv('signup1.csv') items = pd.read_csv('items.csv') ## s = pd.concat([signup,signup1],axis=0) # s = signup.append(signup1) # print(pd.merge(items,s,how="left").groupby('item_name').employee_id.count()) df3 = pd.concat([signup,signup1],axis=0,join='outer') df3 = pd.merge(items,df3,on='item_id') print(df3.groupby('item_name')['employee_id'].count())
Python 3 解法, 执行用时: 780ms, 内存消耗: 524288KB, 提交时间: 2022-07-25
import pandas as pd signup = pd.read_csv('signup.csv') signup1 = pd.read_csv('signup1.csv') items = pd.read_csv('items.csv') a = pd.concat([signup,signup1],axis=0) b = pd.merge(a,items,how='left',on='item_id') cnt = b.groupby('item_name')['employee_id'].count() print(cnt)
Python 3 解法, 执行用时: 780ms, 内存消耗: 524288KB, 提交时间: 2022-07-04
import pandas as pd signup = pd.read_csv('signup.csv') signup1 = pd.read_csv('signup1.csv') items = pd.read_csv('items.csv') total_s=pd.concat([signup,signup1]) output=items.merge(total_s,on='item_id',how='inner') output1=output.groupby('item_name')['employee_id'].count() print(output1)
Python 3 解法, 执行用时: 784ms, 内存消耗: 524288KB, 提交时间: 2022-07-02
import pandas as pd signup = pd.read_csv('signup.csv') signup1 = pd.read_csv('signup1.csv') items = pd.read_csv('items.csv') signup2=pd.concat([signup,signup1]) output=items.merge(signup2,on='item_id',how='inner') output1=output.groupby('item_name')['employee_id'].count() print(output1)