The xarray package provides the DataArray andDataSet classes, which are (roughly speaking) multi-dimensional equivalents of the Pandas Series and DataFrame objects. We're using a dataset in this example because each index – a tuple of a date and location – has two pieces of data associated with it. Both of these objects expose a similar interface to their Pandas equivalents. For example, we can compute the mean along one of the axes using the mean method. The DataArray and DataSet objects also have a convenience method for converting into a Pandas DataFrame called to_dataframe. We used it in this recipe to convert to a DataFrame for plotting, which isn't really necessary because xarray has plotting features built into it.
The real focus of this recipe is on the to_netcdf method and the load_dataset routine. The former stores a DataSet in NetCDF format file. This requires the NetCDF4 package to be installed as it allows us to access...