Pivot Table
pivot_tableSummarize tabular data by creating pivot tables: choose row and column indices, select a value column, and apply aggregation (sum, mean, count, min, max) to reveal patterns and relationships.
Instructions
Create pivot tables from tabular data using Polars.
Like Excel pivot tables: reshape data with row/column dimensions and aggregated values.
Example:
SALES BY REGION AND PRODUCT: data=[ {"region":"North","product":"A","sales":100}, {"region":"North","product":"B","sales":150}, {"region":"South","product":"A","sales":80}, {"region":"South","product":"B","sales":120} ], index="region", columns="product", values="sales", aggfunc="sum" Result: product | A | B --------|------|------ North | 100 | 150 South | 80 | 120
COUNT AGGREGATION: Same data with aggfunc="count" Result: Count of entries per region-product combination
AVERAGE SCORES: data=[{"dept":"Sales","role":"Manager","score":85}, ...] index="dept", columns="role", values="score", aggfunc="mean" Result: Average scores by department and role
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| context | No | Optional annotation to label this calculation (e.g., 'Bond A PV', 'Q2 revenue'). Appears in results for easy identification. | |
| output_mode | No | Output format: full (default), compact, minimal, value, or final. See batch_execute tool for details. | full |
| data | Yes | List of row dictionaries | |
| index | Yes | Column name for row index | |
| columns | Yes | Column name for pivot columns | |
| values | Yes | Column name to aggregate | |
| aggfunc | No | Aggregation function | sum |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |