[Python] Cumulative count per group in PyArrow

Discussão em 'Python' iniciado por Stack, Junho 14, 2025.

  1. Stack

    Stack Membro Participativo

    Say I have

    data = {'a': [1,1,2], 'b': [4,5,6]}


    and I'd like to get a cumulative count (1-indexed) per group.

    In pandas, I can do:

    import pandas as pd

    pd.DataFrame(data).groupby('a').cumcount()+1


    How can I do this in PyArrow, starting from pa.table(data), without doing any conversion to pandas?

    I'm OK with using NumPy functions (e.g. np.arange) to generate the new column, but I can't convert the starting pyarrow.Table to numpy (nor to pandas)

    Continue reading...

Compartilhe esta Página