polars.Expr.sum
-
Get sum value.
Notes
- Dtypes in {Int8, UInt8, Int16, UInt16} are cast to Int64 before summing to prevent overflow issues.
- If there are no non-null values, then the output is
0. If you would prefer empty sums to returnNone, you can usepl.when(expr.count()>0).then(expr.sum())instead ofexpr.sum().
Examples
>>> df = pl.DataFrame({"a": [-1, 0, 1]}) >>> df.select(pl.col("a").sum()) shape: (1, 1) ┌─────┐ │ a │ │ --- │ │ i64 │ ╞═════╡ │ 0 │ └─────┘
Expr.sum() → Expr
© 2020 Ritchie Vink
© 2022 Polars contributors
Licensed under the MIT License.
https://docs.pola.rs/api/python/stable/reference/expressions/api/polars.Expr.sum.html