Select all list columns
Description
Usage
cs__list(inner = NULL)
Arguments
inner
|
An optional inner selector to select columns having specific inner data
types. If NULL , all inner types are selected.
|
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$array()
: Select all array columns. -
cs$nested()
: Select all nested columns.
Examples
library("polars")
df <- pl$DataFrame(
foo = list(c("xx", "yy"), "x"),
bar = list(c(123, 456), 789),
baz = c(2.0, 5.5),
)
# Select all list columns:
df$select(cs$list())
#> shape: (2, 2)
#> ┌──────────────┬────────────────┐
#> │ foo ┆ bar │
#> │ --- ┆ --- │
#> │ list[str] ┆ list[f64] │
#> ╞══════════════╪════════════════╡
#> │ ["xx", "yy"] ┆ [123.0, 456.0] │
#> │ ["x"] ┆ [789.0] │
#> └──────────────┴────────────────┘
#> shape: (2, 1)
#> ┌─────┐
#> │ baz │
#> │ --- │
#> │ f64 │
#> ╞═════╡
#> │ 2.0 │
#> │ 5.5 │
#> └─────┘
# If you want to select specific list columns,
# you can specify the inner data type with a selector:
df$select(cs$list(cs$string()))
#> shape: (2, 1)
#> ┌──────────────┐
#> │ foo │
#> │ --- │
#> │ list[str] │
#> ╞══════════════╡
#> │ ["xx", "yy"] │
#> │ ["x"] │
#> └──────────────┘