简体   繁体   English

Python:TypeError:'int'对象不支持MinMaxScaler的项目分配

[英]Python: TypeError: 'int' object does not support item assignment for MinMaxScaler

The entire code snippet which lead to the error is below: 导致错误的整个代码段如下:

# Import sklearn.preprocessing.StandardScaler
from sklearn.preprocessing import MinMaxScaler

#Selecting Numeric columns from the dataset
numerics = ['int16', 'int32', 'int64', 'float16', 'float32', 'float64']
numericdf = data.select_dtypes(include=numerics)
# Initialize a scaler, then apply it to the features
scaler = MinMaxScaler()
numerical = numericdf
features_raw[numerical] = scaler.fit_transform(data[numerical])

MinMaxScaler in Python giving int TypeError code is above error is given below: Python中的MinMaxScaler给出了int TypeError代码,上面的错误如下:

TypeError                                 Traceback (most recent call last)
<ipython-input-86-3ef670532e17> in <module>()
 27 scaler = MinMaxScaler()
 28 numerical = numericdf
---> 29 features_raw[numerical] = scaler.fit_transform(data[numerical])
 30 
 31 # Show an example of a record with scaling applied

TypeError: 'int' object does not support item assignment

Why the int TypeError? 为什么要int TypeError? Can anybody help with the issue? 有人可以解决这个问题吗?

features_raw是一个整数,而不是一个列表,因此它不支持项目分配。

Okay folks Thanks for all who tried to help unearth the problem. 好的,谢谢所有试图帮助发现问题的人。

I did a few experimentation to the code and found that a for loop was able to enumerate what the single statement was not able to so posting the solution that works below: 我对代码进行了一些试验,发现for循环能够枚举单个语句无法执行的操作,因此发布了下面的解决方案:

for en in numerical:
    f[en] = scaler.fit_transform(data[en])

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

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