Skip to content

Select all enum columns

Source code

Description

[Experimental]

Usage

cs__enum()

Value

A Polars selector

See Also

  • cs for the documentation on operators supported by selectors.
  • cs$by_dtype(): Select all columns matching the given dtype(s).
  • cs$categorical(): Select all categorical columns.

Examples

library("polars")

df <- pl$DataFrame(
  foo = c("xx", "yy"),
  bar = c("aa", "bb"),
  baz = c(2.0, 5.5),
  .schema_overrides = list(
    foo = pl$Enum(c("xx", "yy")),
    bar = pl$Enum(c("aa", "bb"))
  )
)

# Select all enum columns:
df$select(cs$enum())
#> shape: (2, 2)
#> ┌──────┬──────┐
#> │ foo  ┆ bar  │
#> │ ---  ┆ ---  │
#> │ enum ┆ enum │
#> ╞══════╪══════╡
#> │ xx   ┆ aa   │
#> │ yy   ┆ bb   │
#> └──────┴──────┘
# Select all columns except for those that are enum:
df$select(!cs$enum())
#> shape: (2, 1)
#> ┌─────┐
#> │ baz │
#> │ --- │
#> │ f64 │
#> ╞═════╡
#> │ 2.0 │
#> │ 5.5 │
#> └─────┘
# If you want to select specific enum columns,
# you can use the `by_dtype()` selector:
df$select(cs$by_dtype(pl$Enum(c("aa", "bb"))))
#> shape: (2, 1)
#> ┌──────┐
#> │ bar  │
#> │ ---  │
#> │ enum │
#> ╞══════╡
#> │ aa   │
#> │ bb   │
#> └──────┘