@@ -9346,9 +9346,123 @@ def update(
93469346
93479347 # ----------------------------------------------------------------------
93489348 # Data reshaping
9349- @Appender (
9350- dedent (
9351- """
9349+ @deprecate_nonkeyword_arguments (
9350+ Pandas4Warning , allowed_ards = ["self" , "by" , "level" ], name = "groupby"
9351+ )
9352+ def groupby (
9353+ self ,
9354+ by = None ,
9355+ level : IndexLabel | None = None ,
9356+ as_index : bool = True ,
9357+ sort : bool = True ,
9358+ group_keys : bool = True ,
9359+ observed : bool = True ,
9360+ dropna : bool = True ,
9361+ ) -> DataFrameGroupBy :
9362+ """
9363+ Group DataFrame using a mapper or by a Series of columns.
9364+
9365+ A groupby operation involves some combination of splitting the
9366+ object, applying a function, and combining the results. This can be
9367+ used to group large amounts of data and compute operations on these
9368+ groups.
9369+
9370+ Parameters
9371+ ----------
9372+ by : mapping, function, label, pd.Grouper or list of such
9373+ Used to determine the groups for the groupby.
9374+ If ``by`` is a function, it's called on each value of the object's
9375+ index. If a dict or Series is passed, the Series or dict VALUES
9376+ will be used to determine the groups (the Series' values are first
9377+ aligned; see ``.align()`` method). If a list or ndarray of length
9378+ equal to the selected axis is passed (see the `groupby user guide
9379+ <https://pandas.pydata.org/pandas-docs/stable/user_guide/groupby.html#splitting-an-object-into-groups>`_),
9380+ the values are used as-is to determine the groups. A label or list
9381+ of labels may be passed to group by the columns in ``self``.
9382+ Notice that a tuple is interpreted as a (single) key.
9383+ level : int, level name, or sequence of such, default None
9384+ If the axis is a MultiIndex (hierarchical), group by a particular
9385+ level or levels. Do not specify both ``by`` and ``level``.
9386+ as_index : bool, default True
9387+ Return object with group labels as the
9388+ index. Only relevant for DataFrame input. as_index=False is
9389+ effectively "SQL-style" grouped output. This argument has no effect
9390+ on filtrations (see the `filtrations in the user guide
9391+ <https://pandas.pydata.org/docs/dev/user_guide/groupby.html#filtration>`_),
9392+ such as ``head()``, ``tail()``, ``nth()`` and in transformations
9393+ (see the `transformations in the user guide
9394+ <https://pandas.pydata.org/docs/dev/user_guide/groupby.html#transformation>`_).
9395+ sort : bool, default True
9396+ Sort group keys. Get better performance by turning this off.
9397+ Note this does not influence the order of observations within each
9398+ group. Groupby preserves the order of rows within each group. If False,
9399+ the groups will appear in the same order as they did in the original DataFrame.
9400+ This argument has no effect on filtrations (see the `filtrations in the user guide
9401+ <https://pandas.pydata.org/docs/dev/user_guide/groupby.html#filtration>`_),
9402+ such as ``head()``, ``tail()``, ``nth()`` and in transformations
9403+ (see the `transformations in the user guide
9404+ <https://pandas.pydata.org/docs/dev/user_guide/groupby.html#transformation>`_).
9405+
9406+ .. versionchanged:: 2.0.0
9407+
9408+ Specifying ``sort=False`` with an ordered categorical grouper will no
9409+ longer sort the values.
9410+
9411+ group_keys : bool, default True
9412+ When calling apply and the ``by`` argument produces a like-indexed
9413+ (i.e. :ref:`a transform <groupby.transform>`) result, add group keys to
9414+ index to identify pieces. By default group keys are not included
9415+ when the result's index (and column) labels match the inputs, and
9416+ are included otherwise.
9417+
9418+ .. versionchanged:: 1.5.0
9419+
9420+ Warns that ``group_keys`` will no longer be ignored when the
9421+ result from ``apply`` is a like-indexed Series or DataFrame.
9422+ Specify ``group_keys`` explicitly to include the group keys or
9423+ not.
9424+
9425+ .. versionchanged:: 2.0.0
9426+
9427+ ``group_keys`` now defaults to ``True``.
9428+
9429+ observed : bool, default True
9430+ This only applies if any of the groupers are Categoricals.
9431+ If True: only show observed values for categorical groupers.
9432+ If False: show all values for categorical groupers.
9433+
9434+ .. versionchanged:: 3.0.0
9435+
9436+ The default value is now ``True``.
9437+
9438+ dropna : bool, default True
9439+ If True, and if group keys contain NA values, NA values together
9440+ with row/column will be dropped.
9441+ If False, NA values will also be treated as the key in groups.
9442+
9443+ Returns
9444+ -------
9445+ pandas.api.typing.DataFrameGroupBy
9446+ Returns a groupby object that contains information about the groups.
9447+
9448+ See Also
9449+ --------
9450+ resample : Convenience method for frequency conversion and resampling
9451+ of time series.
9452+
9453+ Notes
9454+ -----
9455+ See the `user guide
9456+ <https://pandas.pydata.org/pandas-docs/stable/groupby.html>`__ for more
9457+ detailed usage and examples, including splitting an object into groups,
9458+ iterating through groups, selecting a group, aggregation, and more.
9459+
9460+ The implementation of groupby is hash-based, meaning in particular that
9461+ objects that compare as equal will be considered to be in the same group.
9462+ An exception to this is that pandas has special handling of NA values:
9463+ any NA values will be collapsed to a single group, regardless of how
9464+ they compare. See the user guide linked above for more details.
9465+
93529466 Examples
93539467 --------
93549468 >>> df = pd.DataFrame({'Animal': ['Falcon', 'Falcon',
@@ -9450,22 +9564,6 @@ def update(
94509564 2 24.0
94519565 3 26.0
94529566 """
9453- )
9454- )
9455- @Appender (_shared_docs ["groupby" ] % _shared_doc_kwargs )
9456- @deprecate_nonkeyword_arguments (
9457- Pandas4Warning , allowed_args = ["self" , "by" , "level" ], name = "groupby"
9458- )
9459- def groupby (
9460- self ,
9461- by = None ,
9462- level : IndexLabel | None = None ,
9463- as_index : bool = True ,
9464- sort : bool = True ,
9465- group_keys : bool = True ,
9466- observed : bool = True ,
9467- dropna : bool = True ,
9468- ) -> DataFrameGroupBy :
94699567 from pandas .core .groupby .generic import DataFrameGroupBy
94709568
94719569 if level is None and by is None :
@@ -9482,6 +9580,8 @@ def groupby(
94829580 dropna = dropna ,
94839581 )
94849582
9583+
9584+
94859585 _shared_docs ["pivot" ] = """
94869586 Return reshaped DataFrame organized by given index / column values.
94879587
0 commit comments