Skip to content

Instantly share code, notes, and snippets.

@lfarroco
Last active May 21, 2017 14:23
Show Gist options
  • Save lfarroco/b3516b92a797e93656bf2a7c69ed0f36 to your computer and use it in GitHub Desktop.
Save lfarroco/b3516b92a797e93656bf2a7c69ed0f36 to your computer and use it in GitHub Desktop.
One-hot Encoding using Pandas DataFrames
import pandas as pd
data = pd.DataFrame([
["Team A",1,0],
["Team B",0,1]],
columns=["Team","Attribute A","Attribute B"])
pd.get_dummies(data)
#Output will be:
# Attribute A Attribute B Team_Team A Team_Team B
#0 1 0 1 0
#1 0 1 0 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment