Skip to content Skip to sidebar Skip to footer

How To One Hot Encode With Pandas On A New Dataset?

I have a training data set that has categorical features on which I use pd.get_dummies to one hot encode. This produces a data set with n features. I then train a classification mo

Solution 1:

For example ,

You have tradf with column ['A_1','A_2']

With your new df you have column['A'] but only have one category 1 , you can do

pd.get_dummies(df).reindex(columns=tradf.columns,fill_value=0)

Post a Comment for "How To One Hot Encode With Pandas On A New Dataset?"