Select all struct columns
Description
Usage
cs__struct()
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$list()
: Select all list columns. -
cs$array()
: Select all array columns. -
cs$nested()
: Select all nested columns.
Examples
library("polars")
df <- pl$DataFrame(
foo = data.frame(a = c("xx", "x"), b = c("yy", "y")),
bar = data.frame(a = c(123, 456), b = c(789, 101)),
baz = c(2.0, 5.5),
)
# Select all struct columns:
df$select(cs$struct())
#> shape: (2, 2)
#> ┌─────────────┬───────────────┐
#> │ foo ┆ bar │
#> │ --- ┆ --- │
#> │ struct[2] ┆ struct[2] │
#> ╞═════════════╪═══════════════╡
#> │ {"xx","yy"} ┆ {123.0,789.0} │
#> │ {"x","y"} ┆ {456.0,101.0} │
#> └─────────────┴───────────────┘
#> shape: (2, 1)
#> ┌─────┐
#> │ baz │
#> │ --- │
#> │ f64 │
#> ╞═════╡
#> │ 2.0 │
#> │ 5.5 │
#> └─────┘
# If you want to select specific struct columns,
# you can use the `by_dtype()` selector:
df$select(cs$by_dtype(pl$Struct(
a = pl$String,
b = pl$String
)))
#> shape: (2, 1)
#> ┌─────────────┐
#> │ foo │
#> │ --- │
#> │ struct[2] │
#> ╞═════════════╡
#> │ {"xx","yy"} │
#> │ {"x","y"} │
#> └─────────────┘