Skip to content

Instantly share code, notes, and snippets.

@mrahul17
Created February 5, 2016 04:47
Show Gist options
  • Select an option

  • Save mrahul17/b5e75777be965d28fbcf to your computer and use it in GitHub Desktop.

Select an option

Save mrahul17/b5e75777be965d28fbcf to your computer and use it in GitHub Desktop.
Label encoder
def clean_data(train,test):
obj_cols = [] #list to store columns that have been read as objects
for col in train.columns:
if train[col].dtype==object:
obj_cols.append(col)
preprocessor = preprocessing.LabelEncoder()
for col in obj_cols:
preprocessor.fit(list(train[col].values) + list(test[col].values))
train[col] = preprocessor.transform(list(train[col].values))
test[col] = preprocessor.transform(list(test[col].values))
return train,test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment