Spec-Zone.ru › Polars

polars.Expr.sum

Expr.sum() → Expr

Get sum value.

engine:In MemoryStreamingDistributed

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 return None, you can use pl.when(expr.count()>0).then(expr.sum()) instead of expr.sum().

Examples

>>> df = pl.DataFrame({"a": [-1, 0, 1]})
>>> df.select(pl.col("a").sum())
shape: (1, 1)
┌─────┐
│ a   │
│ --- │
│ i64 │
╞═════╡
│  0  │
└─────┘

© 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

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API