Sklearn pipeline I am using has multiple transformers but one of the initial transformers returns numerical type and the consecutive one takes object type variables.

Basically I need squeeze in a:

data[col] = data[col].astype(object)

for the required columns within the pipeline.

Is there any way to do it?

Note: I am using Feature-engine transformers.


1 Answer 1


You sure can.

One solution off the bat is to extend your estimator that takes object type variables. So what does that mean.

Library that you said are all estimators in the sklearn form fit, predict methodology. So all you have to do is something as follows:

> class modifiedTraf(oldTraf):
>        def __init__(self):
>           super(modifiedTraf, self).__init__():
> bla bla   
>       def fit(self, X):
>           X[col] = X[col].astype(object)
>           super(modifiedTraf,self).fit(X)
>           return self
>       def transform(self, X):
>           X[col] = X[col].astype(object)
>           X=super(modifiedTraf,self).transform(X)
>           return X

Learn more about overriding sklearn classes and super argument for example here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.