Skip to content

Select and modify columns of a DataFrame

Source code

Description

Similar to dplyr::mutate(). However, it discards unmentioned columns (like .() in data.table).

Usage

<DataFrame>$select(...)

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(
  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      │
#> └────────┴──────────┘