Skip to content

Select all list columns

Source code

Description

[Experimental]

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]        │
#> └──────────────┴────────────────┘
# Select all columns except for those that are list:
df$select(!cs$list())
#> 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"]        │
#> └──────────────┘