我要筛选几个部门-然后,我需要显示不匹配的数字。
查找单个部门提供的程序数量:
cond = events['Event Type'].str.contains('Outreach') & (events['Presenter'].str.contains('[Dd]ept1', regex=True))
dpta = events[cond]
dpta_att = dpta['Attendance'].sum()
dpta_num = len(dpta.index)
从理论上讲,以下内容似乎会给我提供属于上述任何部门的剩余程序 not :
pattern = '[Dd]ept1|[Dd]ept2|[Dd]ept3'
leftover_cond = events['Event Type'].str.contains('Outreach') & (events['Presenter'].str.contains(pattern, case=False, regex=True)==False | events['Presenter'].isnull())
leftover_outreach = events[leftover_cond]
leftover_outreach_att = leftover_outreach['Attendance'].sum()
leftover_outreach_num = len(leftover_outreach.index)
我得到的数字比预期的少得多。
数据:
Location Attendance Event Type Presenter
HR Office 10 Outreach DeptA
Board Room 5 Admin Billy
Offsite 103 Outreach DeptB