df = pd.DataFrame({"x": [1.0, 2.0, 3.0], "note": ["a", "b", "c"]})
df| x | note | |
|---|---|---|
| 0 | 1.0 | a |
| 1 | 2.0 | b |
| 2 | 3.0 | c |
Remove the selected columns.
Usage
Every column the selector matches is dropped, and no new columns are produced. Nothing is estimated: which columns to drop is decided by the selector alone, fixed against the training data frame’s schema. To drop columns by a data-driven rule instead, see StepDropCorr, StepDropZeroVariance or StepDropNearZeroVariance.
The selection is taken at face value, so a selector that reaches a column with a role other than "feature" drops that column too.
See Arguments shared across steps for the arguments this step shares with the others.
columns: SelectorColumns to remove. Accepts a single column name, a list of names, a mlfeatures selector such as Selectors.features() (see Selectors for the full set), or a narwhals or polars selector (narwhals.selectors.numeric(), polars.selectors.numeric()). Selectors are resolved against the data frame’s schema when the recipe is fitted, so the same selector works on any backend. Any dtype is accepted.
id: str | None = None"drop"; a second step of this type in the same recipe becomes "drop_2", and passing an id already used in the recipe is an error.
It is often easier to say what to remove than to enumerate what to keep:
| x | note | |
|---|---|---|
| 0 | 1.0 | a |
| 1 | 2.0 | b |
| 2 | 3.0 | c |
Specifying the step touches no data:
Recipe (untrained)
Inputs: no roles assigned
Steps:
step_drop(select(role='feature', type=String)) [untrained]
fit() resolves the selector against the training schema:
Recipe (trained)
Inputs: 1 columns (1 feature)
Steps:
step_drop(note) [trained]
transform() drops the columns it matched: