Exclude columns from a multi-column expression.
Description
Exclude columns from a multi-column expression.
Usage
<Expr>$exclude(...)
Arguments
…
|
The name or datatype of the column(s) to exclude. Accepts regular
expression input. Regular expressions should start with ^
and end with $ .
|
Value
A polars expression
Examples
#> shape: (2, 3)
#> ┌─────┬──────┬──────┐
#> │ aa ┆ ba ┆ cc │
#> │ --- ┆ --- ┆ --- │
#> │ i32 ┆ str ┆ f64 │
#> ╞═════╪══════╪══════╡
#> │ 1 ┆ a ┆ null │
#> │ 2 ┆ null ┆ 2.5 │
#> └─────┴──────┴──────┘
#> shape: (2, 2)
#> ┌─────┬──────┐
#> │ aa ┆ cc │
#> │ --- ┆ --- │
#> │ i32 ┆ f64 │
#> ╞═════╪══════╡
#> │ 1 ┆ null │
#> │ 2 ┆ 2.5 │
#> └─────┴──────┘
# Exclude by regex, e.g. removing all columns whose names end with the
# letter "a":
df$select(pl$all()$exclude("^.*a$"))
#> shape: (2, 1)
#> ┌──────┐
#> │ cc │
#> │ --- │
#> │ f64 │
#> ╞══════╡
#> │ null │
#> │ 2.5 │
#> └──────┘
# Exclude by dtype(s), e.g. removing all columns of type Int64 or Float64:
df$select(pl$all()$exclude(pl$Int64, pl$Float64))
#> shape: (2, 2)
#> ┌─────┬──────┐
#> │ aa ┆ ba │
#> │ --- ┆ --- │
#> │ i32 ┆ str │
#> ╞═════╪══════╡
#> │ 1 ┆ a │
#> │ 2 ┆ null │
#> └─────┴──────┘