GroupBy

GroupBy objects are returned by groupby calls: DataFrame.groupby(), Series.groupby(), etc.

Indexing, iteration

GroupBy.get_group(name)

Construct DataFrame from group with provided name.

Function application

GroupBy.apply(func, *args, **kwargs)

Apply function func group-wise and combine the results together.

GroupBy.transform(func, *args, **kwargs)

Apply function column-by-column to the GroupBy object.

The following methods are available only for DataFrameGroupBy objects.

DataFrameGroupBy.agg([func_or_funcs])

Aggregate using one or more operations over the specified axis.

DataFrameGroupBy.aggregate([func_or_funcs])

Aggregate using one or more operations over the specified axis.

Computations / Descriptive Stats

GroupBy.all([skipna])

Returns True if all values in the group are truthful, else False.

GroupBy.any()

Returns True if any value in the group is truthful, else False.

GroupBy.count()

Compute count of group, excluding missing values.

GroupBy.cumcount([ascending])

Number each item in each group from 0 to the length of that group - 1.

GroupBy.cummax()

Cumulative max for each group.

GroupBy.cummin()

Cumulative min for each group.

GroupBy.cumprod()

Cumulative product for each group.

GroupBy.cumsum()

Cumulative sum for each group.

GroupBy.ewm([com, span, halflife, alpha, …])

Return an ewm grouper, providing ewm functionality per group.

GroupBy.filter(func)

Return a copy of a DataFrame excluding elements from groups that do not satisfy the boolean criterion specified by func.

GroupBy.first([numeric_only])

Compute first of group values.

GroupBy.last([numeric_only])

Compute last of group values.

GroupBy.max([numeric_only])

Compute max of group values.

GroupBy.mean([numeric_only])

Compute mean of groups, excluding missing values.

GroupBy.median([numeric_only, accuracy])

Compute median of groups, excluding missing values.

GroupBy.min([numeric_only])

Compute min of group values.

GroupBy.rank([method, ascending])

Provide the rank of values within each group.

GroupBy.std([ddof])

Compute standard deviation of groups, excluding missing values.

GroupBy.sum()

Compute sum of group values

GroupBy.var([ddof])

Compute variance of groups, excluding missing values.

GroupBy.nunique([dropna])

Return DataFrame with number of distinct observations per group for each column.

GroupBy.size()

Compute group sizes.

GroupBy.diff([periods])

First discrete difference of element.

GroupBy.idxmax([skipna])

Return index of first occurrence of maximum over requested axis in group.

GroupBy.idxmin([skipna])

Return index of first occurrence of minimum over requested axis in group.

GroupBy.fillna([value, method, axis, …])

Fill NA/NaN values in group.

GroupBy.bfill([limit])

Synonym for DataFrame.fillna() with method=`bfill`.

GroupBy.ffill([limit])

Synonym for DataFrame.fillna() with method=`ffill`.

GroupBy.head([n])

Return first n rows of each group.

GroupBy.backfill([limit])

Synonym for DataFrame.fillna() with method=`bfill`.

GroupBy.shift([periods, fill_value])

Shift each group by periods observations.

GroupBy.tail([n])

Return last n rows of each group.

The following methods are available only for DataFrameGroupBy objects.

DataFrameGroupBy.describe()

Generate descriptive statistics that summarize the central tendency, dispersion and shape of a dataset’s distribution, excluding NaN values.

The following methods are available only for SeriesGroupBy objects.

SeriesGroupBy.nsmallest([n])

Return the smallest n elements.

SeriesGroupBy.nlargest([n])

Return the first n rows ordered by columns in descending order in group.

SeriesGroupBy.value_counts([sort, …])

Compute group sizes.

SeriesGroupBy.unique()

Return unique values in group.