Skip to content

Sum all elements in an array

Source code

Description

Sum all elements in an array

Usage

<Expr>$arr$sum()

Value

Expr

Examples

library("polars")

df = pl$DataFrame(
  values = list(c(1, 2), c(3, 4), c(NA_real_, 6)),
  schema = list(values = pl$Array(pl$Float64, 2))
)
df$with_columns(sum = pl$col("values")$arr$sum())
#> shape: (3, 2)
#> ┌───────────────┬─────┐
#> │ values        ┆ sum │
#> │ ---           ┆ --- │
#> │ array[f64, 2] ┆ f64 │
#> ╞═══════════════╪═════╡
#> │ [1.0, 2.0]    ┆ 3.0 │
#> │ [3.0, 4.0]    ┆ 7.0 │
#> │ [null, 6.0]   ┆ 6.0 │
#> └───────────────┴─────┘