Get the physical values of a Categorical or Enum data type
Description
Get the physical representation of a Categorical or an Enum column,
i.e. the integer codes used to store the categories.
Usage
<Expr>$cat$physical()
Value
A polars expression
See Also
-
\$cat$to()
Examples
library("polars")
df <- pl$DataFrame(x = c("foo", "bar", "foo", "x", NA))$cast(
pl$Enum(c("bar", "foo", "x"))
)
df$with_columns(physical = pl$col("x")$cat$physical())
#> shape: (5, 2)
#> ┌──────┬──────────┐
#> │ x ┆ physical │
#> │ --- ┆ --- │
#> │ enum ┆ u8 │
#> ╞══════╪══════════╡
#> │ foo ┆ 1 │
#> │ bar ┆ 0 │
#> │ foo ┆ 1 │
#> │ x ┆ 2 │
#> │ null ┆ null │
#> └──────┴──────────┘