Drop#
- class skrub.Drop[source]#
Drop the selected DataFrame’s column unconditionally.
A note on using single column transformations
Dropis a type of single column transformation . Unlike most scikit-learn estimators, itsfit,transformandfit_transformmethods expect a single column (e.g. Series) not a full dataframe. To apply this transformer to one or more columns in a dataframe, use it in aApplyToColsor aTableVectorizer.To apply to all columns:
ApplyToCols(Drop())
To apply to selected columns:
ApplyToCols(Drop(), cols=['col_name_1', 'col_name_2'])
The other columns are kept in their original order. A
ValueErroris raised if any of the provided column names are not in the dataframe. This transformer is different fromDropColsin that it is designed to be used with other transformers, for example to remove all columns with a given type from a transformation.- Parameters:
See also
DropColsdrop columns by name, or skrub selectors.
ApplyToColsCan be used to Apply a transformer to selected columns in a dataframe.
TableVectorizerTransform a dataframe to a numeric (vectorized) representation.
Examples
Dropis meant to be used with other transformers to drop columns with a given type or other property.For example, if we want to vectorize a dataframe but drop the numeric columns, we can do:
>>> import pandas as pd >>> from skrub import Drop >>> df = pd.DataFrame({"num": [1,2,3], "text": ["hello", "world", "foo"]}) >>> df num text 0 1 hello 1 2 world 2 3 foo >>> from skrub import TableVectorizer >>> TableVectorizer(numeric=Drop()).fit_transform(df) text_foo text_hello text_world 0 0.0 1.0 0.0 1 0.0 0.0 1.0 2 1.0 0.0 0.0
Here, only the “text” column is vectorized, and the “num” column is dropped entirely.
Methods
fit(column[, y])Fit the transformer.
get_feature_names_out([input_features])Get the output feature names.
get_params([deep])Get parameters for this estimator.
set_output(*[, transform])Default no-op implementation for set_output.
set_params(**params)Set the parameters of this estimator.
set_transform_request(*[, column])Configure whether metadata should be requested to be passed to the
transformmethod.fit_transform
transform
- fit(column, y=None, **kwargs)[source]#
Fit the transformer.
This default implementation simply calls
fit_transform()and returnsself.Subclasses should implement
fit_transformandtransform.- Parameters:
- columna pandas or polars
Series Unlike most scikit-learn transformers, single-column transformers transform a single column, not a whole dataframe.
- ycolumn or dataframe
Prediction targets.
- **kwargs
Extra named arguments are passed to
self.fit_transform().
- columna pandas or polars
- Returns:
- self
The fitted transformer.
- get_feature_names_out(input_features=None)[source]#
Get the output feature names.
- Parameters:
- input_featuresarray_like of
str, default=None Input feature names. Ignored.
- input_featuresarray_like of
- Returns:
- set_output(*, transform=None)[source]#
Default no-op implementation for set_output.
Skrub transformers already output dataframes of the correct type by default so there is usually no need for set_output to do anything.
Subclasses are of course free to redefine set_output (e.g. by inheriting from
TransformerMixinbefore SingleColumnTransformer).
- set_params(**params)[source]#
Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as
Pipeline). The latter have parameters of the form<component>__<parameter>so that it’s possible to update each component of a nested object.- Parameters:
- **params
dict Estimator parameters.
- **params
- Returns:
- selfestimator instance
Estimator instance.
- set_transform_request(*, column='$UNCHANGED$')[source]#
Configure whether metadata should be requested to be passed to the
transformmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed totransformif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it totransform.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.