Grouping
Pivot grouping
Pivot can be grouped with groupBy method. It will produce a PivotGroupBy.
PivotGroupBy is a dataframe-like structure that combines Pivot and GroupBy, representing a matrix table with vertical Pivot groups (as columns) and horizontal GroupBy groups (as rows), where each cell represents a group corresponding to both the GroupBy and Pivot key.
Reversed order of pivot and groupBy (i.e., DataFrame.pivot + Pivot.groupBy or DataFrame.groupBy + GroupBy.pivot) will produce the same result.
PivotGroupBy can be reduced or aggregated into a DataFrame.
Check out PivotGroupBy Grammar.
For more information: See "pivot + groupBy" on the documentation website.