import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv("train.csv")
#Use the Titanic data set from kaggle
data.info()
data.head(3)
data1 = pd.read_csv("train.csv",index_col=0)
#这里的index_col是表示把第0列作为索引,PassengerId正好也有这个属性。
#index_col用法比如你使之为2,那么调用的就是Pclass作为索引。
data1.head(3)
#传入sklearn中的特征矩阵必须是2维的
Age = data1.loc[:,'Age'].values.reshape(-1,1)
Age[:20]
from sklearn.impute import SimpleImputer
imp_mean = SimpleImputer()
#这里用均值是因为大概率是0~100不会有很大差距
imp_mean = imp_mean.fit_transform(Age)
imp_mean[:20]
#用填补好的imp_mean来覆写Age列
data1.loc[:,"Age"] = imp_mean
data1.info()
#可以看到Age已经填满了
data1['Age'].isnull().sum()