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
.
Cet exercice fait partie du cours
Parallel Programming with Dask in Python
Instructions
- Use the datetime accessor in the
'time'
coordinate ofds
to assign the months to the variablemonths
. - Select the
'temp'
variable fromds
and group it by themonths
. - Take the mean over the group to calculate the monthly means over all times.
- Compute the result.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de 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()