Dataframe BenchMEASURED IN ONE ENVIRONMENT

    ↑↓ to select, Enter to open, Esc to close

    pandas groupby + agg(dict) is ~5.32× slower than polars group_by + agg for three aggregates per group

    Same three aggregates on the same groups.

    Result

    Runpandas groupby + agg(dict)polars group_by + aggRatio
    Run 1182.1238.04.79×
    Run 2214.0436.895.80×
    Run 3187.8735.35.32×

    Spread over 3 runs: pandas groupby + agg(dict) CV 8.7% / polars group_by + agg CV 3.7% / ratio CV 9.5%

    The two calls

    df.groupby('g').agg(v_sum=('v','sum'), v_mean=('v','mean'), k_max=('k','max'))
    df.group_by('g').agg(pl.col('v').sum(), pl.col('v').mean(), pl.col('k').max())

    Conditions

    1,000 groups, 400,000 rows.

    Where this number does not apply

    Absolute times here are small, so the ratio moves more between runs than the large operations do.

    Reproduce

    cd bench && python run.py --run 1 --out ../data/run1.json