I have to data.frames df1and df2 and with exact the same size and column names, but different values. df2 has much NaN and df1 only a few. I want every NaN in df2 become 0, if there is any value in df1 at the same place (except NaN).
E.g.:
df1
a b c
0 1 5 NaN
1 2 4 8
2 5 8 5
3 8 8 1
4 7 3 2
5 NaN 5 1
df2
a b c
0 5 5 NaN
1 NaN 4 8
2 3 8 NaN
3 NaN NaN 8
4 9 NaN 6
5 NaN 5 7
The result should look like this.
df2
a b c
0 5 5 NaN
1 0 4 8
2 3 8 0
3 0 0 8
4 9 0 6
5 NaN 5 7
I am still new to Python and cannot find a solution so far. Unsucsessfully I tried:
for row in range(len(df1)):
if df1.iloc[row,1:] >= 0:
df2[row,1:] == 0
elif df1.iloc[row,1:] == '':
df2.iloc[row,1:] == ''