如何将一个数据帧的列的值搜索到另一个数据帧中

时间:2021-03-04 14:17:07

标签: python pandas dataframe data-cleaning

我有 2 个数据帧 DF1['mobile','pwd'] ,DF2['mobile','pwd']

DF1: enter image description here

DF2: enter image description here

我想检查 df2['mobile'] 的值是否存在于 df1['mobile'] 中,反之亦然。 我尝试过 isin() 和 merge() 的可能解决方案。但我认为由于长度不等,这行不通。

我想要的输出是

df1:enter image description here

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。

df1.assign(Indf2=df1.mobile.isin(df2.mobile).astype(bool))