Skip to content


Wrapper to keep column names of pandas dataframes in a scikit-learn transformer.

Any scikit-learn transformer wrapped in KeepPandas will return a pd.DataFrame on .transform().


You should only use KeepPandas() when you know for sure scikit-learn did not change the order of your columns.


from skorecard.pipeline import KeepPandas
from skorecard import datasets
from skorecard.bucketers import EqualWidthBucketer

from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler

X, y = datasets.load_uci_credit_card(return_X_y=True)

bucket_pipeline = make_pipeline(
    EqualWidthBucketer(n_bins=5, variables=['LIMIT_BAL', 'BILL_AMT1']),
bucket_pipeline.fit_transform(X, y)

__init__(self, transformer) special


__repr__(self) special

String representation.

fit(self, X, y=None, *args, **kwargs)

Fit estimator.

fit_transform(self, X, y=None, **fit_params) inherited

Fit to data, then transform it.

Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.


X : array-like of shape (n_samples, n_features) Input samples.

y : array-like of shape (n_samples,) or (n_samples, n_outputs), default=None Target values (None for unsupervised transformations).

**fit_params : dict Additional fit parameters.


X_new : ndarray array of shape (n_samples, n_features_new) Transformed array.


Return estimator feature names.

get_params(self, deep=True) inherited

Get parameters for this estimator.


deep : bool, default=True If True, will return the parameters for this estimator and contained subobjects that are estimators.


params : dict Parameter names mapped to their values.

set_params(self, **params) inherited

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as :class:~sklearn.pipeline.Pipeline). The latter have parameters of the form <component>__<parameter> so that it's possible to update each component of a nested object.


**params : dict Estimator parameters.


self : estimator instance Estimator instance.

transform(self, X, *args, **kwargs)

Transform X.

Last update: 2021-11-24
Back to top