Dataframe BenchMEASURED IN ONE ENVIRONMENT

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

    pandas pivot_table is ~1.08× slower than polars pivot for pivoting to a wide table

    This is the case where the two libraries are closest.

    Result

    Runpandas pivot_tablepolars pivotRatio
    Run 1223.22205.671.08×
    Run 2214.34201.411.06×
    Run 3235.28213.211.10×

    Spread over 3 runs: pandas pivot_table CV 4.7% / polars pivot CV 2.9% / ratio CV 1.8%

    The two calls

    df.pivot_table(index='g', columns='k', values='v', aggfunc='sum')
    df.pivot(on='k', index='g', values='v', aggregate_function='sum')

    Conditions

    1,000 group keys by 1,000 column keys, summed.

    Where this number does not apply

    A dense output is required on both sides; sparse pivots are a different path.

    Reproduce

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