I always try to simplify and optimize things when I write my scripts. When I firstly started to write some scripts which iterated over a dates, I didnt realize the importance of splitted datetime objects by its parts and I wrote these scripts complicated with different inner conditions and so on. This one is very basic and simple one - it takes apart the "datetime" and stores the value accordingly by the month in a 2D temporary array, where in the one dimension there are 12 months and in the another dimension - appended values. Then in another loop the values are averaged within each month and result is given as 2D array as a month-averaged value pair.
The function can be seen here - http://pastebin.com/YZEtkKh6