-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
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 2 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 |
---|---|---|
|
@@ -1266,8 +1266,40 @@ def count(self): | |
def mean(self, *args, **kwargs): | ||
""" | ||
Compute mean of groups, excluding missing values | ||
|
||
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 | ||
|
||
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 |
||
|
||
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 | ||
|
||
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 |
||
|
||
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: | ||
|
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.
May be you can try adding long summary and Parameters as well, see https://python-sprints.github.io/pandas/guide/pandas_docstring.html