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:
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? 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 en in numerical:
f[en] = scaler.fit_transform(data[en])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.