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` [1]_ to `group`. Parameters ---------- group : Hashable, DataArray or IndexVariable
(
self,
group: Hashable | DataArray | IndexVariable,
bins: Bins,
right: bool = True,
labels: ArrayLike | Literal[False] | 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,
)
| 7073 | |
| 7074 | @_deprecate_positional_args("v2024.07.0") |
| 7075 | def groupby_bins( |
| 7076 | self, |
| 7077 | group: Hashable | DataArray | IndexVariable, |
| 7078 | bins: Bins, |
| 7079 | right: bool = True, |
| 7080 | labels: ArrayLike | Literal[False] | None = None, |
| 7081 | precision: int = 3, |
| 7082 | include_lowest: bool = False, |
| 7083 | squeeze: Literal[False] = False, |
| 7084 | restore_coord_dims: bool = False, |
| 7085 | duplicates: Literal["raise", "drop"] = "raise", |
| 7086 | eagerly_compute_group: Literal[False] | None = None, |
| 7087 | ) -> DataArrayGroupBy: |
| 7088 | """Returns a DataArrayGroupBy object for performing grouped operations. |
| 7089 | |
| 7090 | Rather than using all unique values of `group`, the values are discretized |
| 7091 | first by applying `pandas.cut` [1]_ to `group`. |
| 7092 | |
| 7093 | Parameters |
| 7094 | ---------- |
| 7095 | group : Hashable, DataArray or IndexVariable |
| 7096 | Array whose binned values should be used to group this array. If a |
| 7097 | Hashable, must be the name of a coordinate contained in this dataarray. |
| 7098 | bins : int or array-like |
| 7099 | If bins is an int, it defines the number of equal-width bins in the |
| 7100 | range of x. However, in this case, the range of x is extended by .1% |
| 7101 | on each side to include the min or max values of x. If bins is a |
| 7102 | sequence it defines the bin edges allowing for non-uniform bin |
| 7103 | width. No extension of the range of x is done in this case. |
| 7104 | right : bool, default: True |
| 7105 | Indicates whether the bins include the rightmost edge or not. If |
| 7106 | right == True (the default), then the bins [1,2,3,4] indicate |
| 7107 | (1,2], (2,3], (3,4]. |
| 7108 | labels : array-like, False or None, default: None |
| 7109 | Used as labels for the resulting bins. Must be of the same length as |
| 7110 | the resulting bins. If False, string bin labels are assigned by |
| 7111 | `pandas.cut`. |
| 7112 | precision : int, default: 3 |
| 7113 | The precision at which to store and display the bins labels. |
| 7114 | include_lowest : bool, default: False |
| 7115 | Whether the first interval should be left-inclusive or not. |
| 7116 | squeeze : False |
| 7117 | This argument is deprecated. |
| 7118 | restore_coord_dims : bool, default: False |
| 7119 | If True, also restore the dimension order of multi-dimensional |
| 7120 | coordinates. |
| 7121 | duplicates : {"raise", "drop"}, default: "raise" |
| 7122 | If bin edges are not unique, raise ValueError or drop non-uniques. |
| 7123 | eagerly_compute_group: bool, optional |
| 7124 | This argument is deprecated. |
| 7125 | |
| 7126 | Returns |
| 7127 | ------- |
| 7128 | grouped : DataArrayGroupBy |
| 7129 | A `DataArrayGroupBy` object patterned after `pandas.GroupBy` that can be |
| 7130 | iterated over in the form of `(unique_value, grouped_array)` pairs. |
| 7131 | The name of the group has the added suffix `_bins` in order to |
| 7132 | distinguish it from the original variable. |