Pandas: 使用均值填充缺失值
使用 Pandas 库中的 isnull()
函数统计 DataFrame 中每列的缺失值数量,可以使用以下代码:
null_counts = loans_2020.isnull().sum()
如果需要使用每列的平均数将缺失值进行填充,可以使用 fillna()
函数,将 loans_2020.mean()
传入作为填充值,并设置 inplace=True
参数来直接修改原 DataFrame:
loans_2020.fillna(loans_2020.mean(), inplace=True)

原文地址: http://www.cveoy.top/t/topic/qu8Z 著作权归作者所有。请勿转载和采集!