1 回答
TA贡献2037条经验 获得超6个赞
这是一个临时解决方案......
合并两个数据帧并添加后缀。
dfNew = df.merge(df1, left_index=True, right_index=True,how='outer', suffixes=('_y', ''))
#result
person_id_y email_y lang person_id email kids
1 None EN 1 tes1@foo.com 2
2 tes2@foo.bar FR 2 tes2@foo.com 0
3 tes2@barbar.com DK 3 tes3@foo.com 0
NaN NaN NaN 4 tes4@foo.com 1
然后只过滤你想要的列
dfNew = dfNew[['person_id','email','kids','lang']]
person_id email kids lang
1 tes1@foo.com 2 EN
2 tes2@foo.com 0 FR
3 tes3@foo.com 0 DK
4 tes4@foo.com 1 NaN
添加回答
举报