Skip to content

Instantly share code, notes, and snippets.

@socratesk
Last active November 3, 2018 19:17
Show Gist options
  • Save socratesk/f8d7228d259acb3d82b07256ba475330 to your computer and use it in GitHub Desktop.
Save socratesk/f8d7228d259acb3d82b07256ba475330 to your computer and use it in GitHub Desktop.
import pandas as pd
from sklearn import preprocessing
countryDF = pd.DataFrame({'id' : [101, 102, 103],
'country' : ['NZ', 'BR', 'US']})
labelEncode = preprocessing.LabelEncoder()
countryDF['countryLabel'] = labelEncode.fit_transform(countryDF['country'])
countryDF.drop(['country'], axis=1, inplace=True)
print(countryDF)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment