xray.DataArray.groupby

DataArray.groupby(group, squeeze=True)

Group this dataset by unique values of the indicated group.

Parameters:

group : str or DataArray

Array whose unique values should be used to group this array. If a string, must be the name of a variable contained in this dataset.

squeeze : boolean, optional

If “group” is a coordinate of this array, squeeze controls whether the subarrays have a dimension of length 1 along that coordinate or if the dimension is squeezed out.

Returns:

grouped : GroupBy

A GroupBy object patterned after pandas.GroupBy that can be iterated over in the form of (unique_value, grouped_array) pairs or over which grouped operations can be applied with the apply and reduce methods (and the associated aliases mean, sum, std, etc.).