简体   繁体   English

在 dask-ml 中估算单列的平均值

[英]Impute mean of single column in dask-ml

Calculating and imputing the mean using dask-ml works fine when changing all the columns that are np.nan :在更改所有np.nan列时,使用 dask-ml 计算和估算平均值可以正常工作:

imputer = impute.SimpleImputer(strategy='mean')
data = [[100, 2], [np.nan, np.nan], [70, 7]]
df = pd.DataFrame(data, columns = ['Weight', 'Age']) 
x3 = imputer.fit_transform(df)
print(x3)

    Weight  Age
 0  100.0   2.0
 1  85.0    4.5
 2  70.0    7.0

But what if I need to leave Age untouched?但是,如果我需要保持Age不变呢? Is it possible to specify what columns to impute?是否可以指定要估算的列?

You should be able to specify colums by df.Weight = imputer.fit_transform(df.Weight) or by indexing columns df.loc["Weight"]您应该能够通过df.Weight = imputer.fit_transform(df.Weight)或通过索引列df.loc["Weight"]来指定列

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM