I have the following issue:
I have two Panda Dataframes with different structures, but they can contain the same strings.
I want two compare both Columns in question between the two Dataframes. If on row matches with another row, it should add the string from another column to the first Dataframe as a new column:
df1
Info1 Info2
A AA
B BB
…
df2
Info1 Info3
C CCC
A AAA
…
It should find that df1 and df2 both have A in Info1 and should add AAA from df2 as a new column to df1.
If no match is found, just add NA
df1
Info1 Info2 Info3
A AA AAA
B BB NA
…
Both Dataframes should only contain strings.
I was trying to do it with a for loop, but I did not get it to work and have no idea how to tackle this.
I also found this solution for a similar issue, but while it seems to run, the column is in df1 is not filled correctly and I only get NaN
df1.Info3 = df1.Info1.map(dict(df2.values))
Has anybody an idea how to do this?
Thanks in advance!
Shepard is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.