Pivot Table
A Callable for returning a pivot table generated from input data.
Definition
- class controller.callable.transformer.PivotTable(self, indexes: list[ColumnReference], columns: list[ColumnReference], values: list[ColumnReference], aggregation_function: str)
- Callable name:
pivot_table- Callable type:
- Parameters:
indexes (list[ColumnReference]) – A list of column references where values in the columns are treated as indexes in the pivot table (group values into rows).
columns (list[ColumnReference]) – A list of column references where values in the columns are treated as columns in the pivot table (group values into columns).
values (list[ColumnReference]) – A list of column references where values in the columns are summarized using
aggregation_function.aggregation_function (AggregationFunction) – The function used to summarize the values in the pivot table.
Parameters
- indexes
A list of column references where values in the columns are treated as indexes in the pivot table (group values into rows).
- Type:
- Required:
True
- Choices:
All columns in the target DataFrame, except those selected in
columnsandvalues
- columns
A list of column references where values in the columns are treated as columns in the pivot table (group values into columns).
- Type:
- Required:
True
- Choices:
All columns in the target DataFrame, except those selected in
indexesandvalues
- values
A list of column references where values in the columns are summarized using
aggregation_function.- Type:
- Required:
True
- Choices:
All columns in the target DataFrame, except those selected in
indexesandcolumns
Note
The list of columns referenced in indexes, columns, and values must be mutually exclusive.
- aggregation_function
The function used to summarize the values in the pivot table.
- Type:
- Required:
True
- Choices:
All available names of aggregation functions
Output
A DataFrame is returned containing the resulting pivot table.
A pivot table may contain indexes or columns of multiple levels. The output of PivotTable flattens multi-level indexes and columns. As an example:
// TODO
Note
The original input data is not preserved.
Example configuration
{
"name": "foo",
"callable": "pivot_table",
"params": {
"indexes": ["$final_exam_submissions.student.program", "$final_exam_submissions.student.student_number"],
"columns": ["$final_exam_submissions.question_response.question_id"],
"values": ["$final_exam_submissions.question_response.score"],
"aggregation_function": "mean"
}
}