How do I …

How do I…


add variables from other datasets to my dataset


add a new dimension and/or coordinate

DataArray.expand_dims(), Dataset.expand_dims()

add a new coordinate variable


change a data variable to a coordinate variable


change the order of dimensions

DataArray.transpose(), Dataset.transpose()

remove a variable from my object

Dataset.drop(), DataArray.drop()

remove dimensions of length 1 or 0

DataArray.squeeze(), Dataset.squeeze()

remove all variables with a particular dimension


convert non-dimension coordinates to data variables or remove them

DataArray.reset_coords(), Dataset.reset_coords()

rename a variable, dimension or coordinate

Dataset.rename(), DataArray.rename(), Dataset.rename_vars(), Dataset.rename_dims(),

convert a DataArray to Dataset or vice versa

DataArray.to_dataset(), Dataset.to_array()

extract the underlying array (e.g. numpy or Dask arrays)

convert to and extract the underlying numpy array


find out if my xarray object is wrapping a Dask Array


know how much memory my object requires

DataArray.nbytes, Dataset.nbytes

convert a possibly irregularly sampled timeseries to a regularly sampled timeseries

DataArray.resample(), Dataset.resample() (see Resampling and grouped operations for more)

apply a function on all data variables in a Dataset


write xarray objects with complex values to a netCDF file

Dataset.to_netcdf(), DataArray.to_netcdf() specifying engine="h5netcdf", invalid_netcdf=True

make xarray objects look like other xarray objects

ones_like(), zeros_like(), full_like(), Dataset.reindex_like(), Dataset.interpolate_like(), Dataset.broadcast_like(), DataArray.reindex_like(), DataArray.interpolate_like(), DataArray.broadcast_like()

replace NaNs with other values

Dataset.fillna(), Dataset.ffill(), Dataset.bfill(), Dataset.interpolate_na(), DataArray.fillna(), DataArray.ffill(), DataArray.bfill(), DataArray.interpolate_na()

extract the year, month, day or similar from a DataArray of time values

obj.dt.month for example where obj is a DataArray containing datetime64 or cftime values. See Datetime components for more.

round off time values to a specified frequency

obj.dt.ceil, obj.dt.floor, obj.dt.round. See Datetime components for more.

make a mask that is True where an object contains any of the values in a array

Dataset.isin(), DataArray.isin()