xarray.groupers.BinGrouper#

class xarray.groupers.BinGrouper(bins, right=True, labels=None, precision=3, include_lowest=False, duplicates='raise')[source]#

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, sequence of scalars, or 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, default 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. When ordered=False, labels must be provided.

Type

array or False, default None

retbins#

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

Type

bool, default False

precision#

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

Type

int, default 3

include_lowest#

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

Type

bool, default 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]#

Methods

__init__(bins[, right, labels, precision, ...])

factorize(group)

Creates intermediates necessary for GroupBy.

Attributes