Skip to content

Instantly share code, notes, and snippets.

@treper
Created April 6, 2017 16:19
Show Gist options
  • Save treper/67fd7b87f4d6bb76964967068e73284a to your computer and use it in GitHub Desktop.
Save treper/67fd7b87f4d6bb76964967068e73284a to your computer and use it in GitHub Desktop.
from sklearn.preprocessing import LabelEncoder
from collections import defaultdict
encoders_dict = defaultdict(LabelEncoder)
categorical = ['age']
users2 = users.apply(lambda x: encoders_dict[x.name].fit_transform(x.astype(str)) if x.name in categorical else x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment