Created
July 3, 2017 08:07
-
-
Save mzaradzki/275d718687040d36cc776351918dc3b3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dfOHE = None | |
for col in categories: # encode 1 category at a time | |
one_hot = pd.get_dummies(df[col], prefix=col) | |
# drop column as it is now encoded | |
if dfOHE is None: | |
dfOHE = df.drop(col, axis=1) | |
else: | |
dfOHE = dfOHE.drop(col, axis=1) | |
# join the encoded dataframe | |
dfOHE = dfOHE.join(one_hot) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment