2
$\begingroup$

I'm working with a heterogenous dataset that includes numerical and categorical columns. I want to use Scikit-Learn's ColumnTransformer to OneHotEncode the categorical data, however, ColumnTransformer will only recombine the columns that I apply a transformer to.

I don't want to apply a transformer to the numerical columns, how can I let the non-transformed values through the function unchanged and included in the output?

$\endgroup$

1 Answer 1

2
$\begingroup$

ColumnTransformer comes with an option called remainder, by default it's set to 'drop' which means columns that aren't used by a transformer are dropped from the dataframe.

Setting this option to remainder='passthrough' will let the unused columns pass through the function and join the returned dataframe unchanged.

The implementation in code looks like this:

ColumnTransformer(transformers=YOUR_TRANSFORMER_LIST_HERE, 
                  remainder='passthrough')
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.