【发布时间】:2022-06-11 13:42:48
【问题描述】:
我有两个不同的 Excel 文件,我使用 pd.readExcel 读取它们。第一个 excel 文件是一种主文件,它有很多列。仅显示相关的列:
df1
Company Name Excel Company ID
0 cleverbridge AG IQ109133656
1 BT España, Compañía de Servicios Globales de T... IQ3806173
2 Technoserv Group IQ40333012
3 Blue Media S.A. IQ50008102
4 zeb.rolfes.schierenbeck.associates gmbh IQ30413992
第二个 excel 基本上是一个输出 excel 文件,如下所示: df2
company_id found_keywords no_of_url company_name
0 IQ137156215 insurance 15 Zühlke Technology Group AG
1 IQ3806173 insurance 15 BT España, Compañía de Servicios Globales de T...
2 IQ40333012 insurance 4 Technoserv Group
3 IQ51614192 insurance 15 Octo Telematics S.p.A.
我希望此输出 excel 文件/df2 包含来自 df1 的那些 company_id 和公司名称,其中来自 df1 的公司 ID 和公司名称不是 df2 的一部分。像这样的东西: df2
company_id found_keywords no_of_url company_name
0 IQ137156215 insurance 15 Zühlke Technology Group AG
1 IQ3806173 insurance 15 BT España, Compañía de Servicios Globales de T...
2 IQ40333012 insurance 4 Technoserv Group
3 IQ51614192 insurance 15 Octo Telematics S.p.A.
4 IQ30413992 NaN NaN zeb.rolfes.schierenbeck.associates gmbh
我尝试了几种通过使用pd.merge 和np.where 来实现此目的的方法,但都没有成功。我需要做什么才能按预期工作。
【问题讨论】:
标签: python excel pandas dataframe