a1 a2 a3 b1
0 0 0 12 NaN
1 0 3 NaN NaN
2 2 3 1 NaN
In the dataframe df
above, I want to gap-fill column a3
and b1
using median of values from the same columns in another dataframe df2
with the same columns but different values.
a1 a2 a3 b1
0 0 0 2 6
1 0 3 3 7
2 2 3 4 8
I tried this:
df.fillna(df2.median(), inplace=True)
, but I am not sure if it does what I want
CodePudding user response:
I think it does what you want.
The median of a3
in df2
is 3, the median of b1
in df2
is 7.
>>> df.fillna(df2.median())
a1 a2 a3 b1
0 0 0 12.0 7.0
1 0 3 3.0 7.0
2 2 3 1.0 7.0
So it looks like good, no?