Group DataFrame using a mapper or by a Series of columns. A groupby operation involves some combination of splitting the object, applying a function, and combining the results. This can be used to group large amounts of data and compute operations on these g
(
self,
by=None,
level: IndexLabel | None = None,
as_index: bool = True,
sort: bool = True,
group_keys: bool = True,
observed: bool = True,
dropna: bool = True,
)
| 10611 | Pandas4Warning, allowed_args=[class="st">"self", class="st">"by", class="st">"level"], name=class="st">"groupby" |
| 10612 | ) |
| 10613 | def groupby( |
| 10614 | self, |
| 10615 | by=None, |
| 10616 | level: IndexLabel | None = None, |
| 10617 | as_index: bool = True, |
| 10618 | sort: bool = True, |
| 10619 | group_keys: bool = True, |
| 10620 | observed: bool = True, |
| 10621 | dropna: bool = True, |
| 10622 | ) -> DataFrameGroupBy: |
| 10623 | class="st">""" |
| 10624 | Group DataFrame using a mapper or by a Series of columns. |
| 10625 | |
| 10626 | A groupby operation involves some combination of splitting the |
| 10627 | object, applying a function, and combining the results. This can be |
| 10628 | used to group large amounts of data and compute operations on these |
| 10629 | groups. |
| 10630 | |
| 10631 | Parameters |
| 10632 | ---------- |
| 10633 | by : mapping, function, label, pd.Grouper or list of such |
| 10634 | Used to determine the groups for the groupby. |
| 10635 | If ``by`` is a function, it&class="cm">#x27;s called on each value of the object's |
| 10636 | index. If a dict or Series is passed, the Series or dict VALUES |
| 10637 | will be used to determine the groups (the Series&class="cm">#x27; values are first |
| 10638 | aligned; see ``.align()`` method). If a list or ndarray of length |
| 10639 | equal to the number of rows is passed (see the `groupby user guide |
| 10640 | <https://pandas.pydata.org/pandas-docs/stable/user_guide/groupby.htmlclass="cm">#splitting-an-object-into-groups>`_), |
| 10641 | the values are used as-is to determine the groups. A label or list |
| 10642 | of labels may be passed to group by the columns in ``self``. |
| 10643 | Notice that a tuple is interpreted as a (single) key. |
| 10644 | level : int, level name, or sequence of such, default None |
| 10645 | If the axis is a MultiIndex (hierarchical), group by a particular |
| 10646 | level or levels. Do not specify both ``by`` and ``level``. |
| 10647 | as_index : bool, default True |
| 10648 | Return object with group labels as the |
| 10649 | index. Only relevant for DataFrame input. as_index=False is |
| 10650 | effectively class="st">"SQL-style" grouped output. This argument has no effect |
| 10651 | on filtrations (see the `filtrations in the user guide |
| 10652 | <https://pandas.pydata.org/docs/dev/user_guide/groupby.htmlclass="cm">#filtration>`_), |
| 10653 | such as ``head()``, ``tail()``, ``nth()`` and in transformations |
| 10654 | (see the `transformations in the user guide |
| 10655 | <https://pandas.pydata.org/docs/dev/user_guide/groupby.htmlclass="cm">#transformation>`_). |
| 10656 | sort : bool, default True |
| 10657 | Sort group keys. Get better performance by turning this off. |
| 10658 | Note this does not influence the order of observations within each |
| 10659 | group. Groupby preserves the order of rows within each group. If False, |
| 10660 | the groups will appear in the same order as they did in the original |
| 10661 | DataFrame. |
| 10662 | This argument has no effect on filtrations (see the `filtrations |
| 10663 | in the user guide |
| 10664 | <https://pandas.pydata.org/docs/dev/user_guide/groupby.htmlclass="cm">#filtration>`_), |
| 10665 | such as ``head()``, ``tail()``, ``nth()`` and in transformations |
| 10666 | (see the `transformations in the user guide |
| 10667 | <https://pandas.pydata.org/docs/dev/user_guide/groupby.htmlclass="cm">#transformation>`_). |
| 10668 | |
| 10669 | .. versionchanged:: 2.0.0 |
| 10670 |