我是 Pandas 和 Numpy 的新手。我试图解决Kaggle | 泰坦尼克号数据集。现在我必须修复“Age”和“Embarked”这两列,因为它们包含 NAN。
现在我尝试了fillna
没有任何成功,很快就发现我错过了inplace = True
.
现在我附上了它们。但是第一次插补成功了,第二次没有成功。我尝试在 SO 和 google 中搜索,但没有找到任何有用的东西。请帮我。
这是我正在尝试的代码。
# imputing "Age" with mean
titanic_df["Age"].fillna(titanic_df["Age"].mean(), inplace = True)
# imputing "Embarked" with mode
titanic_df["Embarked"].fillna(titanic_df["Embarked"].mode(), inplace = True)
print titanic_df["Age"][titanic_df["Age"].isnull()].size
print titanic_df["Embarked"][titanic_df["Embarked"].isnull()].size
我得到的输出为
0
2
但是我设法在不使用的情况下得到了我想要的inplace=True
titanic_df["Age"] =titanic_df["Age"].fillna(titanic_df["Age"].mean())
titanic_df["Embarked"] = titanic_df.fillna(titanic_df["Embarked"].mode())
但我很好奇second usage
of是什么inplace=True
。
如果我问的是非常愚蠢的问题,请耐心等待,因为我是全新的,我可能会错过一些小事。任何帮助表示赞赏。提前致谢。