Last active
February 21, 2019 08:15
-
-
Save hellpanderrr/a35be9ef3a5582a354d8 to your computer and use it in GitHub Desktop.
One hot encode a dataframe in pandas and sklearn
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
| from sklearn.feature_extraction import DictVectorizer as DV | |
| vectorizer = DV(sparse = False) | |
| v = vectorizer.fit_transform(df.T.to_dict().values()) | |
| new_df = pd.DataFrame(v, columns=vectorizer.feature_names_) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment