Returns a DatasetGroupBy object for performing grouped operations. Rather than using all unique values of `group`, the values are discretized first by applying `pandas.cut` [1]_ to `group`. Parameters ---------- group : Hashable, DataArray or IndexVariable
(
self,
group: Hashable | DataArray | IndexVariable,
bins: Bins,
right: bool = True,
labels: ArrayLike | None = None,
precision: int = 3,
include_lowest: bool = False,
squeeze: Literal[False] = False,
restore_coord_dims: bool = False,
duplicates: Literal["raise", "drop"] = "raise",
eagerly_compute_group: Literal[False] | None = None,
)
| 10224 | |
| 10225 | @_deprecate_positional_args("v2024.07.0") |
| 10226 | def groupby_bins( |
| 10227 | self, |
| 10228 | group: Hashable | DataArray | IndexVariable, |
| 10229 | bins: Bins, |
| 10230 | right: bool = True, |
| 10231 | labels: ArrayLike | None = None, |
| 10232 | precision: int = 3, |
| 10233 | include_lowest: bool = False, |
| 10234 | squeeze: Literal[False] = False, |
| 10235 | restore_coord_dims: bool = False, |
| 10236 | duplicates: Literal["raise", "drop"] = "raise", |
| 10237 | eagerly_compute_group: Literal[False] | None = None, |
| 10238 | ) -> DatasetGroupBy: |
| 10239 | """Returns a DatasetGroupBy object for performing grouped operations. |
| 10240 | |
| 10241 | Rather than using all unique values of `group`, the values are discretized |
| 10242 | first by applying `pandas.cut` [1]_ to `group`. |
| 10243 | |
| 10244 | Parameters |
| 10245 | ---------- |
| 10246 | group : Hashable, DataArray or IndexVariable |
| 10247 | Array whose binned values should be used to group this array. If a |
| 10248 | string, must be the name of a variable contained in this dataset. |
| 10249 | bins : int or array-like |
| 10250 | If bins is an int, it defines the number of equal-width bins in the |
| 10251 | range of x. However, in this case, the range of x is extended by .1% |
| 10252 | on each side to include the min or max values of x. If bins is a |
| 10253 | sequence it defines the bin edges allowing for non-uniform bin |
| 10254 | width. No extension of the range of x is done in this case. |
| 10255 | right : bool, default: True |
| 10256 | Indicates whether the bins include the rightmost edge or not. If |
| 10257 | right == True (the default), then the bins [1,2,3,4] indicate |
| 10258 | (1,2], (2,3], (3,4]. |
| 10259 | labels : array-like or bool, default: None |
| 10260 | Used as labels for the resulting bins. Must be of the same length as |
| 10261 | the resulting bins. If False, string bin labels are assigned by |
| 10262 | `pandas.cut`. |
| 10263 | precision : int, default: 3 |
| 10264 | The precision at which to store and display the bins labels. |
| 10265 | include_lowest : bool, default: False |
| 10266 | Whether the first interval should be left-inclusive or not. |
| 10267 | squeeze : False |
| 10268 | This argument is deprecated. |
| 10269 | restore_coord_dims : bool, default: False |
| 10270 | If True, also restore the dimension order of multi-dimensional |
| 10271 | coordinates. |
| 10272 | duplicates : {"raise", "drop"}, default: "raise" |
| 10273 | If bin edges are not unique, raise ValueError or drop non-uniques. |
| 10274 | eagerly_compute_group: False, optional |
| 10275 | This argument is deprecated. |
| 10276 | |
| 10277 | Returns |
| 10278 | ------- |
| 10279 | grouped : DatasetGroupBy |
| 10280 | A `DatasetGroupBy` object patterned after `pandas.GroupBy` that can be |
| 10281 | iterated over in the form of `(unique_value, grouped_array)` pairs. |
| 10282 | The name of the group has the added suffix `_bins` in order to |
| 10283 | distinguish it from the original variable. |