@@ -10378,6 +10378,7 @@ def apply(
10378
10378
----------
10379
10379
func : function
10380
10380
Function to apply to each column or row.
10381
+
10381
10382
axis : {0 or 'index', 1 or 'columns'}, default 0
10382
10383
Axis along which the function is applied:
10383
10384
@@ -10396,18 +10397,25 @@ def apply(
10396
10397
10397
10398
result_type : {'expand', 'reduce', 'broadcast', None}, default None
10398
10399
These only act when ``axis=1`` (columns):
10399
-
10400
+
10400
10401
* 'expand' : list-like results will be turned into columns.
10402
+ Note: The output type is inferred from the first function return value.
10403
+ If the first return value is not list-like (e.g., None or NaN), expansion
10404
+ will not occur, and the result may be a Series instead of a DataFrame.
10405
+ To avoid inconsistent output types, ensure your function returns consistent
10406
+ list-like objects (e.g., an empty dict {}) for missing or NaN-like values.
10407
+
10401
10408
* 'reduce' : returns a Series if possible rather than expanding
10402
10409
list-like results. This is the opposite of 'expand'.
10403
10410
* 'broadcast' : results will be broadcast to the original shape
10404
10411
of the DataFrame, the original index and columns will be
10405
10412
retained.
10406
-
10413
+
10407
10414
The default behaviour (None) depends on the return value of the
10408
10415
applied function: list-like results will be returned as a Series
10409
10416
of those. However if the apply function returns a Series these
10410
- are expanded to columns.
10417
+ are expanded to columns.
10418
+
10411
10419
args : tuple
10412
10420
Positional arguments to pass to `func` in addition to the
10413
10421
array/series.
0 commit comments