这是我正在使用的代码。
数据集是泰坦尼克号火车。
null_index = pd.isnull(train.Age)
np.mean(train.Age[train.Pclass == 1]) # this gives me 38.233
train.Age[train.Pclass == 1][null_index].fillna(value = 38, inplace = True)
# this is not filling na inplace.
# running this code, i still see nan
train.Age[train.Pclass == 1][null_index].head(5)