polars.sum#

polars.sum(*names: str) Expr[source]#

Sum all values.

Syntactic sugar for col(name).sum().

Parameters:
*names

Name(s) of the columns to use in the aggregation.

See also

sum_horizontal

Examples

Sum a column.

>>> df = pl.DataFrame(
...     {
...         "a": [1, 2],
...         "b": [3, 4],
...         "c": [5, 6],
...     }
... )
>>> df.select(pl.sum("a"))
shape: (1, 1)
┌─────┐
│ a   │
│ --- │
│ i64 │
╞═════╡
│ 3   │
└─────┘

Sum multiple columns.

>>> df.select(pl.sum("a", "c"))
shape: (1, 2)
┌─────┬─────┐
│ a   ┆ c   │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪═════╡
│ 3   ┆ 11  │
└─────┴─────┘
>>> df.select(pl.sum("^.*[bc]$"))
shape: (1, 2)
┌─────┬─────┐
│ b   ┆ c   │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪═════╡
│ 7   ┆ 11  │
└─────┴─────┘