I have two dataframes that are in theory partially identical, with each DF having one other unique additional column. I want to take one of these unique columns and join it onto the opposite dataframe, using matching data from TWO of the shared columns. It would look like this:
df1 =
Column A | Column B | Feature |
---|---|---|
1 | 1 | 'branch' |
2 | 2 | 'trunk' |
df2 =
Column A | Column B | Attribute |
---|---|---|
1 | 1 | 'leaves' |
2 | 2 | 'bark' |
I want to take the 'Attribute' column from df2 and move it to df1 where: (df1[Column A] = df2[Column A]) AND (df1[Column B] = df2[Column B])
so the joined df looks like this
Column A | Column B | Feature | Attribute |
---|---|---|---|
1 | 1 | 'branch' | 'leaves' |
2 | 2 | 'trunk' | 'bark' |
In theory since the two dataframes are being created from the same source data, Column A and Column B will always be the same at the same index. But I want to make sure of this, and do a check that both of these columns match. Any help would be appreciated!
(Also, one is a pandas DF and the other is a geoDF, if that makes any difference)
A simple join like df1 = df1.join(df2['Attribute']) seems to work because the df's are being generated from the same source (a gpkg file in this case), but I want to try a double conditional join if possible in case the dataframes are generated differently.