1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Cum Max Sum in Polars

Discussão em 'Python' iniciado por Stack, Setembro 16, 2025.

  1. Stack

    Stack Membro Participativo

    In the following dataframe, I want to populate the column cum_max_sum using the columns minimum and to_add. How can I achieve this using Polars operations?

    ┌──────────────────┬─────────┬────────┬─────────────┐
    │ prev_cum_max_sum ┆ minimum ┆ to_add ┆ cum_max_sum │
    │ --- ┆ --- ┆ --- ┆ --- │
    │ i64 ┆ i64 ┆ i64 ┆ i64 │
    ╞══════════════════╪═════════╪════════╪═════════════╡
    │ null ┆ 1 ┆ 5 ┆ 6 │
    │ 6 ┆ 4 ┆ 6 ┆ 12 │
    │ 12 ┆ 13 ┆ 7 ┆ 20 │
    └──────────────────┴─────────┴────────┴─────────────┘


    Explanation:

    max(null, 1) + 5 = 6

    max(6, 4) + 6 = 12

    max(12, 13) + 7 = 20

    Continue reading...

Compartilhe esta Página