開始使用免費開始

使用 xarray 進行探索式資料分析

Xarray 讓你更輕鬆地處理多維度資料,就像 pandas 讓你更容易處理表格型資料一樣。更棒的是,Xarray 可以在背景中使用 Dask,幫你快速又有效率地處理資料。

你受託要進一步分析歐洲天氣資料集。既然已經會用 Xarray,先從探索式資料分析開始吧。

xarray 已經以 xr 匯入。

本練習屬於課程

在 Python 中使用 Dask 進行平行程式設計

檢視課程

練習說明

  • 使用 Xarray 的 open_zarr() 函式開啟資料集 "data/era_eu.zarr"
  • 使用 DataSet 的 .isel() 方法,選取 time 座標的第 0 個索引。
  • 從第 0 個索引的 ds_sel 中選取變數 'temp',並繪製到 ax1
  • 從第 0 個索引的 ds_sel 中選取變數 'precip',並繪製到 ax2

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Open the ERA5 dataset
ds = ____.____("____")

# Select the zeroth time in the DataSet
ds_sel = ds.____(____=____)

fig, (ax1, ax2) = plt.subplots(1,2, figsize=(8, 3))

# Plot the zeroth temperature field on ax1
____[____].____(ax=____)

# Plot the zeroth precipitation field on ax2
____[____].____(ax=____)
plt.show()
編輯並執行程式碼