You can doit much easy by using Salstat2 https://code.google.com/p/salstat-statistics-package-2/wiki/PivotData
so import your data from the excel file,
and copy the following code into the script panel:
res= group()# calling the class to group the data
res.xdata= [ grid.GetCol('A')...