Skip to content

Sum all elements in a list

Source code

Description

Sum all elements in a list

Usage

<Expr>$list$sum()

Value

Expr

Examples

library("polars")

df = pl$DataFrame(values = list(c(1, 2, 3, NA), c(2, 3), NA_real_))
df$with_columns(sum = pl$col("values")$list$sum())
#> shape: (3, 2)
#> ┌────────────────────┬─────┐
#> │ values             ┆ sum │
#> │ ---                ┆ --- │
#> │ list[f64]          ┆ f64 │
#> ╞════════════════════╪═════╡
#> │ [1.0, 2.0, … null] ┆ 6.0 │
#> │ [2.0, 3.0]         ┆ 5.0 │
#> │ [null]             ┆ 0.0 │
#> └────────────────────┴─────┘