I have one column in the first dataframe called 'id' and another column in the second dataframe called 'first_id' which refers to the id from the first dataframe. I need to create a new column which has value 1 if the id and first_id match, otherwise it is 0. I tried this but I am getting an error
ValueError: Length of values does not match length of index.
df2['new'] = np.where(df2[df2.first_id.isin(df1.id.values)], 1, 0)
I understand why is it happening, because
df2[df2.first_id.isin(df1.id.values)] are of different lengths but I can't make them the same. Any ideas?