一、普通青年的缺失值填补(自己举的例子)
raw=[1,2,3,np.nan,4,6,5,8] sds=[3,2,7,5,4,8,3,5] raw1=pd.DataFrame([raw,sds],columns=list('abcdefgh')) raw1.set_index=list('AB') raw1.iloc[1,4]=np.nan raw1.iloc[1,3]=np.nan raw1 a b c d e f g h 0 1 2 3 NaN 4.0 6 5 8 1 3 2 7 NaN NaN 8 3 5 raw1.fillna(0) a b c d e f g h 0 1 2 3 0.0 4.0 6 5 8 1 3 2 7 0.0 0.0 8 3 5 raw1.fillna(raw1.iloc[0,:].mean())#填充某一行的均值 a b c d e f g h 0 1 2 3 4.142857 4.000000 6 5 8 1 3 2 7 4.142857 4.142857 8 3 5 raw1.dropna(thresh=7)#默认是保留的行的个数 a b c d e f g h 0 1 2 3 NaN 4.0 6 5 8 raw1.dropna(thresh=1,axis=1)#可以设置列保留的最低门槛 a b c e f g h 0 1 2 3 4.0 6 5 8 1 3 2 7 NaN 8 3 5 raw1.fillna({'d':4,'e':0})#添加列名和填补的值 a b c d e f g h 0 1 2 3 4.0 4.0 6 5 8 1 3 2 7 4.0 0.0 8 3 5 raw=[1,2,3,np.nan,4,6,5,8] sd