验证df1的列是否在df2的其他列中

时间:2019-10-04 14:45:10

标签: python-3.x pandas dataframe

我想验证df2 ['id']中是否存在df1 ['id'],我加上df1 ['new'] = 1否则df1 ['new'] = 0。

我该怎么办?

 d = {'id': ['12', '13','77','22','777777','23'],'text':['tt','ey', 'ab','aa','xxx','xx']}
 df1 = pd.DataFrame(data=d)

 d = {'id': ['12', '17','13','22']}
 df2 = pd.DataFrame(data=d)
 #######Expected_output################
 d = {'id': ['12', '13','77','22','777777','23'],'text':['tt','ey', 'ab','aa','xxx','xx'],'New' = [1,1,0,1,0,0]}
 df1 = pd.DataFrame(data=d)

0 个答案:

没有答案