from sklearn.preprocessing import OrdinalEncoder

CATEGORICAL_COLS = {{ columns }}
ordinal_encoder = OrdinalEncoder(handle_unknown="use_encoded_value", unknown_value=-1)
{{ train_dataset }}[CATEGORICAL_COLS] = ordinal_encoder.fit_transform({{ train_dataset }}[CATEGORICAL_COLS])
{{ test_dataset }}[CATEGORICAL_COLS] = ordinal_encoder.transform({{ test_dataset }}[CATEGORICAL_COLS])