目前,我正在尝试将一个因变量归因于熊猫。(不要问为什么。)这是数据集
y.head(15)
Out[138]:
0 13495.0
1 16500.0
2 16500.0
3 13950.0
4 17450.0
5 15250.0
6 17710.0
7 18920.0
8 23875.0
9 NaN
10 16430.0
11 16925.0
12 20970.0
13 21105.0
14 24565.0
Name: price, dtype: float64如果我试图推算这个变量,会发生一些奇怪的事情:
len(y) # 15
from sklearn.preprocessing import Imputer,
mean_imputer_y = Imputer(strategy="mean", axis=0)
imputed_y = mean_imputer_y.fit_transform(y)
len(imputed_y) # 14它显然是在做与计算机应该做的事情完全相反的事情。我不想删除NaN。我想把他们归因于。
对这种行为有什么解释吗?我做错了什么?
谢谢你的帮忙!
发布于 2018-01-13 07:37:48
您应该使用axis=1而不是0。
from sklearn.preprocessing import Imputer
mean_imputer_y = Imputer(strategy="mean", axis=1,missing_values=np.nan)
mean_imputer_y.fit_transform(df.Val)
array([[13495. , 16500. , 16500. , 13950. , 17450. , 15250. , 17710. ,
18920. , 23875. , 18117.5, 16430. , 16925. , 20970. , 21105. ,
24565. ]])https://stackoverflow.com/questions/48235420
复制相似问题