LoslegenKostenlos loslegen

Monthly mean temperatures

After seeing the analysis of the average temperatures, you simply need to see the rest of the months. This would be rather annoying to do using the method we used before as it involves a lot of complicated slicing in time to select the right months. Thankfully, with Xarray, it is a lot simpler.

The European weather dataset is available in your environment as the Xarray DataSet ds.

Diese Übung ist Teil des Kurses

Parallel Programming with Dask in Python

Kurs anzeigen

Anleitung zur Übung

  • Use the datetime accessor in the 'time' coordinate of ds to assign the months to the variable months.
  • Select the 'temp' variable from ds and group it by the months.
  • Take the mean over the group to calculate the monthly means over all times.
  • Compute the result.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# 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()
Code bearbeiten und ausführen