Get startedGet started for free

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.

This exercise is part of the course

Parallel Programming with Dask in Python

View Course

Exercise instructions

  • 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.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# 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()
Edit and Run Code