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:

Transformer

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:

list[ColumnReference]

Required:

True

Choices:

All columns in the target DataFrame, except those selected in columns and values

columns

A list of column references where values in the columns are treated as columns in the pivot table (group values into columns).

Type:

list[ColumnReference]

Required:

True

Choices:

All columns in the target DataFrame, except those selected in indexes and values

values

A list of column references where values in the columns are summarized using aggregation_function.

Type:

list[ColumnReference]

Required:

True

Choices:

All columns in the target DataFrame, except those selected in indexes and columns

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:

AggregationFunction

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"
    }
}