【发布时间】:2022-01-24 22:13:34
【问题描述】:
companies.xlsx
company To
1 amazon hi@test.de
2 google bye@test.com
3 amazon hi@tld.com
4 starbucks hi@test.de
5 greyhound bye@tuz.de
emails.xlsx
hi@test.de bye@test.com hi@tld.com ...
1 amazon google microsoft
2 starbucks amazon tesla
3 Grey Hound greyhound
4 ferrari
所以我有上面的 2 个 excel 表并阅读了两个 em:
file1 = pd.ExcelFile('data/companies.xlsx')
file2 = pd.ExcelFile('data/emails.xlsx')
df_companies = file1.parse('sheet1')
df_emails = file2.parse('sheet1')
我想要完成的是:
- 检查 df_companies['To'] 是否是 df_emails 中的现有标头
- 如果标题存在于 df_emails 中,请在该标题的相应列中搜索 df_companies['company']
- 如果找到公司,则在df_companies中添加一列并填写'1',如果没有填写'0'
例如:亚马逊公司在 company.xlsx 中有收件人电子邮件 hi@test.de。在 email.xlsx 中,标题 hi@test.de 存在,并且在列中也找到了 amazon - 所以它是“1”。
有人知道怎么做吗?
【问题讨论】: