評論:我要找每月平均爲12個月(2001年至2010年,所有年)。您的解決方案只計算月平均爲1年
從2001-01我第一輸出開始長達2010-12,因此,所有的年coverd。
你想要resample
這些值嗎?
我如何獲得12個月的月平均?
你必須決定你想要的東西:在一年之內
平均每個月,結果在每年12個值,高達120個價值在10年
或
平均爲1年,結果在10個值在10年
使用以下xarray.Dataset
,DATE_RANGE = 10年
date_range('2001-01-01', '2010-12-31', name='time')
<xarray.Dataset>
Dimensions: (time: 3652)
Coordinates:
* time (time) datetime64[ns] 2001-01-01 2001-01-02 2001-01-03 ...
Data variables:
data (time) float64 16.0 18.0 15.0 12.0 23.0 9.0 7.0 18.0 23.0 23.0 ...
獲取monthly_avr
爲每個月在date_range('2001-01-01', '2010-12-31', name='time')
:
monthly_avr = ds.resample('1MS', dim='time', how='mean')
輸出:
monthly_avr=<xarray.Dataset>
Dimensions: (time: 120)
Coordinates:
* time (time) datetime64[ns] 2001-01-01 2001-02-01 2001-03-01 ...
Data variables:
data (time) float64 17.42 16.54 19.23 18.37 14.74 17.8 16.45 17.29 ...
獲取year_avr
每年在date_range('2001-01-01', '2010-12-31', name='time')
:
year_avr = ds.resample('1AS', dim='time', how='mean')
輸出:
year_avr=<xarray.Dataset>
Dimensions: (time: 10)
Coordinates:
* time (time) datetime64[ns] 2001-01-01 2002-01-01 2003-01-01 ...
Data variables:
data (time) float64 17.22 17.13 17.05 17.49 17.38 17.07 16.72 16.47 ...
測試與Python 3.4.2 - xarray:0.9。1
謝謝@stovfl,我正在尋找12個月的月平均值(從2001年到2010年的所有年份)。您的解決方案僅計算1年的月平均值 – user308827