pandas.Series.groupby
pandas 3.1.1 · Series and accessors · method
Split an object by keys to aggregate, transform, or filter each group.
Call syntax
Series.groupby(…) Full signature
Series.groupby(
by=None,
level=None,
*,
as_index=True,
sort=True,
group_keys=True,
observed=True,
dropna=True,
)Provide either by or level to tell pandas how to group the data. The other parameters are optional.
Run the example
Edit the example and select Run Python to see the result.
Parameters
| Parameter | Requirement | Accepted values and behavior |
|---|---|---|
by |
Optional Positional or keyword Default None |
mapping, function, label, pd.Grouper or list of such Specify the labels, mapping, or values that determine the sort or grouping. |
level |
Optional Positional or keyword Default None |
int, level name, or sequence of such Choose an index level by name or integer position. |
as_index |
Optional Keyword only Default True |
bool |
sort |
Optional Keyword only Default True |
bool Choose whether the resulting labels or groups are sorted where supported. |
group_keys |
Optional Keyword only Default True |
bool Choose whether the grouping keys become index levels in the result. |
observed |
Optional Keyword only Default True |
bool When grouping categories, choose whether to keep only combinations present in the input. |
dropna |
Optional Keyword only Default True |
bool Choose whether to drop missing values or missing keys from consideration. |
Returns
pandas.api.typing.SeriesGroupBy