从“年龄”列中,我要选择介于(15&45)之间的年龄组,然后用年龄组(15&45)的平均值替换缺少的值
[IN]: train['Age'].isnull().value_counts()
[OUT]:
False 714
True 177
Name: Age, dtype: int64
如何编写此代码?你知道吗
大多数解决方案都涉及基于布尔的输出
train['Age'].fillna((train['Age'] > 15 & train['Age'] < 45).mean())
TypeError: cannot compare a dtyped [float64] array with a scalar of type [bool]
train['Age'].fillna((train['Age'] > 15 & train['Age'] < 45).mean())
年龄组分布在1到80岁之间 从“年龄”列中,我要选择介于(15&45)之间的年龄组,然后用年龄组(15&45)的平均值替换缺少的值
为
Age
列添加括号和loc
:或者使用^{} :
最后替换缺少的值:
相关问题 更多 >
编程相关推荐