Select and modify columns of a DataFrame
Description
Similar to dplyr::mutate()
. However, it discards
unmentioned columns (like .()
in data.table
).
This will run all expression sequentially instead of in parallel. Use
this when the work per expression is cheap. Otherwise,
$select()
should be preferred.
Usage
<DataFrame>$select_seq(...)
Arguments
…
|
Columns to keep. Those can be expressions (e.g
pl$col(“a”) ), column names (e.g “a” ), or list
containing expressions or column names (e.g
list(pl$col(“a”)) ).
|
Value
DataFrame
Examples
library("polars")
as_polars_df(iris)$select_seq(
pl$col("Sepal.Length")$abs()$alias("abs_SL"),
(pl$col("Sepal.Length") + 2)$alias("add_2_SL")
)
#> shape: (150, 2)
#> ┌────────┬──────────┐
#> │ abs_SL ┆ add_2_SL │
#> │ --- ┆ --- │
#> │ f64 ┆ f64 │
#> ╞════════╪══════════╡
#> │ 5.1 ┆ 7.1 │
#> │ 4.9 ┆ 6.9 │
#> │ 4.7 ┆ 6.7 │
#> │ 4.6 ┆ 6.6 │
#> │ 5.0 ┆ 7.0 │
#> │ … ┆ … │
#> │ 6.7 ┆ 8.7 │
#> │ 6.3 ┆ 8.3 │
#> │ 6.5 ┆ 8.5 │
#> │ 6.2 ┆ 8.2 │
#> │ 5.9 ┆ 7.9 │
#> └────────┴──────────┘