On this page
pandas.core.groupby.GroupBy.mean
GroupBy.mean(*args, **kwargs)
[source]-
Compute mean of groups, excluding missing values.
Returns: - pandas.Series or pandas.DataFrame
See also
pandas.Series.
,pandas.DataFrame.
,pandas.Panel.
Examples
>>> df = pd.DataFrame({'A': [1, 1, 2, 1, 2], ... 'B': [np.nan, 2, 3, 4, 5], ... 'C': [1, 2, 1, 1, 2]}, columns=['A', 'B', 'C'])
Groupby one column and return the mean of the remaining columns in each group.
>>> df.groupby('A').mean() >>> B C A 1 3.0 1.333333 2 4.0 1.500000
Groupby two columns and return the mean of the remaining column.
>>> df.groupby(['A', 'B']).mean() >>> C A B 1 2.0 2 4.0 1 2 3.0 1 5.0 2
Groupby one column and return the mean of only particular column in the group.
>>> df.groupby('A')['B'].mean() >>> A 1 3.0 2 4.0 Name: B, dtype: float64
© 2008–2012, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/0.24.2/reference/api/pandas.core.groupby.GroupBy.mean.html