[英]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.