[Python] Accumulating lists in Polars

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

  1. Stack

    Stack Membro Participativo

    Say I have a pl.DataFrame() with 2 columns: The first column contains Date, the second List[str].

    import polars as pl

    df = pl.DataFrame([
    pl.Series('Date', [2000, 2001, 2002]),
    pl.Series('Ids', [
    ['a'],
    ['b', 'c'],
    ['d'],
    ])
    ])

    Date Ids
    2000 ['a']
    2001 ['b', 'c']
    2002 ['d']

    Is it possible to accumulate the List[str] column so that each row contains itself and all previous lists in Polars? Like so:

    Date Ids
    2000 ['a']
    2001 ['a', 'b', 'c']
    2002 ['a', 'b', 'c', 'd']

    Continue reading...

Compartilhe esta Página