@@ -9905,16 +9905,16 @@ def _add_numeric_operations(cls):
9905
9905
9906
9906
cls .any = _make_logical_function (
9907
9907
cls , 'any' , name , name2 , axis_descr , _any_desc , nanops .nanany ,
9908
- _any_examples , _any_see_also , empty_value = False )
9908
+ _any_see_also , _any_examples , empty_value = False )
9909
9909
cls .all = _make_logical_function (
9910
9910
cls , 'all' , name , name2 , axis_descr , _all_desc , nanops .nanall ,
9911
- _all_examples , _all_see_also , empty_value = True )
9911
+ _all_see_also , _all_examples , empty_value = True )
9912
9912
9913
9913
@Substitution (outname = 'mad' ,
9914
9914
desc = "Return the mean absolute deviation of the values "
9915
9915
"for the requested axis." ,
9916
9916
name1 = name , name2 = name2 , axis_descr = axis_descr ,
9917
- min_count = '' , examples = '' )
9917
+ min_count = '' , see_also = '' , examples = '' )
9918
9918
@Appender (_num_doc )
9919
9919
def mad (self , axis = None , skipna = None , level = None ):
9920
9920
if skipna is None :
@@ -9956,7 +9956,7 @@ def mad(self, axis=None, skipna=None, level=None):
9956
9956
desc = "Return the compound percentage of the values for "
9957
9957
"the requested axis." , name1 = name , name2 = name2 ,
9958
9958
axis_descr = axis_descr ,
9959
- min_count = '' , examples = '' )
9959
+ min_count = '' , see_also = '' , examples = '' )
9960
9960
@Appender (_num_doc )
9961
9961
def compound (self , axis = None , skipna = None , level = None ):
9962
9962
if skipna is None :
@@ -9984,8 +9984,9 @@ def compound(self, axis=None, skipna=None, level=None):
9984
9984
9985
9985
cls .sum = _make_min_count_stat_function (
9986
9986
cls , 'sum' , name , name2 , axis_descr ,
9987
- 'Return the sum of the values for the requested axis.' ,
9988
- nanops .nansum , _sum_examples )
9987
+ """Return the sum of the values for the requested axis.\n
9988
+ This is equivalent to the method ``numpy.sum``.""" ,
9989
+ nanops .nansum , _stat_func_see_also , _sum_examples )
9989
9990
cls .mean = _make_stat_function (
9990
9991
cls , 'mean' , name , name2 , axis_descr ,
9991
9992
'Return the mean of the values for the requested axis.' ,
@@ -10004,24 +10005,24 @@ def compound(self, axis=None, skipna=None, level=None):
10004
10005
cls .prod = _make_min_count_stat_function (
10005
10006
cls , 'prod' , name , name2 , axis_descr ,
10006
10007
'Return the product of the values for the requested axis.' ,
10007
- nanops .nanprod , _prod_examples )
10008
+ nanops .nanprod , examples = _prod_examples )
10008
10009
cls .product = cls .prod
10009
10010
cls .median = _make_stat_function (
10010
10011
cls , 'median' , name , name2 , axis_descr ,
10011
10012
'Return the median of the values for the requested axis.' ,
10012
10013
nanops .nanmedian )
10013
10014
cls .max = _make_stat_function (
10014
10015
cls , 'max' , name , name2 , axis_descr ,
10015
- """This method returns the maximum of the values in the object.
10016
+ """Return the maximum of the values for the requested axis. \n
10016
10017
If you want the *index* of the maximum, use ``idxmax``. This is
10017
10018
the equivalent of the ``numpy.ndarray`` method ``argmax``.""" ,
10018
- nanops .nanmax , _max_examples )
10019
+ nanops .nanmax , _stat_func_see_also , _max_examples )
10019
10020
cls .min = _make_stat_function (
10020
10021
cls , 'min' , name , name2 , axis_descr ,
10021
- """This method returns the minimum of the values in the object.
10022
+ """Return the minimum of the values for the requested axis. \n
10022
10023
If you want the *index* of the minimum, use ``idxmin``. This is
10023
10024
the equivalent of the ``numpy.ndarray`` method ``argmin``.""" ,
10024
- nanops .nanmin )
10025
+ nanops .nanmin , _stat_func_see_also , _min_examples )
10025
10026
10026
10027
@classmethod
10027
10028
def _add_series_only_operations (cls ):
@@ -10174,21 +10175,25 @@ def _doc_parms(cls):
10174
10175
Parameters
10175
10176
----------
10176
10177
axis : %(axis_descr)s
10177
- skipna : boolean, default True
10178
+ Axis for the function to be applied on.
10179
+ skipna : bool, default True
10178
10180
Exclude NA/null values when computing the result.
10179
10181
level : int or level name, default None
10180
10182
If the axis is a MultiIndex (hierarchical), count along a
10181
- particular level, collapsing into a %(name1)s
10182
- numeric_only : boolean , default None
10183
+ particular level, collapsing into a %(name1)s.
10184
+ numeric_only : bool , default None
10183
10185
Include only float, int, boolean columns. If None, will attempt to use
10184
10186
everything, then use only numeric data. Not implemented for Series.
10185
10187
%(min_count)s\
10188
+ **kwargs
10189
+ Additional keyword arguments to be passed to the function.
10186
10190
10187
10191
Returns
10188
10192
-------
10189
- %(outname)s : %(name1)s or %(name2)s (if level specified)\
10190
-
10191
- %(examples)s"""
10193
+ %(outname)s : %(name1)s or %(name2)s (if level specified)
10194
+ %(see_also)s
10195
+ %(examples)s\
10196
+ """
10192
10197
10193
10198
_num_ddof_doc = """
10194
10199
%(desc)s
@@ -10692,43 +10697,49 @@ def _doc_parms(cls):
10692
10697
Series([], dtype: bool)
10693
10698
"""
10694
10699
10695
- _sum_examples = """\
10700
+ _shared_docs [ 'stat_func_example' ] = """\
10696
10701
Examples
10697
10702
--------
10698
- ``MultiIndex`` series example of monthly rainfall
10699
10703
10700
- >>> index = pd.MultiIndex.from_product(
10701
- ... [['London', 'New York'], ['Jun', 'Jul', 'Aug']],
10702
- ... names=['city', 'month'])
10703
- >>> s = pd.Series([47, 35, 54, 112, 117, 113], index=index)
10704
+ >>> idx = pd.MultiIndex.from_arrays([
10705
+ ... ['warm', 'warm', 'cold', 'cold'],
10706
+ ... ['dog', 'falcon', 'fish', 'spider']],
10707
+ ... names=['blooded', 'animal'])
10708
+ >>> s = pd.Series([4, 2, 0, 8], name='legs', index=idx)
10704
10709
>>> s
10705
- city month
10706
- London Jun 47
10707
- Jul 35
10708
- Aug 54
10709
- New York Jun 112
10710
- Jul 117
10711
- Aug 113
10712
- dtype: int64
10713
-
10714
- >>> s.sum()
10715
- 478
10716
-
10717
- Sum using level names, as well as indices
10718
-
10719
- >>> s.sum(level='city')
10720
- city
10721
- London 136
10722
- New York 342
10723
- dtype: int64
10724
-
10725
- >>> s.sum(level=1)
10726
- month
10727
- Jun 159
10728
- Jul 152
10729
- Aug 167
10730
- dtype: int64
10710
+ blooded animal
10711
+ warm dog 4
10712
+ falcon 2
10713
+ cold fish 0
10714
+ spider 8
10715
+ Name: legs, dtype: int64
10716
+
10717
+ >>> s.{stat_func}()
10718
+ {default_output}
10719
+
10720
+ {verb} using level names, as well as indices.
10721
+
10722
+ >>> s.{stat_func}(level='blooded')
10723
+ blooded
10724
+ warm {level_output_0}
10725
+ cold {level_output_1}
10726
+ Name: legs, dtype: int64
10727
+
10728
+ >>> s.{stat_func}(level=0)
10729
+ blooded
10730
+ warm {level_output_0}
10731
+ cold {level_output_1}
10732
+ Name: legs, dtype: int64
10733
+ """
10734
+
10735
+ _sum_examples = _shared_docs ['stat_func_example' ].format (
10736
+ stat_func = 'sum' ,
10737
+ verb = 'Sum' ,
10738
+ default_output = 14 ,
10739
+ level_output_0 = 6 ,
10740
+ level_output_1 = 8 )
10731
10741
10742
+ _sum_examples += """
10732
10743
By default, the sum of an empty or all-NA Series is ``0``.
10733
10744
10734
10745
>>> pd.Series([]).sum() # min_count=0 is the default
@@ -10750,6 +10761,35 @@ def _doc_parms(cls):
10750
10761
nan
10751
10762
"""
10752
10763
10764
+ _max_examples = _shared_docs ['stat_func_example' ].format (
10765
+ stat_func = 'max' ,
10766
+ verb = 'Max' ,
10767
+ default_output = 8 ,
10768
+ level_output_0 = 4 ,
10769
+ level_output_1 = 8 )
10770
+
10771
+ _min_examples = _shared_docs ['stat_func_example' ].format (
10772
+ stat_func = 'min' ,
10773
+ verb = 'Min' ,
10774
+ default_output = 0 ,
10775
+ level_output_0 = 2 ,
10776
+ level_output_1 = 0 )
10777
+
10778
+ _stat_func_see_also = """
10779
+ See Also
10780
+ --------
10781
+ Series.sum : Return the sum.
10782
+ Series.min : Return the minimum.
10783
+ Series.max : Return the maximum.
10784
+ Series.idxmin : Return the index of the minimum.
10785
+ Series.idxmax : Return the index of the maximum.
10786
+ DataFrame.min : Return the sum over the requested axis.
10787
+ DataFrame.min : Return the minimum over the requested axis.
10788
+ DataFrame.max : Return the maximum over the requested axis.
10789
+ DataFrame.idxmin : Return the index of the minimum over the requested axis.
10790
+ DataFrame.idxmax : Return the index of the maximum over the requested axis.
10791
+ """
10792
+
10753
10793
_prod_examples = """\
10754
10794
Examples
10755
10795
--------
@@ -10773,45 +10813,6 @@ def _doc_parms(cls):
10773
10813
nan
10774
10814
"""
10775
10815
10776
- _max_examples = """\
10777
- Examples
10778
- --------
10779
- ``MultiIndex`` series example of monthly rainfall
10780
-
10781
- >>> index = pd.MultiIndex.from_product(
10782
- ... [['London', 'New York'], ['Jun', 'Jul', 'Aug']],
10783
- ... names=['city', 'month'])
10784
- >>> s = pd.Series([47, 35, 54, 112, 117, 113], index=index)
10785
- >>> s
10786
- city month
10787
- London Jun 47
10788
- Jul 35
10789
- Aug 54
10790
- New York Jun 112
10791
- Jul 117
10792
- Aug 113
10793
- dtype: int64
10794
-
10795
- >>> s.max()
10796
- 117
10797
-
10798
- Max using level names, as well as indices
10799
-
10800
- >>> s.max(level='city')
10801
- city
10802
- London 54
10803
- New York 117
10804
- dtype: int64
10805
-
10806
- >>> s.max(level=1)
10807
- month
10808
- Jun 112
10809
- Jul 117
10810
- Aug 113
10811
- dtype: int64
10812
- """
10813
-
10814
-
10815
10816
_min_count_stub = """\
10816
10817
min_count : int, default 0
10817
10818
The required number of valid values to perform the operation. If fewer than
@@ -10826,10 +10827,10 @@ def _doc_parms(cls):
10826
10827
10827
10828
10828
10829
def _make_min_count_stat_function (cls , name , name1 , name2 , axis_descr , desc ,
10829
- f , examples ):
10830
+ f , see_also = '' , examples = '' ):
10830
10831
@Substitution (outname = name , desc = desc , name1 = name1 , name2 = name2 ,
10831
10832
axis_descr = axis_descr , min_count = _min_count_stub ,
10832
- examples = examples )
10833
+ see_also = see_also , examples = examples )
10833
10834
@Appender (_num_doc )
10834
10835
def stat_func (self , axis = None , skipna = None , level = None , numeric_only = None ,
10835
10836
min_count = 0 ,
@@ -10854,9 +10855,10 @@ def stat_func(self, axis=None, skipna=None, level=None, numeric_only=None,
10854
10855
10855
10856
10856
10857
def _make_stat_function (cls , name , name1 , name2 , axis_descr , desc , f ,
10857
- examples = '' ):
10858
+ see_also = '' , examples = '' ):
10858
10859
@Substitution (outname = name , desc = desc , name1 = name1 , name2 = name2 ,
10859
- axis_descr = axis_descr , min_count = '' , examples = examples )
10860
+ axis_descr = axis_descr , min_count = '' , see_also = see_also ,
10861
+ examples = examples )
10860
10862
@Appender (_num_doc )
10861
10863
def stat_func (self , axis = None , skipna = None , level = None , numeric_only = None ,
10862
10864
** kwargs ):
@@ -10933,9 +10935,9 @@ def cum_func(self, axis=None, skipna=True, *args, **kwargs):
10933
10935
10934
10936
10935
10937
def _make_logical_function (cls , name , name1 , name2 , axis_descr , desc , f ,
10936
- examples , see_also , empty_value ):
10938
+ see_also , examples , empty_value ):
10937
10939
@Substitution (outname = name , desc = desc , name1 = name1 , name2 = name2 ,
10938
- axis_descr = axis_descr , examples = examples , see_also = see_also ,
10940
+ axis_descr = axis_descr , see_also = see_also , examples = examples ,
10939
10941
empty_value = empty_value )
10940
10942
@Appender (_bool_doc )
10941
10943
def logical_func (self , axis = 0 , bool_only = None , skipna = True , level = None ,
0 commit comments