Reputation: 27
I'm trying to use OneHotEncoding on the categorical variables of the following dataset.
First, I'm trying to convert the 'Geography' column. Here's what I've done so far:
from sklearn.preprocessing import OneHotEncoder
from sklearn.compose import ColumnTransformer
ct = ColumnTransformer(['Geography',OneHotEncoder(categories='auto'),[1]],remainder='passthrough')
df_ = ct.fit_transform(df.values)
However, when I try this, I get the following error:
Can someone help me to understand why this error occurs and how to solve this?
Upvotes: 2
Views: 4331
Reputation: 1396
There is a syntax error in the input parameter to the ColumnTransformer
. It expects a list of tuples.
List of (name, transformer, columns) tuples specifying the transformer objects to be applied to subsets of the data.
Try fixing it by converting the encoder params to a tuple
ct = ColumnTransformer([('Geography',OneHotEncoder(categories='auto'),[1])],remainder='passthrough')
Upvotes: 3