I want to fill the NaN values on my dataframe on column c with the mean for only rows who has as category B, and ignore the others.
print (df) Category b c 0 A 1 5.0 1 C 1 NaN 2 A 1 4.0 3 B 2 NaN 4 A 2 1.0 5 B 2 Nan 6 C 1 3.0 7 C 1 2.0 8 B 1 NaN So what I'm doing for the moment is :
df.c = df.c.fillna(df.c.mean()) But it fill all the NaN values, while I want only to fill the 3rd, 5th and the 8th rows who had category value equal to B.