Created
February 5, 2016 04:47
-
-
Save mrahul17/b5e75777be965d28fbcf to your computer and use it in GitHub Desktop.
Label encoder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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