.html)
  * [ Resampling ](../resampling.html)
  * [ Style ](../style.html)
  * [ Plotting ](../plotting.html)
  * [ Options and settings ](../options.html)
  * [ Extensions ](../extensions.html)
  * [ Testing ](../testing.html)
  * [ Missing values ](../missing_value.html)

  * [ __ ](../../index.html)
  * [ API reference ](../index.html)
  * [ DataFrame ](../frame.html)
  * pandas.DataF... 

#  pandas.DataFrame.groupby  #

DataFrame.  groupby  (  _ by  =  None  _ , _ axis  =  _NoDefault.no_default  _
, _ level  =  None  _ , _ as_index  =  True  _ , _ sort  =  True  _ , _
group_keys  =  True  _ , _ observed  =  _NoDefault.no_default  _ , _ dropna  =
True  _ )  [ [source]  ](https://github.com/pandas-
dev/pandas/blob/v2.2.2/pandas/core/frame.py#L9041-L9193) #

    

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 groups.

Parameters  :

    

**by** mapping, function, label, pd.Grouper or list of such

    

Used to determine the groups for the groupby. If ` by  ` is a function, itâs
called on each value of the objectâs index. If a dict or Series is passed,
the Series or dict VALUES will be used to determine the groups (the Seriesâ
values are first aligned; see ` .align()  ` method). If a list or ndarray of
length equal to the selected axis is passed (see the [ groupby user guide
](https://pandas.pydata.org/pandas-
docs/stable/user_guide/groupby.html#splitting-an-object-into-groups) ), the
values are used as-is to determine the groups. A label or list of labels may
be passed to group by the columns in ` self  ` . Notice that a tuple is
interpreted as a (single) key.

**axis** {0 or âindexâ, 1 or âcolumnsâ}, default 0

    

Split along rows (0) or columns (1). For  Series  this parameter is unused and
defaults to 0.

Deprecated since version 2.1.0:  Will be removed and behave like axis=0 in a
future version. For ` axis=1  ` , do ` frame.T.groupby(...)  ` instead.

**level** int, level name, or sequence of such, default None

    

If the axis is a MultiIndex (hierarchical), group by a particular level or
levels. Do not specify both ` by  ` and ` level  ` .

**as_index** bool, default True

    

Return object with group labels as the index. Only relevant for DataFrame
input. as_index=False is effectively âSQL-styleâ grouped output. This
argument has no effect on filtrations (see the [ filtrations in the user guide
](https://pandas.pydata.org/docs/dev/user_guide/groupby.html#filtration) ),
such as ` head()  ` , ` tail()  ` , ` nth()  ` and in transformations (see the
[ transformations in the user guide
](https://pandas.pydata.org/docs/dev/user_guide/groupby.html#transformation)
).

**sort** bool, default True

    

Sort group keys. Get better performance by turning this off. Note this does
not influence the order of observations within each group. Groupby preserves
the order of rows within each group. If False, the groups will appear in the
same order as they did in the original DataFrame. This argument has no effect
on filtrations (see the [ filtrations in the user guide
](https://pandas.pydata.org/docs/dev/user_guide/groupby.html#filtration) ),
such as ` head()  ` , ` tail()  ` , ` nth()  ` and in transformations (see the
[ transformations in the user guide
](https://pandas.pydata.org/docs/dev/user_guide/groupby.html#transformation)
).

Changed in version 2.0.0:  Specifying ` sort=False  ` with an ordered
categorical grouper will no longer sort the values.

**group_keys** bool, default True

    

When calling apply and the ` by  ` argument produces a like-indexed (i.e. [ a
transform  ](../../user_guide/groupby.html#groupby-transform) ) result, add
group keys to index to identify pieces. By default group keys are not included
when the resultâs index (and column) labels match the inputs, and are
inclu