How to give column names after one-hot encoding with sklearn?

You can get the column names using .get_feature_names() attribute.

>>> ohenc.get_feature_names()
>>> x_cat_df.columns = ohenc.get_feature_names()

Detailed example is here.

Update

from Version 1.0, use get_feature_names_out

Leave a Comment