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
| Run | pandas pivot_table | polars pivot | Ratio |
|---|---|---|---|
| Run 1 | 223.22 | 205.67 | 1.08× |
| Run 2 | 214.34 | 201.41 | 1.06× |
| Run 3 | 235.28 | 213.21 | 1.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