@@ -7660,7 +7660,6 @@ def truncate(self, before=None, after=None, axis=None, copy=True):
7660
7660
5 e j
7661
7661
7662
7662
For Series, only rows can be truncated.
7663
-
7664
7663
>>> df['A'].truncate(before=2, after=4)
7665
7664
2 b
7666
7665
3 c
@@ -8487,19 +8486,21 @@ def compound(self, axis=None, skipna=None, level=None):
8487
8486
cls .compound = compound
8488
8487
8489
8488
cls .cummin = _make_cum_function (
8490
- cls , 'cummin' , name , name2 , axis_descr , "cumulative minimum" ,
8489
+ cls , 'cummin' , name , name2 , axis_descr , "minimum" ,
8491
8490
lambda y , axis : np .minimum .accumulate (y , axis ), "min" ,
8492
- np .inf , np .nan )
8491
+ np .inf , np .nan , _cummin_examples )
8493
8492
cls .cumsum = _make_cum_function (
8494
- cls , 'cumsum' , name , name2 , axis_descr , "cumulative sum" ,
8495
- lambda y , axis : y .cumsum (axis ), "sum" , 0. , np .nan )
8493
+ cls , 'cumsum' , name , name2 , axis_descr , "sum" ,
8494
+ lambda y , axis : y .cumsum (axis ), "sum" , 0. ,
8495
+ np .nan , _cumsum_examples )
8496
8496
cls .cumprod = _make_cum_function (
8497
- cls , 'cumprod' , name , name2 , axis_descr , "cumulative product" ,
8498
- lambda y , axis : y .cumprod (axis ), "prod" , 1. , np .nan )
8497
+ cls , 'cumprod' , name , name2 , axis_descr , "product" ,
8498
+ lambda y , axis : y .cumprod (axis ), "prod" , 1. ,
8499
+ np .nan , _cumprod_examples )
8499
8500
cls .cummax = _make_cum_function (
8500
- cls , 'cummax' , name , name2 , axis_descr , "cumulative max " ,
8501
+ cls , 'cummax' , name , name2 , axis_descr , "maximum " ,
8501
8502
lambda y , axis : np .maximum .accumulate (y , axis ), "max" ,
8502
- - np .inf , np .nan )
8503
+ - np .inf , np .nan , _cummax_examples )
8503
8504
8504
8505
cls .sum = _make_min_count_stat_function (
8505
8506
cls , 'sum' , name , name2 , axis_descr ,
@@ -8702,8 +8703,8 @@ def _doc_parms(cls):
8702
8703
Include only boolean columns. If None, will attempt to use everything,
8703
8704
then use only boolean data. Not implemented for Series.
8704
8705
**kwargs : any, default None
8705
- Additional keywords have no affect but might be accepted for
8706
- compatibility with numpy .
8706
+ Additional keywords have no effect but might be accepted for
8707
+ compatibility with NumPy .
8707
8708
8708
8709
Returns
8709
8710
-------
@@ -8761,24 +8762,296 @@ def _doc_parms(cls):
8761
8762
"""
8762
8763
8763
8764
_cnum_doc = """
8765
+ Return cumulative %(desc)s over a DataFrame or Series axis.
8766
+
8767
+ Returns a DataFrame or Series of the same size containing the cumulative
8768
+ %(desc)s.
8764
8769
8765
8770
Parameters
8766
8771
----------
8767
- axis : %(axis_descr)s
8772
+ axis : {0 or 'index', 1 or 'columns'}, default 0
8773
+ The index or the name of the axis. 0 is equivalent to None or 'index'.
8768
8774
skipna : boolean, default True
8769
8775
Exclude NA/null values. If an entire row/column is NA, the result
8770
- will be NA
8776
+ will be NA.
8777
+ *args, **kwargs :
8778
+ Additional keywords have no effect but might be accepted for
8779
+ compatibility with NumPy.
8771
8780
8772
8781
Returns
8773
8782
-------
8774
- %(outname)s : %(name1)s\n
8775
-
8776
-
8783
+ %(outname)s : %(name1)s or %(name2)s\n
8784
+ %(examples)s
8777
8785
See also
8778
8786
--------
8779
8787
pandas.core.window.Expanding.%(accum_func_name)s : Similar functionality
8780
8788
but ignores ``NaN`` values.
8789
+ %(name2)s.%(accum_func_name)s : Return the %(desc)s over
8790
+ %(name2)s axis.
8791
+ %(name2)s.cummax : Return cumulative maximum over %(name2)s axis.
8792
+ %(name2)s.cummin : Return cumulative minimum over %(name2)s axis.
8793
+ %(name2)s.cumsum : Return cumulative sum over %(name2)s axis.
8794
+ %(name2)s.cumprod : Return cumulative product over %(name2)s axis.
8795
+ """
8796
+
8797
+ _cummin_examples = """\
8798
+ Examples
8799
+ --------
8800
+ **Series**
8781
8801
8802
+ >>> s = pd.Series([2, np.nan, 5, -1, 0])
8803
+ >>> s
8804
+ 0 2.0
8805
+ 1 NaN
8806
+ 2 5.0
8807
+ 3 -1.0
8808
+ 4 0.0
8809
+ dtype: float64
8810
+
8811
+ By default, NA values are ignored.
8812
+
8813
+ >>> s.cummin()
8814
+ 0 2.0
8815
+ 1 NaN
8816
+ 2 2.0
8817
+ 3 -1.0
8818
+ 4 -1.0
8819
+ dtype: float64
8820
+
8821
+ To include NA values in the operation, use ``skipna=False``
8822
+
8823
+ >>> s.cummin(skipna=False)
8824
+ 0 2.0
8825
+ 1 NaN
8826
+ 2 NaN
8827
+ 3 NaN
8828
+ 4 NaN
8829
+ dtype: float64
8830
+
8831
+ **DataFrame**
8832
+
8833
+ >>> df = pd.DataFrame([[2.0, 1.0],
8834
+ ... [3.0, np.nan],
8835
+ ... [1.0, 0.0]],
8836
+ ... columns=list('AB'))
8837
+ >>> df
8838
+ A B
8839
+ 0 2.0 1.0
8840
+ 1 3.0 NaN
8841
+ 2 1.0 0.0
8842
+
8843
+ By default, iterates over rows and finds the minimum
8844
+ in each column. This is equivalent to ``axis=None`` or ``axis='index'``.
8845
+
8846
+ >>> df.cummin()
8847
+ A B
8848
+ 0 2.0 1.0
8849
+ 1 2.0 NaN
8850
+ 2 1.0 0.0
8851
+
8852
+ To iterate over columns and find the minimum in each row,
8853
+ use ``axis=1``
8854
+
8855
+ >>> df.cummin(axis=1)
8856
+ A B
8857
+ 0 2.0 1.0
8858
+ 1 3.0 NaN
8859
+ 2 1.0 0.0
8860
+ """
8861
+
8862
+ _cumsum_examples = """\
8863
+ Examples
8864
+ --------
8865
+ **Series**
8866
+
8867
+ >>> s = pd.Series([2, np.nan, 5, -1, 0])
8868
+ >>> s
8869
+ 0 2.0
8870
+ 1 NaN
8871
+ 2 5.0
8872
+ 3 -1.0
8873
+ 4 0.0
8874
+ dtype: float64
8875
+
8876
+ By default, NA values are ignored.
8877
+
8878
+ >>> s.cumsum()
8879
+ 0 2.0
8880
+ 1 NaN
8881
+ 2 7.0
8882
+ 3 6.0
8883
+ 4 6.0
8884
+ dtype: float64
8885
+
8886
+ To include NA values in the operation, use ``skipna=False``
8887
+
8888
+ >>> s.cumsum(skipna=False)
8889
+ 0 2.0
8890
+ 1 NaN
8891
+ 2 NaN
8892
+ 3 NaN
8893
+ 4 NaN
8894
+ dtype: float64
8895
+
8896
+ **DataFrame**
8897
+
8898
+ >>> df = pd.DataFrame([[2.0, 1.0],
8899
+ ... [3.0, np.nan],
8900
+ ... [1.0, 0.0]],
8901
+ ... columns=list('AB'))
8902
+ >>> df
8903
+ A B
8904
+ 0 2.0 1.0
8905
+ 1 3.0 NaN
8906
+ 2 1.0 0.0
8907
+
8908
+ By default, iterates over rows and finds the sum
8909
+ in each column. This is equivalent to ``axis=None`` or ``axis='index'``.
8910
+
8911
+ >>> df.cumsum()
8912
+ A B
8913
+ 0 2.0 1.0
8914
+ 1 5.0 NaN
8915
+ 2 6.0 1.0
8916
+
8917
+ To iterate over columns and find the sum in each row,
8918
+ use ``axis=1``
8919
+
8920
+ >>> df.cumsum(axis=1)
8921
+ A B
8922
+ 0 2.0 3.0
8923
+ 1 3.0 NaN
8924
+ 2 1.0 1.0
8925
+ """
8926
+
8927
+ _cumprod_examples = """\
8928
+ Examples
8929
+ --------
8930
+ **Series**
8931
+
8932
+ >>> s = pd.Series([2, np.nan, 5, -1, 0])
8933
+ >>> s
8934
+ 0 2.0
8935
+ 1 NaN
8936
+ 2 5.0
8937
+ 3 -1.0
8938
+ 4 0.0
8939
+ dtype: float64
8940
+
8941
+ By default, NA values are ignored.
8942
+
8943
+ >>> s.cumprod()
8944
+ 0 2.0
8945
+ 1 NaN
8946
+ 2 10.0
8947
+ 3 -10.0
8948
+ 4 -0.0
8949
+ dtype: float64
8950
+
8951
+ To include NA values in the operation, use ``skipna=False``
8952
+
8953
+ >>> s.cumprod(skipna=False)
8954
+ 0 2.0
8955
+ 1 NaN
8956
+ 2 NaN
8957
+ 3 NaN
8958
+ 4 NaN
8959
+ dtype: float64
8960
+
8961
+ **DataFrame**
8962
+
8963
+ >>> df = pd.DataFrame([[2.0, 1.0],
8964
+ ... [3.0, np.nan],
8965
+ ... [1.0, 0.0]],
8966
+ ... columns=list('AB'))
8967
+ >>> df
8968
+ A B
8969
+ 0 2.0 1.0
8970
+ 1 3.0 NaN
8971
+ 2 1.0 0.0
8972
+
8973
+ By default, iterates over rows and finds the product
8974
+ in each column. This is equivalent to ``axis=None`` or ``axis='index'``.
8975
+
8976
+ >>> df.cumprod()
8977
+ A B
8978
+ 0 2.0 1.0
8979
+ 1 6.0 NaN
8980
+ 2 6.0 0.0
8981
+
8982
+ To iterate over columns and find the product in each row,
8983
+ use ``axis=1``
8984
+
8985
+ >>> df.cumprod(axis=1)
8986
+ A B
8987
+ 0 2.0 2.0
8988
+ 1 3.0 NaN
8989
+ 2 1.0 0.0
8990
+ """
8991
+
8992
+ _cummax_examples = """\
8993
+ Examples
8994
+ --------
8995
+ **Series**
8996
+
8997
+ >>> s = pd.Series([2, np.nan, 5, -1, 0])
8998
+ >>> s
8999
+ 0 2.0
9000
+ 1 NaN
9001
+ 2 5.0
9002
+ 3 -1.0
9003
+ 4 0.0
9004
+ dtype: float64
9005
+
9006
+ By default, NA values are ignored.
9007
+
9008
+ >>> s.cummax()
9009
+ 0 2.0
9010
+ 1 NaN
9011
+ 2 5.0
9012
+ 3 5.0
9013
+ 4 5.0
9014
+ dtype: float64
9015
+
9016
+ To include NA values in the operation, use ``skipna=False``
9017
+
9018
+ >>> s.cummax(skipna=False)
9019
+ 0 2.0
9020
+ 1 NaN
9021
+ 2 NaN
9022
+ 3 NaN
9023
+ 4 NaN
9024
+ dtype: float64
9025
+
9026
+ **DataFrame**
9027
+
9028
+ >>> df = pd.DataFrame([[2.0, 1.0],
9029
+ ... [3.0, np.nan],
9030
+ ... [1.0, 0.0]],
9031
+ ... columns=list('AB'))
9032
+ >>> df
9033
+ A B
9034
+ 0 2.0 1.0
9035
+ 1 3.0 NaN
9036
+ 2 1.0 0.0
9037
+
9038
+ By default, iterates over rows and finds the maximum
9039
+ in each column. This is equivalent to ``axis=None`` or ``axis='index'``.
9040
+
9041
+ >>> df.cummax()
9042
+ A B
9043
+ 0 2.0 1.0
9044
+ 1 3.0 NaN
9045
+ 2 3.0 1.0
9046
+
9047
+ To iterate over columns and find the maximum in each row,
9048
+ use ``axis=1``
9049
+
9050
+ >>> df.cummax(axis=1)
9051
+ A B
9052
+ 0 2.0 2.0
9053
+ 1 3.0 NaN
9054
+ 2 1.0 1.0
8782
9055
"""
8783
9056
8784
9057
_any_see_also = """\
@@ -8975,11 +9248,11 @@ def stat_func(self, axis=None, skipna=None, level=None, ddof=1,
8975
9248
8976
9249
8977
9250
def _make_cum_function (cls , name , name1 , name2 , axis_descr , desc ,
8978
- accum_func , accum_func_name , mask_a , mask_b ):
9251
+ accum_func , accum_func_name , mask_a , mask_b , examples ):
8979
9252
@Substitution (outname = name , desc = desc , name1 = name1 , name2 = name2 ,
8980
- axis_descr = axis_descr , accum_func_name = accum_func_name )
8981
- @ Appender ( "Return {0} over requested axis." . format ( desc ) +
8982
- _cnum_doc )
9253
+ axis_descr = axis_descr , accum_func_name = accum_func_name ,
9254
+ examples = examples )
9255
+ @ Appender ( _cnum_doc )
8983
9256
def cum_func (self , axis = None , skipna = True , * args , ** kwargs ):
8984
9257
skipna = nv .validate_cum_func_with_skipna (skipna , args , kwargs , name )
8985
9258
if axis is None :
0 commit comments