Answers for "mask and then fillnan#"

0

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)
Posted by: Guest on March-20-2021

Python Answers by Framework

Browse Popular Code Answers by Language