繁体   English   中英

在 Python 上应用 sklearn StandardScaler 时出错

[英]Getting an error when applying sklearn StandardScaler on Python

我正在使用具有分类和数字列的 DataFrame。 我正在尝试缩放数字列,因为数字非常极端。 我尝试使用下面的代码,但它一直出错。 我只指出了要应用的数字列。

from sklearn.preprocessing import StandardScaler

numerical = df.iloc[:, 6:24]
scaler = StandardScaler()
scaled_df = scaler.fit_transform(df[numerical])

错误是 ValueError: Boolean array expected for the condition, not float64

我不明白是什么原因造成的。 我已经尝试更新我正在使用的 pandas 版本,但没有修复它。

numerical已经是 dataframe( df的子集),因此df[numerical]在这里没有意义:

scaled_df = scaler.fit_transform(numerical)

如果你只尝试:

>>> df[numerical]
...
ValueError: Boolean array expected for the condition, not float64

暂无
暂无

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

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