@@ -4545,17 +4545,16 @@ def pipe(self, func, *args, **kwargs):
45454545
45464546 Parameters
45474547 ----------
4548- func : function, string, dictionary, or list of string/functions
4548+ func : function, str, list or dict
45494549 Function to use for aggregating the data. If a function, must either
4550- work when passed a %(klass)s or when passed to %(klass)s.apply. For
4551- a DataFrame, can pass a dict, if the keys are DataFrame column names.
4550+ work when passed a %(klass)s or when passed to %(klass)s.apply.
45524551
45534552 Accepted combinations are:
45544553
4555- - string function name.
4556- - function.
4557- - list of functions.
4558- - dict of column names -> functions ( or list of functions) .
4554+ - function
4555+ - string function name
4556+ - list of functions and/or function names, e.g. ``[np.sum, 'mean']``
4557+ - dict of axis labels -> functions, function names or list of such .
45594558 %(axis)s
45604559 *args
45614560 Positional arguments to pass to `func`.
@@ -4564,7 +4563,11 @@ def pipe(self, func, *args, **kwargs):
45644563
45654564 Returns
45664565 -------
4567- aggregated : %(klass)s
4566+ DataFrame, Series or scalar
4567+ if DataFrame.agg is called with a single function, returns a Series
4568+ if DataFrame.agg is called with several functions, returns a DataFrame
4569+ if Series.agg is called with single function, returns a scalar
4570+ if Series.agg is called with several functions, returns a Series
45684571
45694572 Notes
45704573 -----
@@ -4574,50 +4577,71 @@ def pipe(self, func, *args, **kwargs):
45744577 """ )
45754578
45764579 _shared_docs ['transform' ] = ("""
4577- Call function producing a like-indexed %(klass)s
4578- and return a %(klass)s with the transformed values
4580+ Call ``func`` on self producing a %(klass)s with transformed values
4581+ and that has the same axis length as self.
45794582
45804583 .. versionadded:: 0.20.0
45814584
45824585 Parameters
45834586 ----------
4584- func : callable, string, dictionary, or list of string/callables
4585- To apply to column
4587+ func : function, str, list or dict
4588+ Function to use for transforming the data. If a function, must either
4589+ work when passed a %(klass)s or when passed to %(klass)s.apply.
45864590
4587- Accepted Combinations are:
4591+ Accepted combinations are:
45884592
4589- - string function name
45904593 - function
4591- - list of functions
4592- - dict of column names -> functions (or list of functions)
4594+ - string function name
4595+ - list of functions and/or function names, e.g. ``[np.exp. 'sqrt']``
4596+ - dict of axis labels -> functions, function names or list of such.
4597+ %(axis)s
4598+ *args
4599+ Positional arguments to pass to `func`.
4600+ **kwargs
4601+ Keyword arguments to pass to `func`.
45934602
45944603 Returns
45954604 -------
4596- transformed : %(klass)s
4605+ %(klass)s
4606+ A %(klass)s that must have the same length as self.
45974607
4598- Examples
4608+ Raises
4609+ ------
4610+ ValueError : If the returned %(klass)s has a different length than self.
4611+
4612+ See Also
45994613 --------
4600- >>> df = pd.DataFrame(np.random.randn(10, 3), columns=['A', 'B', 'C'],
4601- ... index=pd.date_range('1/1/2000', periods=10))
4602- df.iloc[3:7] = np.nan
4603-
4604- >>> df.transform(lambda x: (x - x.mean()) / x.std())
4605- A B C
4606- 2000-01-01 0.579457 1.236184 0.123424
4607- 2000-01-02 0.370357 -0.605875 -1.231325
4608- 2000-01-03 1.455756 -0.277446 0.288967
4609- 2000-01-04 NaN NaN NaN
4610- 2000-01-05 NaN NaN NaN
4611- 2000-01-06 NaN NaN NaN
4612- 2000-01-07 NaN NaN NaN
4613- 2000-01-08 -0.498658 1.274522 1.642524
4614- 2000-01-09 -0.540524 -1.012676 -0.828968
4615- 2000-01-10 -1.366388 -0.614710 0.005378
4616-
4617- See also
4614+ %(klass)s.agg : Only perform aggregating type operations.
4615+ %(klass)s.apply : Invoke function on a %(klass)s.
4616+
4617+ Examples
46184618 --------
4619- pandas.%(klass)s.aggregate
4620- pandas.%(klass)s.apply
4619+ >>> df = pd.DataFrame({'A': range(3), 'B': range(1, 4)})
4620+ >>> df
4621+ A B
4622+ 0 0 1
4623+ 1 1 2
4624+ 2 2 3
4625+ >>> df.transform(lambda x: x + 1)
4626+ A B
4627+ 0 1 2
4628+ 1 2 3
4629+ 2 3 4
4630+
4631+ Even though the resulting %(klass)s must have the same length as the
4632+ input %(klass)s, it is possible to provide several input functions:
4633+
4634+ >>> s = pd.Series(range(3))
4635+ >>> s
4636+ 0 0
4637+ 1 1
4638+ 2 2
4639+ dtype: int64
4640+ >>> s.transform([np.sqrt, np.exp])
4641+ sqrt exp
4642+ 0 0.000000 1.000000
4643+ 1 1.000000 2.718282
4644+ 2 1.414214 7.389056
46214645 """ )
46224646
46234647 # ----------------------------------------------------------------------
@@ -9401,7 +9425,7 @@ def ewm(self, com=None, span=None, halflife=None, alpha=None,
94019425
94029426 cls .ewm = ewm
94039427
9404- @Appender (_shared_docs ['transform' ] % _shared_doc_kwargs )
9428+ @Appender (_shared_docs ['transform' ] % dict ( axis = "" , ** _shared_doc_kwargs ) )
94059429 def transform (self , func , * args , ** kwargs ):
94069430 result = self .agg (func , * args , ** kwargs )
94079431 if is_scalar (result ) or len (result ) != len (self ):
0 commit comments