I have two dataframes with different column size, where four columns can have the same values in both dataframes. I want to make a new column in df1, that takes the value 1 if there is a row in df2 that has the same values for column 'A','B','C', and 'D' as a row in df1. If there isn't such a row, I want the value to be 0. Rows 'E' and 'F' are not important for checking the values.
Is there a pandas function that can do this, or do I have to this in a loop.
For example:
df1 =
A B C D E F
1 1 20 20 3 2
1 1 12 14 1 3
2 1 13 43 4 3
2 2 12 34 1 4
df2 =
A B C D E
1 3 12 14 2
1 1 20 20 4
2 2 21 31 5
2 2 12 34 8
expected output:
df1 =
A B C D E F Target
1 1 20 20 3 2 1
1 1 12 14 1 3 0
2 1 13 43 4 3 0
2 2 12 34 1 4 1