[英]TypeError: 'int' object does not support item assignment Python
[英]Python: TypeError: 'int' object does not support item assignment for MinMaxScaler
导致错误的整个代码段如下:
# 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])
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
为什么要int TypeError? 有人可以解决这个问题吗?
features_raw是一个整数,而不是一个列表,因此它不支持项目分配。
好的,谢谢所有试图帮助发现问题的人。
我对代码进行了一些试验,发现for循环能够枚举单个语句无法执行的操作,因此发布了下面的解决方案:
for en in numerical:
f[en] = scaler.fit_transform(data[en])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.