html_url,issue_url,id,node_id,user,created_at,updated_at,author_association,body,reactions,performed_via_github_app,issue
https://github.com/pydata/xarray/issues/2594#issuecomment-445452721,https://api.github.com/repos/pydata/xarray/issues/2594,445452721,MDEyOklzc3VlQ29tbWVudDQ0NTQ1MjcyMQ==,6628425,2018-12-08T11:36:16Z,2018-12-08T11:36:16Z,MEMBER,"It just takes the average.
However if you have an array of weights, it is straightforward to use groupby to take a weighted mean:
```python
import numpy as np
import pandas as pd
import xarray as xr
times = pd.date_range('2001', periods=36, freq='MS')
da = xr.DataArray(range(36), [('time', times)])
weights = times.shift(1, 'MS') - times
weights = xr.DataArray(weights, [('time', times)]).astype('float')
annual_means = ((da * weights).groupby('time.year').sum('time') /
weights.groupby('time.year').sum('time'))
```
Note this assumes that your DataArray does not contain missing values. If your array has missing values, you might want to use something like this:
```python
annual_means = ((da * weights).groupby('time.year').sum('time') /
weights.where(~np.isnan(da)).groupby('time.year').sum('time'))
```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,388901771