My problem is that the first item of over 2000 sublists is a date which is in a year-month format and the rest are values for days, and I need to get the monthly average. I tried few things but couldn't get it to work. I would be grateful for some suggestions.

what I've tried is something like:

def avPrice(mylist):
month=[]
i = 0
for i in mylist:
if mylist[i][0] not in month:
month = mylist[i][0],mylist[i][1]*mylist[i][2],mylist[i][2]
else:
month = month[0],month[1]+(mylist[i][1]*mylist[line][2]),month[2]+mylist[i][2]
i = i + 1
return month
monthAvPrice.append(month)

Edit: The above only gets the numerator of the desired value. The code shown below computes both the numerator and the denominator. As demo code, it produces a list containing both the values and their ratio.

Note the apparently-extra for in the following code. (That is, the portion... for w,v in [[w, list(v)] for w,v in itertools ...
in the third line of code.) The extra layer of for is used to make a copy of iterable v as a list. That is, because the v returned by itertools.groupby() is an iterable rather than an actual list, numer_sum(v) would exhaust v, so denom_sum(v) would get a value of 0. Another approach would be to use itertools.tee; but an answer to another question says the list approach may be faster. A third possibility is to combine numer_sum and denom_sum into a single function that returns a tuple, and add an outer for to compute the ratio.

That should work assuming you have two sublists for every month. If you have more, then you might have to add a function to check for all the sublists whose 'zeroth' index is equal to a certain string. For example:

newList=[]
tempList=[]
for i in list:
if i[0]=='year1-month1':
tempList.append(i)
while len(tempList)>1:
tempList=monthly_average(tempList)