How to encode more than one column with column transformer?

I want to encode more than one column with columtransformer. Do you know how to add those?

from sklearn.preprocessing import LabelEncoder
from sklearn.compose import make_column_transformer
transformer = make_column_transformer(( OneHotEncoder(categories='auto'), [1] ),remainder="passthrough")
X = transformer.fit_transform(X)

LabelEncoder_Y = LabelEncoder()
y = LabelEncoder_Y.fit_transform(y)

image

Upvotes: 2

Views: 5055

Answers (1)

Mankind_2000
Mankind_2000

Reputation: 2208

For make_column_transformer provide a list of indices/ column names for columns you need to encode and transform. For eg, if you need column index 0 and 1:

transformer = make_column_transformer( (OneHotEncoder(categories='auto'), 
                                       [0, 1]), remainder="passthrough" )

Upvotes: 3

Related Questions