【发布时间】:2016-07-22 12:18:33
【问题描述】:
我想利用 numpy 从下面的数组中计算每个季度的一组值的平均值:
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}]
我希望结果告诉我以下内容:
- 对于 Q1-15,平均值为 6
- 对于 Q2-15,平均值为 9
- 对于 Q3-15,平均值为 11.5
基于this stackoverflow question,我尝试了以下方法:
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
【问题讨论】:
-
查看熊猫。您链接到的问题使用熊猫。