-
-
Notifications
You must be signed in to change notification settings - Fork 19.1k
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
Changes from 5 commits
b44c618
f339b2c
29756b7
e71fbce
e709f31
31084a3
96bda06
1eeedd7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1265,9 +1265,40 @@ def count(self): | |
@Appender(_doc_template) | ||
def mean(self, *args, **kwargs): | ||
""" | ||
Compute mean of groups, excluding missing values | ||
Compute mean of the target column for groups that are defined by the groupby columns. | ||
Missing values are excluded in computing the mean. | ||
If there is one groupby column, the groups are the unique values in the specified groupby column. | ||
If there are multiple groupby columns, the groups are the unique combinations of the specified groupby columns. | ||
|
||
Returns | ||
------- | ||
pandas.core.series.Series | ||
The average of the target column ('B' in the examples below) | ||
grouped by the groupby columns ('A' and ['A', 'C'] in the examples below) | ||
|
||
Example of groupby one column:the groups are stored as index in the result. | ||
|
||
--------------------------------------------------------------------------- | ||
>>> 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 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
Example of groupby multiple columns: the result index will be a MultiIndex. | ||
--------------------------------------------------------------------------- | ||
>>> 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 | ||
|
||
|
||
For multiple groupings, the result index will be a MultiIndex | ||
""" | ||
nv.validate_groupby_func('mean', args, kwargs, ['numeric_only']) | ||
try: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blank line here for the Extended Summary