import numpy as np
import pandas as pd
#读取数据
df=pd.read_csv('/data/workspace/myshixun/step1/train.csv')
##### begin #####
#查看列中是否存在空值
temp=df.isnull().any()
print(temp)
#使用SimpleImputer取出缺失值所在列的数值,sklearn当中特征矩阵必须是二维才能传入 使用reshape(-1,1)升维
age=df['Age'].values.reshape(-1,1)
#导入模块
from sklearn.impute import SimpleImputer
#实例化,均值填充,可改变strategy参数,实现其他填充方式
imp_mean=SimpleImputer(missing_values=np.nan,strategy='mean')
#fit_transform一步完成调取结果
imp_mean=imp_mean.fit_transform(age)
#填充好的数据传回到 data['Age']列
df_fill
国科大数据挖掘实训——数据预处理之数据清洗
最新推荐文章于 2024-04-11 09:53:16 发布