I have 2 data frames as below:
df1(main data)
UID SG
1 A
2 B
3 C
4 D
5 E
df2
UID AN SG
1 x A
3 y C
2 z B
1 xy A
3 v C
Now, I want to add a new column to df1, say "isPresent". This column will have "Yes" if the UID from df1 is present in df2 and "No" if UID in not in df2. So my df1 will finally looks like this,
df1
UID SG isPresent
1 A Yes
2 B Yes
3 C Yes
4 D No
5 E No
My approach is taking an intersection of the UIDs from both the dataframes and then a for loop in df1 to add data cell by cell.
But I want to apply an approach without using for loop and using pandas as much as possible, if possible.