1
我想利用numpy的从下方阵列计算每个季度的一组值的平均值:如何按季度分组并使用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
检查大熊猫。你链接到的问题使用熊猫。 – dbliss