67
67
args_transpose = 'axes to permute (int or label for object)' ,
68
68
optional_by = """
69
69
by : str or list of str
70
- Name or list of names to sort by""" )
70
+ Name or list of names to sort by""" ,
71
+ agg_return_type = """Scalar or Series
72
+ Returns a scalar, if supplied a single argument and a Series
73
+ if supplied multiple arguments.""" ,
74
+ )
71
75
72
76
73
77
def _single_replace (self , to_replace , method , inplace , limit ):
@@ -4545,16 +4549,16 @@ def pipe(self, func, *args, **kwargs):
4545
4549
4546
4550
Parameters
4547
4551
----------
4548
- func : function, string , list of functions and/or strings or dict
4552
+ func : function, str , list or dict
4549
4553
Function to use for aggregating the data. If a function, must either
4550
4554
work when passed a %(klass)s or when passed to %(klass)s.apply.
4551
4555
4552
4556
Accepted combinations are:
4553
4557
4554
- - string function name
4555
4558
- function
4556
- - list of functions and/or function names
4557
- - dict of axis labels -> functions, function names or list of such
4559
+ - string function name
4560
+ - list of functions and/or function names, e.g. ``[np.sum, 'mean']``
4561
+ - dict of axis labels -> functions, function names or list of such.
4558
4562
%(axis)s
4559
4563
*args
4560
4564
Positional arguments to pass to `func`.
@@ -4563,7 +4567,11 @@ def pipe(self, func, *args, **kwargs):
4563
4567
4564
4568
Returns
4565
4569
-------
4566
- pandas.%(klass)s
4570
+ DataFrame, Series or scalar
4571
+ if DataFrame.agg is called with a single function, returns a Series
4572
+ if DataFrame.agg is called with several functions, returns a DataFrame
4573
+ if Series.agg is called with single function, returns a scalar
4574
+ if Series.agg is called with several functions, returns a Series
4567
4575
4568
4576
Notes
4569
4577
-----
@@ -4580,15 +4588,15 @@ def pipe(self, func, *args, **kwargs):
4580
4588
4581
4589
Parameters
4582
4590
----------
4583
- func : function, string , list of functions and/or strings or dict
4591
+ func : function, str , list or dict
4584
4592
Function to use for transforming the data. If a function, must either
4585
4593
work when passed a %(klass)s or when passed to %(klass)s.apply.
4586
4594
4587
4595
Accepted combinations are:
4588
4596
4589
- - string function name
4590
4597
- function
4591
- - list of functions and/or function names
4598
+ - string function name
4599
+ - list of functions and/or function names, e.g. ``[np.exp. 'sqrt']``
4592
4600
- dict of axis labels -> functions, function names or list of such.
4593
4601
%(axis)s
4594
4602
*args
@@ -4598,31 +4606,41 @@ def pipe(self, func, *args, **kwargs):
4598
4606
4599
4607
Returns
4600
4608
-------
4601
- pandas. %(klass)s
4609
+ %(klass)s
4602
4610
A %(klass)s that must have the same length as self.
4603
4611
4604
4612
Raises
4605
4613
------
4606
- ValueError : if the returned %(klass)s has a different length than self.
4614
+ ValueError : If the returned %(klass)s has a different length than self.
4607
4615
4608
4616
See Also
4609
4617
--------
4610
- pandas. %(klass)s.agg : only perform aggregating type operations
4611
- pandas. %(klass)s.apply : Invoke function on a Series
4618
+ %(klass)s.agg : Only perform aggregating type operations.
4619
+ %(klass)s.apply : Invoke function on a Series.
4612
4620
4613
4621
Examples
4614
4622
--------
4615
4623
>>> df = pd.DataFrame({'A': range(3), 'B': range(1, 4)})
4624
+ >>> df
4625
+ A B
4626
+ 0 0 1
4627
+ 1 1 2
4628
+ 2 2 3
4616
4629
>>> df.transform(lambda x: x + 1)
4617
4630
A B
4618
4631
0 1 2
4619
4632
1 2 3
4620
4633
2 3 4
4621
4634
4622
- Even though the resulting %(klass)s must have the length as the input
4623
- %(klass)s, it is possible to provide several input functions:
4635
+ Even though the resulting %(klass)s must have the same length as the
4636
+ input %(klass)s, it is possible to provide several input functions:
4624
4637
4625
4638
>>> s = pd.Series(range(3))
4639
+ >>> s
4640
+ 0 0
4641
+ 1 1
4642
+ 2 2
4643
+ dtype: int64
4626
4644
>>> s.transform([np.sqrt, np.exp])
4627
4645
sqrt exp
4628
4646
0 0.000000 1.000000
0 commit comments