gather bar
gather bar

Reputation: 474

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:

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?

Upvotes: 0

Views: 1163

Answers (2)

gather bar
gather bar

Reputation: 474

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])

Upvotes: 1

DaOnlyOwner
DaOnlyOwner

Reputation: 353

features_raw is an integer, not a list, and thus it doesn't support item assignment.

Upvotes: 0

Related Questions