Skip to content

DOC: Apply doc sprint #20111

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

Closed
wants to merge 4 commits into from
Closed
Changes from 3 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
22 changes: 14 additions & 8 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4818,7 +4818,8 @@ def aggregate(self, func, axis=0, *args, **kwargs):

def apply(self, func, axis=0, broadcast=None, raw=False, reduce=None,
result_type=None, args=(), **kwds):
"""Applies function along an axis of the DataFrame.
"""
Apply function along an axis of the DataFrame.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe "Apply a function along an axis of the DataFrame." (add "a" before "function").


Objects passed to functions are Series objects having index
either the DataFrame's index (axis=0) or the columns (axis=1).
Expand All @@ -4828,10 +4829,11 @@ def apply(self, func, axis=0, broadcast=None, raw=False, reduce=None,
Parameters
----------
func : function
Function to apply to each column/row
Function to apply to each column/row.
axis : {0 or 'index', 1 or 'columns'}, default 0
Axis along which the function is applied
Copy link
Contributor

Choose a reason for hiding this comment

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

This line can have end with a period.

* 0 or 'index': apply function to each column
* 1 or 'columns': apply function to each row
* 1 or 'columns': apply function to each row.
Copy link
Contributor

Choose a reason for hiding this comment

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

These bullets should both have periods, or not. I don't really have a preference, but probably best to add a period to both.

broadcast : boolean, optional
For aggregation functions, return object of same size with values
propagated
Expand All @@ -4844,7 +4846,7 @@ def apply(self, func, axis=0, broadcast=None, raw=False, reduce=None,
If False, convert each row or column into a Series. If raw=True the
passed function will receive ndarray objects instead. If you are
just applying a NumPy reduction function this will achieve much
better performance
better performance.
reduce : boolean or None, default None
Try to apply reduction procedures. If the DataFrame is empty,
apply will use reduce to determine whether the result should be a
Expand Down Expand Up @@ -4872,12 +4874,15 @@ def apply(self, func, axis=0, broadcast=None, raw=False, reduce=None,
of those. However if the apply function returns a Series these
are expanded to columns.

.. versionadded:: 0.23.0
.. versionadded:: 0.23.0.

args : tuple
Positional arguments to pass to function in addition to the
array/series
Additional keyword arguments will be passed as keywords to the function
array/series.

kwds : dictionary
Copy link
Contributor

Choose a reason for hiding this comment

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

@jorisvandenbossche remind me, what's the policy here? Just kwargs, with no type?

Copy link
Contributor

Choose a reason for hiding this comment

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

Though probably just kwds in this case.

Copy link
Member

Choose a reason for hiding this comment

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

**kwargs with no type

Additional keyword arguments will be passed as keywords to
the function.

Notes
-----
Expand Down Expand Up @@ -4941,6 +4946,7 @@ def apply(self, func, axis=0, broadcast=None, raw=False, reduce=None,
3 [1, 2]
4 [1, 2]
5 [1, 2]
dtype: object

Passing result_type='expand' will expand list-like results
to columns of a Dataframe
Expand All @@ -4958,7 +4964,7 @@ def apply(self, func, axis=0, broadcast=None, raw=False, reduce=None,
``result_type='expand'``. The resulting column names
will be the Series index.

>>> df.apply(lambda x: Series([1, 2], index=['foo', 'bar']), axis=1)
>>> df.apply(lambda x: pd.Series([1, 2], index=['foo', 'bar']), axis=1)
foo bar
0 1 2
1 1 2
Expand Down