polars.exclude

polars.exclude(columns: Union[str, List[str]]) polars.internals.expr.Expr

Exclude certain columns from a wildcard expression.

Syntactic sugar for:

>>> pl.col("*").exclude(columns)  
Parameters
columns

Column(s) to exclude from selection

Examples

>>> df = pl.DataFrame(
...     {
...         "a": [1, 2, 3],
...         "b": ["a", "b", None],
...         "c": [None, 2, 1],
...     }
... )
>>> df
shape: (3, 3)
┌─────┬──────┬──────┐
│ a   ┆ b    ┆ c    │
│ --- ┆ ---  ┆ ---  │
│ i64 ┆ str  ┆ i64  │
╞═════╪══════╪══════╡
│ 1   ┆ a    ┆ null │
├╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤
│ 2   ┆ b    ┆ 2    │
├╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤
│ 3   ┆ null ┆ 1    │
└─────┴──────┴──────┘
>>> df.select(pl.exclude("b"))
shape: (3, 2)
┌─────┬──────┐
│ a   ┆ c    │
│ --- ┆ ---  │
│ i64 ┆ i64  │
╞═════╪══════╡
│ 1   ┆ null │
├╌╌╌╌╌┼╌╌╌╌╌╌┤
│ 2   ┆ 2    │
├╌╌╌╌╌┼╌╌╌╌╌╌┤
│ 3   ┆ 1    │
└─────┴──────┘