Skip to content

Doc: Added docstring to Groupby mean #20910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 7, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1297,9 +1297,48 @@ def count(self):
@Appender(_doc_template)
def mean(self, *args, **kwargs):
"""
Compute mean of groups, excluding missing values
Compute mean of groups, excluding missing values.

For multiple groupings, the result index will be a MultiIndex
Returns
-------
pandas.Series or pandas.DataFrame

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
"""
nv.validate_groupby_func('mean', args, kwargs, ['numeric_only'])
try:
Expand Down