Skip to content

Instantly share code, notes, and snippets.

@vanbrands
Last active July 10, 2020 01:54
Show Gist options
  • Save vanbrands/5fb088b1ba4424a3977f58ca1b453bc9 to your computer and use it in GitHub Desktop.
Save vanbrands/5fb088b1ba4424a3977f58ca1b453bc9 to your computer and use it in GitHub Desktop.
# You have you set of possible categories in a list for example.
# (it could be anything really...)
possible_categories = ['foo', 'bar]
# Convert the categorical column to type Categorical
df['categorical_column'] = pd.Categorical(
values=df['categorical_column'],
categories=possible_categories
)
dummies = pd.get_dummies(df['categorical_column'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment