4

I want to one-hot encode multiple columns in my data frame at once using Keras to_categorical. How to do it?

need_to_encode = ['Item_Fat_Content', 'Outlet_Location_Type', 'Outlet_Type', 'Outlet_Size', 'Item_Type_Combined', 'Outlet']

These are the columns I need to one-hot encode.

Mathanraj-Sharma
  • 354
  • 1
  • 3
  • 7

1 Answers1

3

Well you could use this util function over every column that needs encoding of your data.

Or you use scikit-learn's categorical encoder on the part of the dataframe you need to encode.

Next time don't forget to include a minimal working example, this way we can help further.

Zaccharie Ramzi
  • 2,106
  • 1
  • 18
  • 37