Unexpected keyword arg 'categorical_features' in one hot encoding

I’m getting the following error:

error : oneHot = OneHotEncoder(categorical_features = [0]) TypeError: init() got an unexpected keyword argument 'categorical_features'.

I’m trying to one-hot encode the 0th column in the following dataset:

0th column is what I'm trying to one hot encode

I’m getting the following error when I run the following code:

from sklearn.preprocessing import LabelEncoder,OneHotEncoder 
labelen_x = LabelEncoder() # string to numeric encoding object
x[:,0]= labelen_x.fit_transform(x[:,0]) # replaces the string labels with numerics for ML algorithm to be able to work with it
oneHot = OneHotEncoder(categorical_features = [0])
x = oneHot.fit_transform(x).toarray()

Error:

oneHot = OneHotEncoder(categorical_features = [0]) TypeError: init() got an unexpected keyword argument 'categorical_features'.

I’m trying to one-hot encode the 0th column in the following dataset:

0th column is what I'm trying to one hot encode

I’m using LabelEncoder and OneHotEncoder from sklearn.preprocessing and running the following code:

from sklearn.preprocessing import LabelEncoder,OneHotEncoder 
labelen_x = LabelEncoder() # string to numeric encoding object
x[:,0]= labelen_x.fit_transform(x[:,0]) # replaces the string labels with numerics for ML algorithm to be able to work with it
oneHot = OneHotEncoder(categorical_features = [0])
x = oneHot.fit_transform(x).toarray()

I’m getting the following error:

error : oneHot = OneHotEncoder(categorical_features = [0]) TypeError: init() got an unexpected keyword argument 'categorical_features'.

I’m trying to one-hot encode the 0th column of the following dataset:

0th column is what I'm trying to one hot encode

I’m using sklearn.preprocessing’s LabelEncoder and OneHotEncoder and running the following code:

from sklearn.preprocessing import LabelEncoder,OneHotEncoder 
labelen_x = LabelEncoder() # string to numeric encoding object
x[:,0]= labelen_x.fit_transform(x[:,0]) # replaces the string labels with numerics 
oneHot = OneHotEncoder(categorical_features = [0])
x = oneHot.fit_transform(x).toarray()

I’m getting the following error:

error : oneHot = OneHotEncoder(categorical_features = [0]) TypeError: init() got an unexpected keyword argument 'categorical_features'.

I’m trying to one-hot encode the 0th column of the following dataset:

0th column is what I'm trying to one hot encode

I’m using LabelEncoder and OneHotEncoder from sklearn.preprocessing and running the following code:

from sklearn.preprocessing import LabelEncoder,OneHotEncoder 
labelen_x = LabelEncoder() # string to numeric encoding object
x[:,0]= labelen_x.fit_transform(x[:,0]) # replaces the string labels with numerics 
oneHot = OneHotEncoder(categorical_features = [0])
x = oneHot.fit_transform(x).toarray()

I’m getting the following error:

error : oneHot = OneHotEncoder(categorical_features = [0]) TypeError: init() got an unexpected keyword argument 'categorical_features'.

I’m trying to one-hot encode the 0th column in the following dataset:

0th column is what I'm trying to one hot encode

I’m using sklearn.preprocessing’s LabelEncoder and OneHotEncoder and running the following code:

from sklearn.preprocessing import LabelEncoder,OneHotEncoder 
labelen_x = LabelEncoder() # string to numeric encoding object
x[:,0]= labelen_x.fit_transform(x[:,0]) # replaces the string labels with numerics 
oneHot = OneHotEncoder(categorical_features = [0])
x = oneHot.fit_transform(x).toarray()

I’m getting the following error:

error : oneHot = OneHotEncoder(categorical_features = [0]) TypeError: init() got an unexpected keyword argument 'categorical_features'.

I’m trying to one-hot encode the 0th column of the following dataset:

0th column is what I'm trying to one hot encode

I’m using LabelEncoder and OneHotEncoder from sklearn.preprocessing and running the following code:

from sklearn.preprocessing import LabelEncoder,OneHotEncoder 
labelen_x = LabelEncoder() # string to numeric encoding object
x[:,0]= labelen_x.fit_transform(x[:,0]) # replaces the string labels with numerics 
oneHot = OneHotEncoder(categorical_features = [0])
x = oneHot.fit_transform(x).toarray()

I’m getting the following error:

error : oneHot = OneHotEncoder(categorical_features = [0]) TypeError: init() got an unexpected keyword argument 'categorical_features'.

I’m trying to one-hot encode the 0th column of the following dataset:

0th column is what I'm trying to one hot encode

I’m using sklearn.preprocessing’s LabelEncoder and OneHotEncoder and getting the following error when running the following code:

from sklearn.preprocessing import LabelEncoder,OneHotEncoder 
labelen_x = LabelEncoder() # string to numeric encoding object
x[:,0]= labelen_x.fit_transform(x[:,0]) # replaces the string labels with numerics 
oneHot = OneHotEncoder(categorical_features = [0])
x = oneHot.fit_transform(x).toarray()

Error:

oneHot = OneHotEncoder(categorical_features = [0]) TypeError: init() got an unexpected keyword argument 'categorical_features'.

categorical_features is no longer a valid argument in the OneHotEncoder constructor. Instead, you should use ColumnTransformer to specify the columns to be one-hot encoded. Here’s how to modify your code:

from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import OneHotEncoder, LabelEncoder

labelen_x = LabelEncoder()
x[:, 0] = labelen_x.fit_transform(x[:, 0])
ct = ColumnTransformer(transformers=[('encoder', OneHotEncoder(), [0])], remainder='passthrough')
x = ct.fit_transform(x)