Guest User

Calculate monthly average from list

a guest
Nov 12th, 2012
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  #This function creates a monthly average from list with
  2.  #such structure (["%Y-%m-%d %H:%M:%S", float],["%Y-%m-%d %H:%M:%S", float]..)
  4. def monthlyAverage(array):
  5.     tmpMonthArray=[[]*12 for x in xrange(12)]
  6.     resultArray=[]
  7.     for eachPair in array:
  8.         #print eachPair[0]
  9.         dateObjekts=datetime.datetime.strptime(eachPair[0],"%Y-%m-%d %H:%M:%S")
  10.         menesis=dateObjekts.month
  11.         tmpMonthArray[menesis-1].append(eachPair[1])
  12.     i=1
  13.     for each in tmpMonthArray:
  14.         resultArray.append([i,sum(each)/len(each)])
  15.         i+=1    
  16.     print resultArray
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add to your ad blocker whitelist or disable your adblocking software.