Skip to content

Select and modify columns of a LazyFrame

Source code

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

<LazyFrame>$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

A LazyFrame

Examples

library("polars")

as_polars_lf(iris)$select_seq(
  pl$col("Sepal.Length")$abs()$alias("abs_SL"),
  (pl$col("Sepal.Length") + 2)$alias("add_2_SL")
)
#> polars LazyFrame
#>  $explain(): Show the optimized query plan.
#> 
#> Naive plan:
#>  SELECT [col("Sepal.Length").abs().alias("abs_SL"), [(col("Sepal.Length")) + (2.0)].alias("add_2_SL")] FROM
#>   DF ["Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width"]; PROJECT */5 COLUMNS; SELECTION: None