SHARE
TWEET

Calculate monthly average from list

a guest Nov 12th, 2012 64 Never
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]..)
  3.  
  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
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top