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 2 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
32 changes: 32 additions & 0 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1266,8 +1266,40 @@ def count(self):
def mean(self, *args, **kwargs):
"""
Compute mean of groups, excluding missing values

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be you can try adding long summary and Parameters as well, see https://python-sprints.github.io/pandas/guide/pandas_docstring.html

Example of groupby one column:
------------------------------
>>> df = pd.DataFrame({'A': [1, 1, 2, 1, 2],
'B': [np.nan, 2, 3, 4, 5]}, columns=['A', 'B'])
>>> g = df.groupby('A')['B'].mean()
>>> g
A
1 3.0
2 4.0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to put the Example at the end, see https://python-sprints.github.io/pandas/guide/pandas_docstring.html


For multiple groupings, the result index will be a MultiIndex

Example of groupby multiple columns:
------------------------------------
>>> 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'])
>>> g = df.groupby(['A', 'C'])['B'].mean()
>>> g
A C
1 1 4.0
2 2.0
2 1 3.0
2 5.0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to put the Example at the end, see https://python-sprints.github.io/pandas/guide/pandas_docstring.html


Returns
-------
pandas.core.series.Series
The average of the target column ('B' in the examples above) grouped by the groupby columns ('A' and ['A', 'C']
in the examples above)

"""
nv.validate_groupby_func('mean', args, kwargs, ['numeric_only'])
try:
Expand Down