Reputation: 117
I am trying to use OneHotEncoding to transform the second column of my csv file, which consists of company names.
from sklearn.preprocessing import OneHotEncoder
ct = ColumnTransformer(transformers=[('encoder', OneHotEncoder(), [1])]), remainder='passthrough'
X = np.array(ct.fit_transform(X))
and I received this error:
ct = ColumnTransformer(transformers=[('encoder', OneHotEncoder(), [1])]), remainder='passthrough'
^
SyntaxError: can't assign to function call
Where did i go wrong? I understand that perhaps there is an error with how I wrote the ct line, but i do not know exactly what I did wrong.
Upvotes: 0
Views: 159
Reputation: 1
you can call columntransformer from sklearn.compose first write the code like this from sklearn.compose import ColumnTransformer from sklearn.preprocessing import OneHotEncoder ct = ColumnTransformer(transformers=[('encoder', OneHotEncoder(), [1])]), remainder='passthrough' X = np.array(ct.fit_transform(X))
Upvotes: 0
Reputation: 2478
I think you set a bracket incorrectly and it should probably be like this:
ct = ColumnTransformer(transformers=[('encoder', OneHotEncoder(), [1])], remainder='passthrough')
Upvotes: 1