我有一个 Pandas 数据框,它有一个特定的电子邮件地址列表,例如:
Email
[email protected]
[email protected]
我的电子邮件联系信息主列表分为 5 个 Pandas 数据框(从 excel 导入)。我需要在这 5 个数据帧中查找以在我的初始数据帧中提取联系人的 first_name 和 last_names。有没有一种快速的方法来做到这一点?
编辑:其他数据框将电子邮件地址作为主要标识符,first_name 和 last_name 具有单独的列,例如:
Email|first_name|last_name
[email protected]|James|Bond
[email protected]|Jason|Bourne
谢谢你的帮助!
使用 导入 Excel 文件后df = pd.read_excel(path_to_file)
,您可以使用pd.merge
:
df1 = pd.DataFrame({'Email': ['[email protected]', '[email protected]']})
df2 = pd.DataFrame({'Email': ['[email protected]', '[email protected]'],
'first_name': ['James', 'Jason'],
'last_name': ['Bond', 'Bourne']})
pd.merge(df1, df2, on='Email')
Email first_name last_name
0 [email protected] James Bond
1 [email protected] Jason Bourne
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句