我想根据熊猫中的其他列填充缺失值。这是我的表:
Gender Married
Male Yes
Male Yes
Female No
Female No
Male NaN
Female NaN
如果性别为男性,我将填充已婚字段的缺失值 -> 已婚为是,否则已婚为否:
df['Married'].fillna(df[df['Married'].isnull()].apply(lambda x: 'Yes' if (df[df['Married'].isnull()]['Gender'] is 'Male') else 'No', axis=1), inplace=True)
但它失败了,我尝试了很多方法,但没有得到预期的结果。我希望收到你们所有人。
慕尼黑8549860
相关分类