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] Is there a way to cumulatively and distinctively expand list in polars

Discussão em 'Python' iniciado por Stack, Setembro 15, 2024.

  1. Stack

    Stack Membro Participativo

    For distance, I want to accomplish conversion like below.

    df = pl.DataFrame({
    "col": [["a"], ["a", "b"], ["c"]]
    })


    ┌────────────┐
    │ col │
    │ --- │
    │ list[str] │
    ╞════════════╡
    │ ["a"] │
    │ ["a", "b"] │
    │ ["c"] │
    └────────────┘
    ↓
    ↓
    ↓
    ┌────────────┬─────────────────┐
    │ col ┆ col_cum │
    │ --- ┆ --- │
    │ list[str] ┆ list[str] │
    ╞════════════╪═════════════════╡
    │ ["a"] ┆ ["a"] │
    │ ["a", "b"] ┆ ["a", "b"] │
    │ ["c"] ┆ ["a", "b", "c"] │
    └────────────┴─────────────────┘


    I've tried polars.Expr.cumulative_eval(), but could not get it to work.

    I can access the first element and last element in every iteration. But I want here is the result of the previous iteration i think. Could I get some help?

    Continue reading...

Compartilhe esta Página