Skip to content

Instantly share code, notes, and snippets.

@vanessaaleung
Last active September 28, 2019 17:53
Show Gist options
  • Save vanessaaleung/2ec7ad1c23aedaaecac317dd4096821e to your computer and use it in GitHub Desktop.
Save vanessaaleung/2ec7ad1c23aedaaecac317dd4096821e to your computer and use it in GitHub Desktop.
# one hot encoding
sf_onehot = pd.get_dummies(sf_venues[['Venue Category']], prefix = "", prefix_sep = "")
# add neighborhood column back to dataframe
sf_onehot['Neighborhood'] = sf_venues['Neighborhood']
# move neighborhood column to the first column
fixed_columns = [sf_onehot.columns[-1]] + list(sf_onehot.columns[:-1])
sf_onehot = sf_onehot[fixed_columns]
sf_onehot.head()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment