Home > OS >  How to compute average value for each year and month combinations using numpy?
How to compute average value for each year and month combinations using numpy?

Time:09-15

I have 2 numpy arrays, namely, times and values. (see below for reproducible data).

  1. times contains dates (yyyy-mm-dd)
  2. values contains values for each corresponding date

Now, I want to compute average value for each month and year combinations. For example, if there are 5 years of daily data I want to have a 5*12=60 values (e.g. something like 'group by year and month').

What is the best way to achieve this using numpy?

Reproducible data:

  1. times
# import the numpy library
import numpy as np

times = np.array(['2004-01-01T00:00:00.000000000', '2004-01-02T00:00:00.000000000',
       '2004-01-03T00:00:00.000000000', '2004-01-04T00:00:00.000000000',
       '2004-01-05T00:00:00.000000000', '2004-01-06T00:00:00.000000000',
       '2004-01-07T00:00:00.000000000', '2004-01-08T00:00:00.000000000',
       '2004-01-09T00:00:00.000000000', '2004-01-10T00:00:00.000000000',
       '2004-01-11T00:00:00.000000000', '2004-01-12T00:00:00.000000000',
       '2004-01-13T00:00:00.000000000', '2004-01-14T00:00:00.000000000',
       '2004-01-15T00:00:00.000000000', '2004-01-16T00:00:00.000000000',
       '2004-01-17T00:00:00.000000000', '2004-01-18T00:00:00.000000000',
       '2004-01-19T00:00:00.000000000', '2004-01-20T00:00:00.000000000',
       '2004-01-21T00:00:00.000000000', '2004-01-22T00:00:00.000000000',
       '2004-01-23T00:00:00.000000000', '2004-01-24T00:00:00.000000000',
       '2004-01-25T00:00:00.000000000', '2004-01-26T00:00:00.000000000',
       '2004-01-27T00:00:00.000000000', '2004-01-28T00:00:00.000000000',
       '2004-01-29T00:00:00.000000000', '2004-01-30T00:00:00.000000000',
       '2004-01-31T00:00:00.000000000', '2004-02-01T00:00:00.000000000',
       '2004-02-02T00:00:00.000000000', '2004-02-03T00:00:00.000000000',
       '2004-02-04T00:00:00.000000000', '2004-02-05T00:00:00.000000000',
       '2004-02-06T00:00:00.000000000', '2004-02-07T00:00:00.000000000',
       '2004-02-08T00:00:00.000000000', '2004-02-09T00:00:00.000000000',
       '2004-02-10T00:00:00.000000000', '2004-02-11T00:00:00.000000000',
       '2004-02-12T00:00:00.000000000', '2004-02-13T00:00:00.000000000',
       '2004-02-14T00:00:00.000000000', '2004-02-15T00:00:00.000000000',
       '2004-02-16T00:00:00.000000000', '2004-02-17T00:00:00.000000000',
       '2004-02-18T00:00:00.000000000', '2004-02-19T00:00:00.000000000',
       '2004-02-20T00:00:00.000000000', '2004-02-21T00:00:00.000000000',
       '2004-02-22T00:00:00.000000000', '2004-02-23T00:00:00.000000000',
       '2004-02-24T00:00:00.000000000', '2004-02-25T00:00:00.000000000',
       '2004-02-26T00:00:00.000000000', '2004-02-27T00:00:00.000000000',
       '2004-02-28T00:00:00.000000000', '2004-02-29T00:00:00.000000000',
       '2004-03-01T00:00:00.000000000', '2004-03-02T00:00:00.000000000',
       '2004-03-03T00:00:00.000000000', '2004-03-04T00:00:00.000000000',
       '2004-03-05T00:00:00.000000000', '2004-03-06T00:00:00.000000000',
       '2004-03-07T00:00:00.000000000', '2004-03-08T00:00:00.000000000',
       '2004-03-09T00:00:00.000000000', '2004-03-10T00:00:00.000000000',
       '2004-03-11T00:00:00.000000000', '2004-03-12T00:00:00.000000000',
       '2004-03-13T00:00:00.000000000', '2004-03-14T00:00:00.000000000',
       '2004-03-15T00:00:00.000000000', '2004-03-16T00:00:00.000000000',
       '2004-03-17T00:00:00.000000000', '2004-03-18T00:00:00.000000000',
       '2004-03-19T00:00:00.000000000', '2004-03-20T00:00:00.000000000',
       '2004-03-21T00:00:00.000000000', '2004-03-22T00:00:00.000000000',
       '2004-03-23T00:00:00.000000000', '2004-03-24T00:00:00.000000000',
       '2004-03-25T00:00:00.000000000', '2004-03-26T00:00:00.000000000',
       '2004-03-27T00:00:00.000000000', '2004-03-28T00:00:00.000000000',
       '2004-03-29T00:00:00.000000000', '2004-03-30T00:00:00.000000000',
       '2004-03-31T00:00:00.000000000', '2004-04-01T00:00:00.000000000',
       '2004-04-02T00:00:00.000000000', '2004-04-03T00:00:00.000000000',
       '2004-04-04T00:00:00.000000000', '2004-04-05T00:00:00.000000000',
       '2004-04-06T00:00:00.000000000', '2004-04-07T00:00:00.000000000',
       '2004-04-08T00:00:00.000000000', '2004-04-09T00:00:00.000000000',
       '2004-04-10T00:00:00.000000000', '2004-04-11T00:00:00.000000000',
       '2004-04-12T00:00:00.000000000', '2004-04-13T00:00:00.000000000',
       '2004-04-14T00:00:00.000000000', '2004-04-15T00:00:00.000000000',
       '2004-04-16T00:00:00.000000000', '2004-04-17T00:00:00.000000000',
       '2004-04-18T00:00:00.000000000', '2004-04-19T00:00:00.000000000',
       '2004-04-20T00:00:00.000000000', '2004-04-21T00:00:00.000000000',
       '2004-04-22T00:00:00.000000000', '2004-04-23T00:00:00.000000000',
       '2004-04-24T00:00:00.000000000', '2004-04-25T00:00:00.000000000',
       '2004-04-26T00:00:00.000000000', '2004-04-27T00:00:00.000000000',
       '2004-04-28T00:00:00.000000000', '2004-04-29T00:00:00.000000000',
       '2004-04-30T00:00:00.000000000', '2004-05-01T00:00:00.000000000',
       '2004-05-02T00:00:00.000000000', '2004-05-03T00:00:00.000000000',
       '2004-05-04T00:00:00.000000000', '2004-05-05T00:00:00.000000000',
       '2004-05-06T00:00:00.000000000', '2004-05-07T00:00:00.000000000',
       '2004-05-08T00:00:00.000000000', '2004-05-09T00:00:00.000000000',
       '2004-05-10T00:00:00.000000000', '2004-05-11T00:00:00.000000000',
       '2004-05-12T00:00:00.000000000', '2004-05-13T00:00:00.000000000',
       '2004-05-14T00:00:00.000000000', '2004-05-15T00:00:00.000000000',
       '2004-05-16T00:00:00.000000000', '2004-05-17T00:00:00.000000000',
       '2004-05-18T00:00:00.000000000', '2004-05-19T00:00:00.000000000',
       '2004-05-20T00:00:00.000000000', '2004-05-21T00:00:00.000000000',
       '2004-05-22T00:00:00.000000000', '2004-05-23T00:00:00.000000000',
       '2004-05-24T00:00:00.000000000', '2004-05-25T00:00:00.000000000',
       '2004-05-26T00:00:00.000000000', '2004-05-27T00:00:00.000000000',
       '2004-05-28T00:00:00.000000000', '2004-05-29T00:00:00.000000000',
       '2004-05-30T00:00:00.000000000', '2004-05-31T00:00:00.000000000',
       '2004-06-01T00:00:00.000000000', '2004-06-02T00:00:00.000000000',
       '2004-06-03T00:00:00.000000000', '2004-06-04T00:00:00.000000000',
       '2004-06-05T00:00:00.000000000', '2004-06-06T00:00:00.000000000',
       '2004-06-07T00:00:00.000000000', '2004-06-08T00:00:00.000000000',
       '2004-06-09T00:00:00.000000000', '2004-06-10T00:00:00.000000000',
       '2004-06-11T00:00:00.000000000', '2004-06-12T00:00:00.000000000',
       '2004-06-13T00:00:00.000000000', '2004-06-14T00:00:00.000000000',
       '2004-06-15T00:00:00.000000000', '2004-06-16T00:00:00.000000000',
       '2004-06-17T00:00:00.000000000', '2004-06-18T00:00:00.000000000',
       '2004-06-19T00:00:00.000000000', '2004-06-20T00:00:00.000000000',
       '2004-06-21T00:00:00.000000000', '2004-06-22T00:00:00.000000000',
       '2004-06-23T00:00:00.000000000', '2004-06-24T00:00:00.000000000',
       '2004-06-25T00:00:00.000000000', '2004-06-26T00:00:00.000000000',
       '2004-06-27T00:00:00.000000000', '2004-06-28T00:00:00.000000000',
       '2004-06-29T00:00:00.000000000', '2004-06-30T00:00:00.000000000',
       '2004-07-01T00:00:00.000000000', '2004-07-02T00:00:00.000000000',
       '2004-07-03T00:00:00.000000000', '2004-07-04T00:00:00.000000000',
       '2004-07-05T00:00:00.000000000', '2004-07-06T00:00:00.000000000',
       '2004-07-07T00:00:00.000000000', '2004-07-08T00:00:00.000000000',
       '2004-07-09T00:00:00.000000000', '2004-07-10T00:00:00.000000000',
       '2004-07-11T00:00:00.000000000', '2004-07-12T00:00:00.000000000',
       '2004-07-13T00:00:00.000000000', '2004-07-14T00:00:00.000000000',
       '2004-07-15T00:00:00.000000000', '2004-07-16T00:00:00.000000000',
       '2004-07-17T00:00:00.000000000', '2004-07-18T00:00:00.000000000',
       '2004-07-19T00:00:00.000000000', '2004-07-20T00:00:00.000000000',
       '2004-07-21T00:00:00.000000000', '2004-07-22T00:00:00.000000000',
       '2004-07-23T00:00:00.000000000', '2004-07-24T00:00:00.000000000',
       '2004-07-25T00:00:00.000000000', '2004-07-26T00:00:00.000000000',
       '2004-07-27T00:00:00.000000000', '2004-07-28T00:00:00.000000000',
       '2004-07-29T00:00:00.000000000', '2004-07-30T00:00:00.000000000',
       '2004-07-31T00:00:00.000000000', '2004-08-01T00:00:00.000000000',
       '2004-08-02T00:00:00.000000000', '2004-08-03T00:00:00.000000000',
       '2004-08-04T00:00:00.000000000', '2004-08-05T00:00:00.000000000',
       '2004-08-06T00:00:00.000000000', '2004-08-07T00:00:00.000000000',
       '2004-08-08T00:00:00.000000000', '2004-08-09T00:00:00.000000000',
       '2004-08-10T00:00:00.000000000', '2004-08-11T00:00:00.000000000',
       '2004-08-12T00:00:00.000000000', '2004-08-13T00:00:00.000000000',
       '2004-08-14T00:00:00.000000000', '2004-08-15T00:00:00.000000000',
       '2004-08-16T00:00:00.000000000', '2004-08-17T00:00:00.000000000',
       '2004-08-18T00:00:00.000000000', '2004-08-19T00:00:00.000000000',
       '2004-08-20T00:00:00.000000000', '2004-08-21T00:00:00.000000000',
       '2004-08-22T00:00:00.000000000', '2004-08-23T00:00:00.000000000',
       '2004-08-24T00:00:00.000000000', '2004-08-25T00:00:00.000000000',
       '2004-08-26T00:00:00.000000000', '2004-08-27T00:00:00.000000000',
       '2004-08-28T00:00:00.000000000', '2004-08-29T00:00:00.000000000',
       '2004-08-30T00:00:00.000000000', '2004-08-31T00:00:00.000000000',
       '2004-09-01T00:00:00.000000000', '2004-09-02T00:00:00.000000000',
       '2004-09-03T00:00:00.000000000', '2004-09-04T00:00:00.000000000',
       '2004-09-05T00:00:00.000000000', '2004-09-06T00:00:00.000000000',
       '2004-09-07T00:00:00.000000000', '2004-09-08T00:00:00.000000000',
       '2004-09-09T00:00:00.000000000', '2004-09-10T00:00:00.000000000',
       '2004-09-11T00:00:00.000000000', '2004-09-12T00:00:00.000000000',
       '2004-09-13T00:00:00.000000000', '2004-09-14T00:00:00.000000000',
       '2004-09-15T00:00:00.000000000', '2004-09-16T00:00:00.000000000',
       '2004-09-17T00:00:00.000000000', '2004-09-18T00:00:00.000000000',
       '2004-09-19T00:00:00.000000000', '2004-09-20T00:00:00.000000000',
       '2004-09-21T00:00:00.000000000', '2004-09-22T00:00:00.000000000',
       '2004-09-23T00:00:00.000000000', '2004-09-24T00:00:00.000000000',
       '2004-09-25T00:00:00.000000000', '2004-09-26T00:00:00.000000000',
       '2004-09-27T00:00:00.000000000', '2004-09-28T00:00:00.000000000',
       '2004-09-29T00:00:00.000000000', '2004-09-30T00:00:00.000000000',
       '2004-10-01T00:00:00.000000000', '2004-10-02T00:00:00.000000000',
       '2004-10-03T00:00:00.000000000', '2004-10-04T00:00:00.000000000',
       '2004-10-05T00:00:00.000000000', '2004-10-06T00:00:00.000000000',
       '2004-10-07T00:00:00.000000000', '2004-10-08T00:00:00.000000000',
       '2004-10-09T00:00:00.000000000', '2004-10-10T00:00:00.000000000',
       '2004-10-11T00:00:00.000000000', '2004-10-12T00:00:00.000000000',
       '2004-10-13T00:00:00.000000000', '2004-10-14T00:00:00.000000000',
       '2004-10-15T00:00:00.000000000', '2004-10-16T00:00:00.000000000',
       '2004-10-17T00:00:00.000000000', '2004-10-18T00:00:00.000000000',
       '2004-10-19T00:00:00.000000000', '2004-10-20T00:00:00.000000000',
       '2004-10-21T00:00:00.000000000', '2004-10-22T00:00:00.000000000',
       '2004-10-23T00:00:00.000000000', '2004-10-24T00:00:00.000000000',
       '2004-10-25T00:00:00.000000000', '2004-10-26T00:00:00.000000000',
       '2004-10-27T00:00:00.000000000', '2004-10-28T00:00:00.000000000',
       '2004-10-29T00:00:00.000000000', '2004-10-30T00:00:00.000000000',
       '2004-10-31T00:00:00.000000000', '2004-11-01T00:00:00.000000000',
       '2004-11-02T00:00:00.000000000', '2004-11-03T00:00:00.000000000',
       '2004-11-04T00:00:00.000000000', '2004-11-05T00:00:00.000000000',
       '2004-11-06T00:00:00.000000000', '2004-11-07T00:00:00.000000000',
       '2004-11-08T00:00:00.000000000', '2004-11-09T00:00:00.000000000',
       '2004-11-10T00:00:00.000000000', '2004-11-11T00:00:00.000000000',
       '2004-11-12T00:00:00.000000000', '2004-11-13T00:00:00.000000000',
       '2004-11-14T00:00:00.000000000', '2004-11-15T00:00:00.000000000',
       '2004-11-16T00:00:00.000000000', '2004-11-17T00:00:00.000000000',
       '2004-11-18T00:00:00.000000000', '2004-11-19T00:00:00.000000000',
       '2004-11-20T00:00:00.000000000', '2004-11-21T00:00:00.000000000',
       '2004-11-22T00:00:00.000000000', '2004-11-23T00:00:00.000000000',
       '2004-11-24T00:00:00.000000000', '2004-11-25T00:00:00.000000000',
       '2004-11-26T00:00:00.000000000', '2004-11-27T00:00:00.000000000',
       '2004-11-28T00:00:00.000000000', '2004-11-29T00:00:00.000000000',
       '2004-11-30T00:00:00.000000000', '2004-12-01T00:00:00.000000000',
       '2004-12-02T00:00:00.000000000', '2004-12-03T00:00:00.000000000',
       '2004-12-04T00:00:00.000000000', '2004-12-05T00:00:00.000000000',
       '2004-12-06T00:00:00.000000000', '2004-12-07T00:00:00.000000000',
       '2004-12-08T00:00:00.000000000', '2004-12-09T00:00:00.000000000',
       '2004-12-10T00:00:00.000000000', '2004-12-11T00:00:00.000000000',
       '2004-12-12T00:00:00.000000000', '2004-12-13T00:00:00.000000000',
       '2004-12-14T00:00:00.000000000', '2004-12-15T00:00:00.000000000',
       '2004-12-16T00:00:00.000000000', '2004-12-17T00:00:00.000000000',
       '2004-12-18T00:00:00.000000000', '2004-12-19T00:00:00.000000000',
       '2004-12-20T00:00:00.000000000', '2004-12-21T00:00:00.000000000',
       '2004-12-22T00:00:00.000000000', '2004-12-23T00:00:00.000000000',
       '2004-12-24T00:00:00.000000000', '2004-12-25T00:00:00.000000000',
       '2004-12-26T00:00:00.000000000', '2004-12-27T00:00:00.000000000',
       '2004-12-28T00:00:00.000000000', '2004-12-29T00:00:00.000000000',
       '2004-12-30T00:00:00.000000000', '2004-12-31T00:00:00.000000000',
       '2005-01-01T00:00:00.000000000', '2005-01-02T00:00:00.000000000',
       '2005-01-03T00:00:00.000000000', '2005-01-04T00:00:00.000000000',
       '2005-01-05T00:00:00.000000000', '2005-01-06T00:00:00.000000000',
       '2005-01-07T00:00:00.000000000', '2005-01-08T00:00:00.000000000',
       '2005-01-09T00:00:00.000000000', '2005-01-10T00:00:00.000000000',
       '2005-01-11T00:00:00.000000000', '2005-01-12T00:00:00.000000000',
       '2005-01-13T00:00:00.000000000', '2005-01-14T00:00:00.000000000',
       '2005-01-15T00:00:00.000000000', '2005-01-16T00:00:00.000000000',
       '2005-01-17T00:00:00.000000000', '2005-01-18T00:00:00.000000000',
       '2005-01-19T00:00:00.000000000', '2005-01-20T00:00:00.000000000',
       '2005-01-21T00:00:00.000000000', '2005-01-22T00:00:00.000000000',
       '2005-01-23T00:00:00.000000000', '2005-01-24T00:00:00.000000000',
       '2005-01-25T00:00:00.000000000', '2005-01-26T00:00:00.000000000',
       '2005-01-27T00:00:00.000000000', '2005-01-28T00:00:00.000000000',
       '2005-01-29T00:00:00.000000000', '2005-01-30T00:00:00.000000000',
       '2005-01-31T00:00:00.000000000', '2005-02-01T00:00:00.000000000',
       '2005-02-02T00:00:00.000000000', '2005-02-03T00:00:00.000000000',
       '2005-02-04T00:00:00.000000000', '2005-02-05T00:00:00.000000000',
       '2005-02-06T00:00:00.000000000', '2005-02-07T00:00:00.000000000',
       '2005-02-08T00:00:00.000000000', '2005-02-09T00:00:00.000000000',
       '2005-02-10T00:00:00.000000000', '2005-02-11T00:00:00.000000000',
       '2005-02-12T00:00:00.000000000', '2005-02-13T00:00:00.000000000',
       '2005-02-14T00:00:00.000000000', '2005-02-15T00:00:00.000000000',
       '2005-02-16T00:00:00.000000000', '2005-02-17T00:00:00.000000000',
       '2005-02-18T00:00:00.000000000', '2005-02-19T00:00:00.000000000',
       '2005-02-20T00:00:00.000000000', '2005-02-21T00:00:00.000000000',
       '2005-02-22T00:00:00.000000000', '2005-02-23T00:00:00.000000000',
       '2005-02-24T00:00:00.000000000', '2005-02-25T00:00:00.000000000',
       '2005-02-26T00:00:00.000000000', '2005-02-27T00:00:00.000000000',
       '2005-02-28T00:00:00.000000000', '2005-03-01T00:00:00.000000000',
       '2005-03-02T00:00:00.000000000', '2005-03-03T00:00:00.000000000',
       '2005-03-04T00:00:00.000000000', '2005-03-05T00:00:00.000000000',
       '2005-03-06T00:00:00.000000000', '2005-03-07T00:00:00.000000000',
       '2005-03-08T00:00:00.000000000', '2005-03-09T00:00:00.000000000',
       '2005-03-10T00:00:00.000000000', '2005-03-11T00:00:00.000000000',
       '2005-03-12T00:00:00.000000000', '2005-03-13T00:00:00.000000000',
       '2005-03-14T00:00:00.000000000', '2005-03-15T00:00:00.000000000',
       '2005-03-16T00:00:00.000000000', '2005-03-17T00:00:00.000000000',
       '2005-03-18T00:00:00.000000000', '2005-03-19T00:00:00.000000000',
       '2005-03-20T00:00:00.000000000', '2005-03-21T00:00:00.000000000',
       '2005-03-22T00:00:00.000000000', '2005-03-23T00:00:00.000000000',
       '2005-03-24T00:00:00.000000000', '2005-03-25T00:00:00.000000000',
       '2005-03-26T00:00:00.000000000', '2005-03-27T00:00:00.000000000',
       '2005-03-28T00:00:00.000000000', '2005-03-29T00:00:00.000000000',
       '2005-03-30T00:00:00.000000000'], dtype='datetime64[ns]')
  1. values
