Create an expression representing column(s) in a dataframe
Description
Create an expression representing column(s) in a dataframe
Usage
pl$col(...)
Arguments
…
|
One of the following:
|
Value
Expr of a column or columns
Examples
#> polars Expr: col("foo")
#> polars Expr: cols(["foo", "bar"])
#> polars Expr: dtype_columns([Float64, String])
#> polars Expr: *
# multiple character vectors and a list of RPolarsDataTypes are also allowed
pl$col(c("foo", "bar"), "baz")
#> polars Expr: cols(["foo", "bar", "baz"])
#> polars Expr: cols(["foo", "bar", "baz"])
#> polars Expr: dtype_columns([Float64, String])
# there are some special notations for selecting columns
df = pl$DataFrame(foo = 1:3, bar = 4:6, baz = 7:9)
# select all columns with a wildcard `"*"`
df$select(pl$col("*"))
#> shape: (3, 3)
#> ┌─────┬─────┬─────┐
#> │ foo ┆ bar ┆ baz │
#> │ --- ┆ --- ┆ --- │
#> │ i32 ┆ i32 ┆ i32 │
#> ╞═════╪═════╪═════╡
#> │ 1 ┆ 4 ┆ 7 │
#> │ 2 ┆ 5 ┆ 8 │
#> │ 3 ┆ 6 ┆ 9 │
#> └─────┴─────┴─────┘
# select multiple columns by a regular expression
# starts with `^` and ends with `$`
df$select(pl$col(c("^ba.*$")))
#> shape: (3, 2)
#> ┌─────┬─────┐
#> │ bar ┆ baz │
#> │ --- ┆ --- │
#> │ i32 ┆ i32 │
#> ╞═════╪═════╡
#> │ 4 ┆ 7 │
#> │ 5 ┆ 8 │
#> │ 6 ┆ 9 │
#> └─────┴─────┘