mask and then fillnan# code example
Example: mask and then fillnan#
a b c
1 1 5.0
1 1 None
1 1 4.0
1 2 1.0
2 1 2.0
2 1 None
mask = (df['a']==1) & (df['b']==1)
mean = df.loc[mask, 'c'].mean()
df.loc[mask, 'c'] = df.loc[mask, 'c'].fillna(mean)
a b c
1 1 5.0
1 1 None
1 1 4.0
1 2 1.0
2 1 2.0
2 1 None
mask = (df['a']==1) & (df['b']==1)
mean = df.loc[mask, 'c'].mean()
df.loc[mask, 'c'] = df.loc[mask, 'c'].fillna(mean)