values = np.array([7.70072076e 00, 1.15550154e 01, 2.52179418e 01, 1.55478327e 01,
       2.59781549e 01, 2.34152693e 01, 1.79109624e 01, 1.19977931e 01,
       1.00978354e 01, 0.00000000e 00, 4.63780341e 00, 9.86850318e 00,
       5.25415761e 00, 3.91471839e 00, 1.96036085e 01, 1.90064540e 01,
       1.11661406e 01, 2.25606837e 01, 6.00817101e 00, 1.69457231e 01,
       1.12589495e 01, 1.70272436e 01, 8.52431208e 00, 6.99124111e 00,
       1.34710377e 01, 1.40938799e 01, 1.38007694e 01, 2.41116309e 01,
       1.48877005e 01, 1.34417599e 01, 1.10949287e 01, 1.76228695e 01,
       2.00311967e 01, 1.34366201e 01, 2.59325445e 01, 2.14892189e 01,
       1.46289504e-01, 2.58948139e 01, 1.27299791e 01, 8.53511688e 00,
       1.95477776e 01, 7.75086195e 00, 1.08907403e 01, 1.21731987e 01,
       3.32295294e-01, 2.33457880e 01, 1.03636754e 00, 2.51652898e 00,
       0.00000000e 00, 2.36290467e 01, 7.49552335e 00, 5.31544824e 00,
       1.52790873e 00, 1.81752126e 01, 4.13123845e 00, 1.31874512e 01,
       6.01649464e-01, 9.40022796e 00, 2.04857146e 01, 7.54955426e 00,
       4.20621914e 00, 8.00308549e 00, 2.24401814e 00, 1.45324028e 01,
       1.45319574e 01, 7.99542387e 00, 2.76623390e 01, 1.07801930e 01,
       3.16076758e 00, 2.08360200e 01, 1.29046245e 01, 1.39387913e 01,
       1.20802721e 00, 1.46970620e 01, 2.54739344e 00, 2.61452965e 00,
       2.56090636e 01, 2.41717369e 00, 7.54546906e 00, 2.12478859e 01,
       1.19155216e 01, 4.63542198e 00, 7.71845492e 00, 1.56085474e 01,
       1.86042955e 01, 2.05600909e 01, 2.06061635e 01, 1.34498937e 00,
       2.32473478e 01, 3.79213708e 00, 4.41185690e 00, 4.76466781e 00,
       3.03566769e 00, 1.40809127e 01, 1.40129436e 01, 1.85373554e 01,
       1.97763783e 01, 0.00000000e 00, 1.50543144e 01, 1.39111993e 01,
       2.05928796e 01, 1.66687205e 00, 2.31263408e 00, 9.75572291e 00,
       2.07017149e 01, 1.58974488e 01, 1.16193468e 01, 7.27507123e 00,
       2.96885028e 00, 0.00000000e 00, 4.52040888e 00, 1.02263017e 01,
       1.03136977e 01, 8.25899582e-01, 5.03786892e 00, 1.68507230e 01,
       1.00213081e 01, 6.38183248e 00, 5.71099386e 00, 1.38144686e 01,
       7.15521205e 00, 5.94458881e 00, 2.62194930e 00, 1.94945780e 01,
       9.33201928e 00, 1.36677680e 01, 1.56902998e 01, 5.37752133e 00,
       3.58222494e 00, 1.00110565e 01, 9.00501132e 00, 6.06534711e 00,
       8.93813028e 00, 1.17667303e 01, 1.51834064e 01, 5.38251677e 00,
       6.64119918e 00, 8.50995608e 00, 5.16653574e 00, 1.07122130e 01,
       9.18142490e 00, 7.79627403e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       0.00000000e 00, 0.00000000e 00, 1.03848055e 01, 1.08489897e 01,
       6.21303638e 00, 1.06653583e 01, 1.90092719e 01, 2.47118370e 01,
       6.07360133e 01, 0.00000000e 00, 0.00000000e 00, 0.00000000e 00,
       7.20030534e-01, 2.49698890e 01, 2.13602459e-01, 2.45318682e 00,
       5.01041793e-01, 1.90137329e 01, 1.46071881e 01, 7.23347874e 00,
       1.95912745e 01, 3.58426756e 00, 9.51807936e 00, 4.36878079e-02,
       2.21128522e 01, 3.17686016e 01, 2.99007373e 01, 3.04031682e 01,
       2.02257518e 01, 1.86238389e 01, 2.76588079e 01, 2.21848903e 01,
       1.07687429e 01, 2.37335606e 01, 1.66929890e 01, 2.35181666e 01,
       1.69985338e 00, 2.83520296e 01, 2.16374393e 01, 2.05611237e 01,
       3.59128604e 01, 3.87838765e 01, 7.45223977e 00, 3.03020402e 01,
       1.86921895e 01, 2.09489534e 01, 3.58149879e 01, 1.27630888e 01,
       4.10551490e 01, 5.58532492e 00, 1.84476961e 01, 3.14587052e 01,
       3.25132686e 01, 6.31785153e 00, 3.46112066e 01, 5.39397069e 00,
       3.04035074e 01, 2.48492473e 01, 9.79893327e 00, 1.84628427e 01,
       1.86888600e 01, 3.67012881e 01, 3.41793981e 01, 3.99801672e 01,
       3.93846918e 01, 2.92138714e 01, 2.16493085e 01, 1.19923666e 01,
       2.06220580e 01, 9.22929337e 00, 1.21253861e 01, 2.39722270e 01,
       2.83720115e 01, 1.31777736e 01, 2.25567754e 01, 1.26539722e 01,
       2.90462533e 01, 3.71084505e 01, 4.30259275e 01, 4.07509318e 01,
       2.35128070e 01, 3.53533807e 01, 1.70285172e 01, 3.30286511e 01,
       2.38847906e 01, 0.00000000e 00, 2.52662806e 01, 1.69363015e 01,
       2.46401968e 01, 2.11388967e 01, 1.02503617e 01, 5.87485942e 00,
       6.58417043e-01, 1.59571398e 01, 1.38180476e 01, 7.53667991e 00,
       1.63162834e 01, 2.87401191e 01, 3.24826676e 01, 2.11112348e 01,
       2.22729622e 01, 2.08574081e 01, 1.04833067e 01, 6.79199822e 00,
       2.35733811e 01, 3.51793514e 01, 6.80932152e 00, 2.09290927e 01,
       4.35239938e 00, 6.31846749e 00, 4.59065600e 00, 2.83986563e 01,
       3.62887793e 01, 1.80637687e 01, 1.35552655e 01, 1.67298455e 00,
       3.12957390e 01, 3.81211895e 01, 2.81783440e 01, 5.73997181e 00,
       2.58828941e 00, 2.45794860e 01, 8.26224226e 00, 8.32910394e 00,
       2.67829527e 01, 2.14388670e 01, 2.39131033e 01, 1.28893395e 01,
       6.80103296e 00, 5.90787620e 00, 1.33425236e 01, 1.14569906e 01,
       6.92987448e 00, 4.11646860e 00, 3.02049801e 01, 3.70180538e 01,
       3.27249529e 01, 1.58443540e 01, 3.41710006e-01, 2.36869973e 00,
       1.96053557e 01, 1.01010941e 01, 3.89427977e 01, 1.87978068e 01,
       2.53674880e 01, 1.35991975e 01, 8.33476273e 00, 7.39297656e 00,
       2.26704228e 01, 3.81890746e 01, 3.92587785e 00, 3.30023774e 01,
       2.36791818e 01, 2.75009903e 01, 5.09154447e 00, 5.32452541e 00,
       1.74513700e 01, 1.83963763e 01, 3.12658501e 01, 3.99468412e 01,
       2.12089935e 01, 1.39061695e 01, 1.91288989e 01, 1.30272091e 01,
       1.36074910e 01, 3.69017354e 01, 2.93510937e 01, 2.40498501e 01,
       1.24911778e 00, 2.58514096e 01, 1.39207610e 01, 3.66927101e 01,
       4.65986156e 00, 2.41432470e 01, 1.87374470e 01])

CodePudding user response:

A quick approach could be the following:

months = times.astype('datetime64[M]').astype(int) % 12   1
print([(month, values[months==month].mean()) for month in set(months)])

years = times.astype('datetime64[Y]').astype(int)   19707
print([(year, values[years==year].mean()) for year in set(years)])

FOLLOW UP

Following up on your comment:

yearmonths=years*100   months

print([(ym, values[yearmonths==ym].mean()) for ym in set(yearmonths)])
  • Related