pandas - How can I one hot encode in Python? - Stack Overflow

PHOTO EMBED

Tue Mar 16 2021 19:38:30 GMT+0000 (Coordinated Universal Time)

Saved by @chenyangsu #python

import pandas as pd
s = pd.Series(list('abca'))
pd.get_dummies(s)
Out[]: 
     a    b    c
0  1.0  0.0  0.0
1  0.0  1.0  0.0
2  0.0  0.0  1.0
3  1.0  0.0  0.0
content_copyCOPY

https://stackoverflow.com/questions/37292872/how-can-i-one-hot-encode-in-python