每月平均氣溫
看過平均氣溫的分析之後,你想把其他月份也一併算出來。若用先前的方法,得在時間上做相當繁複的切片來選對月份,會很麻煩。所幸使用 Xarray 就簡單多了。
歐洲天氣資料集已載入為 Xarray DataSet ds,可在你的環境中使用。
本練習屬於課程
在 Python 中使用 Dask 進行平行程式設計
練習說明
- 使用
ds的'time'座標中的 datetime 存取器,將月份指定給變數months。 - 從
ds中選取'temp'變數,並依months分組。 - 對分組取平均,計算所有時間上的每月平均。
- 計算(compute)結果。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Extract the months from the time coordinates
months = ds['____'].____.____
# Select the temp DataArray and group by months
monthly_groupby = ds['____'].____(____)
# Find the mean temp by month
monthly_mean_temps = ____.____()
# Compute the result
monthly_mean_temps_computed = ____.____()
monthly_mean_temps_computed.plot(col='month', col_wrap=4, add_colorbar=False)
plt.show()