Skip to content

DOC: Add note on inference behavior of apply with result_type='expand' #61552

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all 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
9 changes: 9 additions & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -10378,6 +10378,7 @@ def apply(
----------
func : function
Function to apply to each column or row.

axis : {0 or 'index', 1 or 'columns'}, default 0
Axis along which the function is applied:

Expand All @@ -10398,6 +10399,13 @@ def apply(
These only act when ``axis=1`` (columns):

* 'expand' : list-like results will be turned into columns.
Note: The output type is inferred from the first function return value.
If the first return value is not list-like (e.g., None or NaN), expansion
will not occur, and the result may be a Series instead of a DataFrame.
To avoid inconsistent output types, ensure your function returns
consistent list-like objects (e.g., an empty dict {}) for missing or
NaN-like values.

* 'reduce' : returns a Series if possible rather than expanding
list-like results. This is the opposite of 'expand'.
* 'broadcast' : results will be broadcast to the original shape
Expand All @@ -10408,6 +10416,7 @@ def apply(
applied function: list-like results will be returned as a Series
of those. However if the apply function returns a Series these
are expanded to columns.

args : tuple
Positional arguments to pass to `func` in addition to the
array/series.
Expand Down
Loading