DA40. 统计职能部分运动会某项目的报名信息
描述
某公司计划举办一场运动会,现有运动会项目数据集items.csv。 包含以下字段:
有员工报名情况数据集signup.csv。包含以下字段:
请你统计职能部门(functional)中报名标枪(javenlin)的所有员工的员工编号(employee_id)、姓名(name)及性别(sex)。
输出职能部门(functional)中报名标枪(javenlin)的所有员工的员工编号(employee_id)、姓名(name)及性别(sex)。
以上数据集的输出如下(注意:结果中行标签从0开始顺序排序):
Python 3 解法, 执行用时: 787ms, 内存消耗: 524288KB, 提交时间: 2022-07-12
import pandas as pd signup = pd.read_csv('signup.csv') items = pd.read_csv('items.csv') df = pd.merge(signup,items,on="item_id") df1 = df[(df["department"] == "functional") & (df["item_name"] == "javelin")] df2 = df1[["employee_id","name","sex"]] # df2.index = range(df2.shape[0]) print(df2)
Python 3 解法, 执行用时: 790ms, 内存消耗: 524288KB, 提交时间: 2022-06-28
import pandas as pd signup = pd.read_csv('signup.csv') items = pd.read_csv('items.csv') new = pd.merge(items,signup,on = 'item_id') new1 = new[(new['department'] == 'functional')&(new['item_name'] == 'javelin' )] print(new1[['employee_id','name','sex']].reset_index(drop = True))
Python 3 解法, 执行用时: 792ms, 内存消耗: 524288KB, 提交时间: 2022-07-03
#请你统计职能部门(functional)中报名标枪(javenlin)的所有员工的员工编号(employee_id)、 #姓名(name)及性别(sex)。 import pandas as pd signup = pd.read_csv('signup.csv') items = pd.read_csv('items.csv') new=pd.merge(items,signup,on='item_id') new1 = new[(new['department']=='functional')&(new['item_name']=='javelin')] new2=new1[['employee_id','name','sex']].reset_index(drop = True) print(new2)
Python 3 解法, 执行用时: 796ms, 内存消耗: 524288KB, 提交时间: 2022-07-24
import pandas as pd signup = pd.read_csv('signup.csv') items = pd.read_csv('items.csv') dt=pd.merge(signup,items,on='item_id',how='left') a=dt[(dt['department']=='functional')&(dt['item_name']=='javelin')].reset_index() print(a[['employee_id','name','sex']]) ## !! 要用双括号
Python 3 解法, 执行用时: 798ms, 内存消耗: 524288KB, 提交时间: 2022-07-28
import pandas as pd signup = pd.read_csv('signup.csv') items = pd.read_csv('items.csv') data = pd.merge(signup,items,how='inner',on='item_id') data=data[(data['department'] == 'functional') & (data['item_name'] == 'javelin')].reset_index(drop=True) print(data[['employee_id','name','sex']])