xarray.Dataset.groupby

xarray.Dataset.groupby#

Dataset.groupby(group=None, *, squeeze=False, restore_coord_dims=False, **groupers)[source]#

Returns a DatasetGroupBy object for performing grouped operations.

Parameters:
  • group (Hashable or DataArray or IndexVariable or mapping of Hashable to Grouper) – Array whose unique values should be used to group this array. If a Hashable, must be the name of a coordinate contained in this dataarray. If a dictionary, must map an existing variable name to a Grouper instance.

  • squeeze (bool, default: True) – If “group” is a dimension of any arrays in this dataset, squeeze controls whether the subarrays have a dimension of length 1 along that dimension or if the dimension is squeezed out.

  • restore_coord_dims (bool, default: False) – If True, also restore the dimension order of multi-dimensional coordinates.

  • **groupers (Mapping of str to Grouper or Resampler) – Mapping of variable name to group by to Grouper or Resampler object. One of group or groupers must be provided. Only a single grouper is allowed at present.

Returns:

grouped (DatasetGroupBy) – A DatasetGroupBy object patterned after pandas.GroupBy that can be iterated over in the form of (unique_value, grouped_array) pairs.

See also

GroupBy: Group and Bin Data

Users guide explanation of how to group and bin data.

Computational Patterns

Tutorial on Groupby() for windowed computation.

Grouped Computations

Tutorial on Groupby() demonstrating reductions, transformation and comparison with resample().

Dataset.groupby_bins DataArray.groupby core.groupby.DatasetGroupBy pandas.DataFrame.groupby Dataset.coarsen Dataset.resample DataArray.resample