Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #mask
ADD COMMENT
Topic
Name
8+4 =