polars.cum_sum_horizontal#
- polars.cum_sum_horizontal(*exprs: IntoExpr | Iterable[IntoExpr]) Expr [source]#
Cumulatively sum all values horizontally across columns.
- Parameters:
- *exprs
Column(s) to use in the aggregation. Accepts expression input. Strings are parsed as column names, other non-expression inputs are parsed as literals.
Examples
>>> df = pl.DataFrame( ... { ... "a": [1, 8, 3], ... "b": [4, 5, None], ... "c": ["x", "y", "z"], ... } ... ) >>> df.with_columns(pl.cum_sum_horizontal("a", "b")) shape: (3, 4) ┌─────┬──────┬─────┬───────────┐ │ a ┆ b ┆ c ┆ cum_sum │ │ --- ┆ --- ┆ --- ┆ --- │ │ i64 ┆ i64 ┆ str ┆ struct[2] │ ╞═════╪══════╪═════╪═══════════╡ │ 1 ┆ 4 ┆ x ┆ {1,5} │ │ 8 ┆ 5 ┆ y ┆ {8,13} │ │ 3 ┆ null ┆ z ┆ {3,null} │ └─────┴──────┴─────┴───────────┘