0

I have two following dataframes df1 and df2:

df1:

ID number Result
13256 99 NaN
15556 100 NaN
14556 100 NaN

df2:

13256 15556 14556 number
12 1 4 99
10 2 5 100
11 3 6 101

Basically, I want to get the values from df2 where values in the number columns match and the name of the column in df2 matches the row value of ID column in df1. The values I get, I want to add them in column Result in df1.

So the expected output is:

ID number Result
13256 99 12
15556 100 2
14556 100 5

I tried something like this but still couldn't succeed it:

    for index, row in df1.iterrows():
        if ((row['ID'] in df2.columns) and (df2.loc[0, 'number'] == row['number'])):
    
            value = row['number']
            print(value)

I appreciate any help!

complog
  • 67
  • 7

0 Answers0