Grouper object for binning numeric data. Attributes ---------- bins : int, sequence of scalars, or IntervalIndex 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 t
| 342 | |
| 343 | @dataclass |
| 344 | class BinGrouper(Grouper): |
| 345 | """ |
| 346 | Grouper object for binning numeric data. |
| 347 | |
| 348 | Attributes |
| 349 | ---------- |
| 350 | bins : int, sequence of scalars, or IntervalIndex |
| 351 | The criteria to bin by. |
| 352 | |
| 353 | * int : Defines the number of equal-width bins in the range of `x`. The |
| 354 | range of `x` is extended by .1% on each side to include the minimum |
| 355 | and maximum values of `x`. |
| 356 | * sequence of scalars : Defines the bin edges allowing for non-uniform |
| 357 | width. No extension of the range of `x` is done. |
| 358 | * IntervalIndex : Defines the exact bins to be used. Note that |
| 359 | IntervalIndex for `bins` must be non-overlapping. |
| 360 | |
| 361 | right : bool, default True |
| 362 | Indicates whether `bins` includes the rightmost edge or not. If |
| 363 | ``right == True`` (the default), then the `bins` ``[1, 2, 3, 4]`` |
| 364 | indicate (1,2], (2,3], (3,4]. This argument is ignored when |
| 365 | `bins` is an IntervalIndex. |
| 366 | labels : array or False, default None |
| 367 | Specifies the labels for the returned bins. Must be the same length as |
| 368 | the resulting bins. If False, returns only integer indicators of the |
| 369 | bins. This affects the type of the output container (see below). |
| 370 | This argument is ignored when `bins` is an IntervalIndex. If True, |
| 371 | raises an error. |
| 372 | retbins : bool, default False |
| 373 | Whether to return the bins or not. Useful when bins is provided |
| 374 | as a scalar. |
| 375 | precision : int, default 3 |
| 376 | The precision at which to store and display the bins labels. |
| 377 | include_lowest : bool, default False |
| 378 | Whether the first interval should be left-inclusive or not. |
| 379 | duplicates : {"raise", "drop"}, default: "raise" |
| 380 | If bin edges are not unique, raise ValueError or drop non-uniques. |
| 381 | """ |
| 382 | |
| 383 | bins: Bins |
| 384 | # The rest are copied from pandas |
| 385 | right: bool = True |
| 386 | labels: Any = None |
| 387 | precision: int = 3 |
| 388 | include_lowest: bool = False |
| 389 | duplicates: Literal["raise", "drop"] = "raise" |
| 390 | |
| 391 | def reset(self) -> Self: |
| 392 | return type(self)( |
| 393 | bins=self.bins, |
| 394 | right=self.right, |
| 395 | labels=self.labels, |
| 396 | precision=self.precision, |
| 397 | include_lowest=self.include_lowest, |
| 398 | duplicates=self.duplicates, |
| 399 | ) |
| 400 | |
| 401 | def __post_init__(self) -> None: |
no outgoing calls
searching dependent graphs…