## StepDropZeroVariance


Remove columns that have a single unique value (zero variance).


Usage

``` python
StepDropZeroVariance(
    columns,
    *,
    id=None,
)
```


The selected columns whose observed values are all the same (or all missing) are dropped, and no new columns are produced. For a looser rule that also drops columns dominated by one value, see [StepDropNearZeroVariance](StepDropNearZeroVariance.md#mlfeatures.StepDropNearZeroVariance).

See [Zero Variance Filter](https://feaz-book.com/too-many-zv) in *Feature Engineering A to Z* for background on this technique.

See [Arguments shared across steps](../user-guide/common-step-arguments.md) for the arguments this step shares with the others.


## Parameters


`columns: Selector`  
Columns to consider for removal. Accepts a single column name, a list of names, a mlfeatures selector such as [Selectors.features()](Selectors.md#mlfeatures.Selectors.features) (see [Selectors](Selectors.md#mlfeatures.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`  
Stable step identifier. Defaults to `"zv"`; a second step of this type in the same recipe becomes `"zv_2"`, and passing an `id` already used in the recipe is an error.


## Examples

`const` has a single unique value, so it is dropped; `x` is kept:


``` python
df = pd.DataFrame({"x": [1.0, 2.0, 3.0], "const": [5.0, 5.0, 5.0]})
df
```


|     | x   | const |
|-----|-----|-------|
| 0   | 1.0 | 5.0   |
| 1   | 2.0 | 5.0   |
| 2   | 3.0 | 5.0   |


Specifying the step touches no data:


``` python
recipe = Recipe().add(StepDropZeroVariance(s.numeric_features()))
recipe
```


    Recipe (untrained)
      Inputs: no roles assigned
      Steps:
        step_drop_zero_variance(select(role='feature', type=NumericType))  [untrained]


[fit()](Step.fit.md#mlfeatures.Step.fit) counts the unique values in each column:


``` python
fitted = recipe.fit(df)
fitted
```


    Recipe (trained)
      Inputs: 1 columns (1 feature)
      Steps:
        step_drop_zero_variance(x, const)  [trained]


[transform()](Step.transform.md#mlfeatures.Step.transform) drops the constant one:


``` python
fitted.transform(df)
```


|     | x   |
|-----|-----|
| 0   | 1.0 |
| 1   | 2.0 |
| 2   | 3.0 |
