-1

I have a column in a dataframe with values as XS, S, M, L, XL and XXL. What i want is to have 6 new columns in dataframe as XS, S, M, L, XL and XXL and each having a binary value referenced from the column. Is this possible?

I attended a lecture in which the instructor used something similar to this but I can't really put my finger on how she did it or what was the method called.

Any help, whatsoever is appreciated.

Sandy
  • 21
  • 3
  • 1
    Does this answer your question? [How can I one hot encode in Python?](https://stackoverflow.com/questions/37292872/how-can-i-one-hot-encode-in-python) – smarie Mar 31 '20 at 12:13

1 Answers1

2

I think what you're looking for is called One Hot Encoding.

And it is super easy to implement using scikit-learn. Just try the following:

df = pd.get_dummies(df, prefix=['SIZE'], columns=['SIZE'])

here you will have to import sci-kitlearn first. Also 'pd' is the dataframe where you have the SIZE column. Give it a go.

Atharva
  • 611
  • 3
  • 9