The function should take a pandas data frame as an input.
The function calculates Totals and Subtotals of a pivot table. The function is flexible on the number of variables that are used as index and columns.
Totals and subtotals must be displayed at the top (for index) and on the left (for columns). Extra points if you can specify it in the function whether they are display left/right top/bottom.
It must be possible to specify whether Index Totals should be included. It must be possible to specify whether Index Subtotals should be included. It must be possible to specify whether Column Totals should be included. It must be possible to specify whether Column Subtotals should be included.
It must be possible to label both totals and all subtotals.
Attached is sample code for two index and two columns as well an Excel with the current output (sheet have) as well as the maximum output (sheet want) when both totals (Index and Column) as well as both subtotals (Column1 and Index1) are activated.