Menu Close

How to hot encode in Python Pandas?

Sometimes, we want to hot encode in Python Pandas.

In this article, we’ll look at how o hot encode in Python Pandas.

How to hot encode in Python Pandas?

To hot encode in Python Pandas, we an use the get_dummies method.

For instance, we write

import pandas as pd

s = pd.Series(list('abca'))
pd.get_dummies(s)

to create a series from the list with pd.Series.

Then we call get_dummies with series s to convert the categorical variable into dummy/indicator variables.

Conclusion

To hot encode in Python Pandas, we an use the get_dummies method.

Posted in Python, Python Answers