[Python] Take cumsum of each row in polars

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

  1. Stack

    Stack Membro Participativo

    E.g. if I have

    import polars as pl
    df = pl.DataFrame({'a': [1,2,3], 'b': [4,5,6]})


    how would I find the cumulative sum of each row?

    Expected output:

    a b
    0 1 5
    1 2 7
    2 3 9


    Here's the equivalent in pandas:

    >>> import pandas as pd
    >>> pd.DataFrame({'a': [1,2,3], 'b': [4,5,6]}).cumsum(axis=1)
    a b
    0 1 5
    1 2 7
    2 3 9


    but I can't figure out how to do it in polars

    Continue reading...

Compartilhe esta Página