I am a Python 3 beginner and I am trying to practice some examples. I have dictionary data (year, month) formatted as follows:
year month yearmonth x1 x2 x3 ...
1999 1 199901 10 20 30 ...
1999 3 199903 10 20 30 ...
2000 4 200004 10 20 30 ...
2000 9 200009 10 20 30 ...
2000 10 200010 10 20 30 ...
.................................
.................................
I would like to get subtotals for each year for certain keys, e.g. subtotal for only variable x2
. The expected result is to return the following:
year totalx2
1999 40
2000 60
.........
Of course, in my data there are more years and months than presented here. If there is a missing month for a certain year, I will assume that the value is 0 when adding the 12 months subtotal.
Any help would be great! Thanks for your patient with a beginner. Joe