i have a dataframe df1:
id age val
10 2 10
20 3 NaN
30 4 55
40 5 NaN
I have another dataframe df2:
age val_main
1 111
2 222
3 333
4 444
5 555
6 666
I want to only replace value from df1 where it is NaN with its corresponding value from df2.
Final output im looking for is:
id age val
10 2 10
20 3 333
30 4 55
40 5 555
i tried iterating the df1 by for loop and then locating the values from df2 where the row in df1 is null.
eg:
for index,row in df1.iterrows():
if row['val'].isnull():
df2.loc[df2.age==row.age].val
.....
.....
But i'm looking for a more robust and intelligent way of doing this.