Skip to content

Instantly share code, notes, and snippets.

@kshirsagarsiddharth
Created March 20, 2022 17:57
Show Gist options
  • Save kshirsagarsiddharth/c257bdafc9ede2c0ebd31a6f6384ed7f to your computer and use it in GitHub Desktop.
Save kshirsagarsiddharth/c257bdafc9ede2c0ebd31a6f6384ed7f to your computer and use it in GitHub Desktop.
oh_encoder = OneHotEncoder(handle_unknown='ignore', sparse=False)
oh_cols_train = pd.DataFrame(oh_encoder.fit_transform(X_train[unordered_columns]))
oh_cols_valid = pd.DataFrame(oh_encoder.transform(X_valid[unordered_columns]))
# One-hot encoding removed index; put it back
oh_cols_train.index = X_train.index
oh_cols_valid.index = X_valid.index
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment