How to group by quarter and calculate average from an array using numpy?
Question: I'd like to utilize numpy to calculate the average of a set of values in each
quarter from the below array:

    
    
    Data = [{'date':'2015-01-01',value:5},{'date':'2015-02-01',value:6},{'date':'2015-03-01',value:7},{'date':'2015-04-01',value:8},{'date':'2015-05-01',value:9},{'date':'2015-06-01',value:10},{'date':'2015-07-01',value:11},{'date':'2015-08-01',value:12}]
    

I'd like the result to tell me the following:

  * For Q1-15, the average was 6
  * For Q2-15, the average was 9
  * For Q3-15, the average was 11.5

Based on [this stackoverflow
question](http://stackoverflow.com/questions/23859840/python-aggregate-by-
month-and-calculate-average), I've tried the below:

    
    
    np = Data #I'm not sure how to read in data into numpy from an array in my structure
    np.resample('Q',how='mean') #I'm not sure if using 'Q' would group this by quarter
    


Answer: I think pandas works better in this case. I will just use your simple example
for illustration.

    
    
    import pandas as pd # use recent version which has dt.quarter attr for time
    import json
    value = 'value' # to be able to read your Data string as json 
    Data1 = json.dumps(Data) # need it to use read_json() method.
    a = pd.read_json(Data1)
    a[a['date'].dt.quarter == 1].mean() # 1st quarter
    a[a['date'].dt.quarter == 2].mean() # 2nd quarter
    a[a['date'].dt.quarter == 3].mean() # 3rd quarter
    

