one hot encoding python pandas

Do you want to know the information regarding “one hot encoding python pandas”. If yes, you’re in the correct post.

one hot encoding python pandas

y = pd.get_dummies(df.Countries, prefix='Country')
print(y.head())
# from here you can merge it onto your main DF
from sklearn.preprocessing import MultiLabelBinarizer

mlb = MultiLabelBinarizer()
df = df.join(pd.DataFrame(mlb.fit_transform(df.pop('Col3')),
                          columns=mlb.classes_,
                          index=df.index))

Final Words

I hope this article helps you to know about “one hot encoding python pandas”. If you have any doubts regarding this tutorial please let us know via the comment section. Share this article with your friends & family via social networks.

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coder Diksha. Here, I post about programming to help developers.

Share on:

Leave a Comment