Skip to content

DOC: update the GroupBy.apply docstring #20098

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 11 commits into from
Jul 21, 2018
16 changes: 9 additions & 7 deletions pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,11 @@
func : function
A callable that takes a {input} as its first argument, and
returns a dataframe, a series or a scalar. In addition the
callable may take positional and keyword arguments
args, kwargs : tuple and dict
Optional positional and keyword arguments to pass to ``func``
callable may take positional and keyword arguments.
args : tuple
Copy link
Member

Choose a reason for hiding this comment

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

Can you make this *args ? (and you can leave out the 'tuple')

Optional positional and keyword arguments to pass to ``func``.
Copy link
Member

Choose a reason for hiding this comment

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

This are only the positional ones, and below the keyword ones.

I think it would also be a good idea to add an example of this in the Examples section

kwargs : dict
Copy link
Member

Choose a reason for hiding this comment

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

Here the same **kwargs (and without dict)

Optional positional and keyword arguments to pass to ``func``.

Returns
-------
Expand All @@ -118,12 +120,12 @@
Examples
--------
{examples}

See also
--------
Copy link
Contributor

Choose a reason for hiding this comment

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

can you reference Series/DataFrame.apply as well

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add these to the See Also?

pipe : Apply function to the full GroupBy object instead of to each
group.
aggregate, transform
aggregate : Apply aggregate function to the GroupBy object.
transform : Apply function column-by-column to the GroupBy object.
""",
dataframe_examples="""
>>> df = pd.DataFrame({'A': 'a a b'.split(), 'B': [1,2,3], 'C': [4,6, 5]})
Expand All @@ -136,7 +138,7 @@
its argument and returns a dataframe. ``apply`` combines the result for
each group together into a new dataframe:

>>> g.apply(lambda x: x / x.sum())
>>> g[['B','C']].apply(lambda x: x / x.sum())
B C
0 0.333333 0.4
1 0.666667 0.6
Expand All @@ -146,7 +148,7 @@
its argument and returns a series. ``apply`` combines the result for
each group together into a new dataframe:

>>> g.apply(lambda x: x.max() - x.min())
>>> g[['B','C']].apply(lambda x: x.max() - x.min())
B C
A
a 1 2
Expand Down