# xarray.DataArray.groupby_bins

#### DataArray.groupby_bins(group, bins, right=True, labels=None, precision=3, include_lowest=False, squeeze=False, restore_coord_dims=False, duplicates='raise', eagerly_compute_group=None)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/dataarray.py#L7287-L7383)

Returns a DataArrayGroupBy object for performing grouped operations.

Rather than using all unique values of group, the values are discretized
first by applying pandas.cut <sup>[1](#id2)</sup> to group.

* **Parameters:**
  * **group** (`Hashable`, [`DataArray`](xarray.DataArray.html.md#xarray.DataArray) or [`IndexVariable`](xarray.IndexVariable.html.md#xarray.IndexVariable)) – Array whose binned values should be used to group this array. If a
    Hashable, must be the name of a coordinate contained in this dataarray.
  * **bins** ([`int`](https://docs.python.org/3/builtins/functions.html#int) or [array-like](https://numpy.org/doc/stable/glossary.html#term-array_like)) – If bins is an int, it defines the number of equal-width bins in the
    range of x. However, in this case, the range of x is extended by .1%
    on each side to include the min or max values of x. If bins is a
    sequence it defines the bin edges allowing for non-uniform bin
    width. No extension of the range of x is done in this case.
  * **right** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default*: [`True`](https://docs.python.org/3/builtins/constants.html#True)) – Indicates whether the bins include the rightmost edge or not. If
    right == True (the default), then the bins [1,2,3,4] indicate
    (1,2], (2,3], (3,4].
  * **labels** ([array-like](https://numpy.org/doc/stable/glossary.html#term-array_like), [`False`](https://docs.python.org/3/builtins/constants.html#False) or [`None`](https://docs.python.org/3/builtins/constants.html#None), *default*: [`None`](https://docs.python.org/3/builtins/constants.html#None)) – Used as labels for the resulting bins. Must be of the same length as
    the resulting bins. If False, string bin labels are assigned by
    pandas.cut.
  * **precision** ([`int`](https://docs.python.org/3/builtins/functions.html#int), *default*: `3`) – The precision at which to store and display the bins labels.
  * **include_lowest** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default*: [`False`](https://docs.python.org/3/builtins/constants.html#False)) – Whether the first interval should be left-inclusive or not.
  * **squeeze** ([`False`](https://docs.python.org/3/builtins/constants.html#False)) – This argument is deprecated.
  * **restore_coord_dims** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default*: [`False`](https://docs.python.org/3/builtins/constants.html#False)) – If True, also restore the dimension order of multi-dimensional
    coordinates.
  * **duplicates** (`{"raise", "drop"}`, *default*: `"raise"`) – If bin edges are not unique, raise ValueError or drop non-uniques.
  * **eagerly_compute_group** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *optional*) – This argument is deprecated.
* **Returns:**
  **grouped** ([`DataArrayGroupBy`](xarray.core.groupby.DataArrayGroupBy.html.md#xarray.core.groupby.DataArrayGroupBy)) – A DataArrayGroupBy object patterned after pandas.GroupBy that can be
  iterated over in the form of (unique_value, grouped_array) pairs.
  The name of the group has the added suffix \_bins in order to
  distinguish it from the original variable.

#### SEE ALSO
[GroupBy: Group and Bin Data](../user-guide/groupby.html.md#groupby)
: Users guide explanation of how to group and bin data.

[`DataArray.groupby`](xarray.DataArray.groupby.html.md#xarray.DataArray.groupby), [`Dataset.groupby_bins`](xarray.Dataset.groupby_bins.html.md#xarray.Dataset.groupby_bins), [`core.groupby.DataArrayGroupBy`](xarray.core.groupby.DataArrayGroupBy.html.md#xarray.core.groupby.DataArrayGroupBy), [`pandas.DataFrame.groupby`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.groupby.html#pandas.DataFrame.groupby)

### References

* <a id='id2'>**[1]**</a> [https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.cut.html](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.cut.html)
