I have two dataframes df1 and df2. I would like to check if id2 value exists in df2. If exists, fetch the rows in df1 with identical id1 values. I tried left join but it gives only the first row.
pd.merge(df1, df2.rename(columns={'id1':'id2'}), on='id2', how='left')
df1
id1 id2 id3
C45 AB ZU
C45 ZO RE
C67 RT FG
C78 TZ GH
df2
id1
AB
GH
ZU
Expected output is:
id1 id2 id3
C45 AB ZU
C45 ZO RE