Using pandas we can do the following:

A summary of transformations steps can be helpful:

StepOperationResult
1set_indexRows get hierarchical keys
2stackWide → long with 3-level row index
3reset + extractParse variable names into fields
4pivotTidy format with metric columns
5unstackWide format with MultiIndex columns

In DE_Tools see:

Related terms:

Split-Apply-Combine