具有带有值的df1
0 1
0 abc def unknown
1 uvw xyz unknown
2 cricket ball unknown
3 tennis racket unknown
和带有值的df2
0 0 1
0 abc def password
1 cricket ball password1
2 tennis racket password2
.....
22610 uvw xyz password3
应使用0值映射df1和df2并更新df1中的1列
输出应为
0 1
0 abc def | password
1 uvw xyz | password3
2 cricket ball | password1
3 tennis racket | password2
答案 0 :(得分:0)
您需要:
在df2中创建新列,其中包含两列的串联以与df1列匹配:
df2['concat']= df2[0]+str(' ')+df2[0]
# added space to match with df1 and drop the df2[0] columns
将df1 [0]的列名重命名为“ concat”:
df1.rename({0:'concat'},inplace =True,axis=1)
使用熊猫的合并方法:
df1.merge(df2,on='concat')
您将获得预期的结果。