create_pivot_table
Build a pivot table from specified columns in a source sheet, aggregate values with sum, mean, or custom functions, and optionally write the result to a new sheet or file.
Instructions
Build a pivot table from a source sheet and optionally write it to output_sheet/output_file.
Args: file_path: Workbook path. sheet_name: Source data sheet. index_cols: List of column names to use as index (rows). value_cols: Columns to aggregate. aggfunc: Aggregation function or dict (e.g. "sum", "mean" or {col: "sum"}). output_sheet: Optional destination sheet for pivot output. output_file: Optional file to write the pivot output. column_field: Optional field used for pivot columns. date_freq: Optional date grouping alias (e.g. 'ME', 'YE', 'W').
Returns: dict: Details about output including created sheet and saved pivot metadata.
Notes:
- Writes to workbook when output_sheet/output_file is provided. Stores pivot definitions in _mcp_pivots for refresh.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| aggfunc | No | sum | |
| date_freq | No | ||
| file_path | Yes | ||
| index_cols | Yes | ||
| sheet_name | Yes | ||
| value_cols | Yes | ||
| output_file | No | ||
| column_field | No | ||
| output_sheet | No |