From 5a0afb2cf898a017b646488715a082dc15184087 Mon Sep 17 00:00:00 2001 From: dtammaro Date: Sat, 10 Mar 2018 12:14:43 +0100 Subject: [PATCH 1/4] DOC: update the pandas.DataFrame.apply docstring --- pandas/core/frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index a66d00fff9714..c665eacb3d748 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -4958,7 +4958,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 From 31628ecf731d9d192ac9e8333915549da3013e15 Mon Sep 17 00:00:00 2001 From: dtammaro Date: Sat, 10 Mar 2018 12:32:35 +0100 Subject: [PATCH 2/4] DOC: update pandas.DataFrame.apply docstring --- pandas/core/frame.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index c665eacb3d748..baa7d3057f92e 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -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. Objects passed to functions are Series objects having index either the DataFrame's index (axis=0) or the columns (axis=1). @@ -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 * 0 or 'index': apply function to each column - * 1 or 'columns': apply function to each row + * 1 or 'columns': apply function to each row. broadcast : boolean, optional For aggregation functions, return object of same size with values propagated @@ -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 @@ -4872,12 +4874,14 @@ 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 + Additional keyword arguments will be passed as keywords to the function. Notes ----- @@ -4941,6 +4945,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 From a5f37c71e261be17a151bb3ebd946bf9c6f81175 Mon Sep 17 00:00:00 2001 From: dtammaro Date: Sat, 10 Mar 2018 12:50:16 +0100 Subject: [PATCH 3/4] DOC: update the pandas.DataFrame.apply docstring --- pandas/core/frame.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index baa7d3057f92e..fabb25391b85c 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -4819,7 +4819,7 @@ 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): """ - Apply function along an axis of the DataFrame. + Apply function along an axis of the DataFrame. Objects passed to functions are Series objects having index either the DataFrame's index (axis=0) or the columns (axis=1). @@ -4831,7 +4831,7 @@ def apply(self, func, axis=0, broadcast=None, raw=False, reduce=None, func : function Function to apply to each column/row. axis : {0 or 'index', 1 or 'columns'}, default 0 - Axis along which the function is applied + Axis along which the function is applied * 0 or 'index': apply function to each column * 1 or 'columns': apply function to each row. broadcast : boolean, optional @@ -4880,8 +4880,9 @@ def apply(self, func, axis=0, broadcast=None, raw=False, reduce=None, Positional arguments to pass to function in addition to the array/series. - kwds : dictionary - Additional keyword arguments will be passed as keywords to the function. + kwds : dictionary + Additional keyword arguments will be passed as keywords to + the function. Notes ----- @@ -4945,7 +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 + dtype: object Passing result_type='expand' will expand list-like results to columns of a Dataframe From 2e4d7ee3c57942abb769f3abc46e9f2817b18c76 Mon Sep 17 00:00:00 2001 From: dtammaro Date: Sat, 10 Mar 2018 14:15:47 +0100 Subject: [PATCH 4/4] DOC: update the pandas.DataFrame.apply docstring --- pandas/core/frame.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index fabb25391b85c..c81bb21639085 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -4819,7 +4819,7 @@ 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): """ - Apply function along an axis of the DataFrame. + Apply a function along an axis of the DataFrame. Objects passed to functions are Series objects having index either the DataFrame's index (axis=0) or the columns (axis=1). @@ -4831,8 +4831,8 @@ def apply(self, func, axis=0, broadcast=None, raw=False, reduce=None, func : function Function to apply to each column/row. axis : {0 or 'index', 1 or 'columns'}, default 0 - Axis along which the function is applied - * 0 or 'index': apply function to each column + Axis along which the function is applied. + * 0 or 'index': apply function to each column. * 1 or 'columns': apply function to each row. broadcast : boolean, optional For aggregation functions, return object of same size with values @@ -4880,7 +4880,7 @@ def apply(self, func, axis=0, broadcast=None, raw=False, reduce=None, Positional arguments to pass to function in addition to the array/series. - kwds : dictionary + kwds : Additional keyword arguments will be passed as keywords to the function.