# xarray.groupers.BinGrouper

### *class* xarray.groupers.BinGrouper(bins, right=True, labels=None, precision=3, include_lowest=False, duplicates='raise')[[source]](https://github.com/pydata/xarray/blob/main/xarray/groupers.py#L345-L474)

Grouper object for binning numeric data.

#### bins

The criteria to bin by.

* int : Defines the number of equal-width bins in the range of x. The
  range of x is extended by .1% on each side to include the minimum
  and maximum values of x.
* sequence of scalars : Defines the bin edges allowing for non-uniform
  width. No extension of the range of x is done.
* IntervalIndex : Defines the exact bins to be used. Note that
  IntervalIndex for bins must be non-overlapping.

* **Type:**
  [`int`](https://docs.python.org/3/builtins/functions.html#int), [sequence](https://docs.python.org/3/glossary.html#term-sequence) of `scalars`, or [`IntervalIndex`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.IntervalIndex.html#pandas.IntervalIndex)

#### right

Indicates whether bins includes the rightmost edge or not. If
`right == True` (the default), then the bins `[1, 2, 3, 4]`
indicate (1,2], (2,3], (3,4]. This argument is ignored when
bins is an IntervalIndex.

* **Type:**
  [`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default* [`True`](https://docs.python.org/3/builtins/constants.html#True)

#### labels

Specifies the labels for the returned bins. Must be the same length as
the resulting bins. If False, returns only integer indicators of the
bins. This affects the type of the output container (see below).
This argument is ignored when bins is an IntervalIndex. If True,
raises an error.

* **Type:**
  [array](https://numpy.org/doc/stable/glossary.html#term-array) or [`False`](https://docs.python.org/3/builtins/constants.html#False), *default* [`None`](https://docs.python.org/3/builtins/constants.html#None)

#### retbins

Whether to return the bins or not. Useful when bins is provided
as a scalar.

* **Type:**
  [`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default* [`False`](https://docs.python.org/3/builtins/constants.html#False)

#### precision

The precision at which to store and display the bins labels.

* **Type:**
  [`int`](https://docs.python.org/3/builtins/functions.html#int), *default* `3`

#### include_lowest

Whether the first interval should be left-inclusive or not.

* **Type:**
  [`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default* [`False`](https://docs.python.org/3/builtins/constants.html#False)

#### duplicates

If bin edges are not unique, raise ValueError or drop non-uniques.

* **Type:**
  `{"raise", "drop"}`, *default*: `"raise"`

#### \_\_init_\_(bins, right=True, labels=None, precision=3, include_lowest=False, duplicates='raise')[[source]](https://github.com/pydata/xarray/blob/main/xarray/../doc/<string>)

### Methods

| [`__init__`](#xarray.groupers.BinGrouper.__init__)(bins[, right, labels, precision, ...])   |                                                            |
|----------------------------------------------------------------------------------------------------|------------------------------------------------------------|
| `factorize`(group)                                                                                 | Creates intermediates necessary for GroupBy.               |
| `reset`()                                                                                          | Creates a new version of this Grouper clearing any caches. |

### Attributes

| [`duplicates`](#xarray.groupers.BinGrouper.duplicates)     |    |
|-----------------------------------------------------------------|----|
| [`include_lowest`](#xarray.groupers.BinGrouper.include_lowest) |    |
| [`labels`](#xarray.groupers.BinGrouper.labels)         |    |
| [`precision`](#xarray.groupers.BinGrouper.precision)      |    |
| [`right`](#xarray.groupers.BinGrouper.right)          |    |
| [`bins`](#xarray.groupers.BinGrouper.bins)           |    |
