@@ -2028,7 +2028,7 @@ def all(self, skipna: bool = True):
2028
2028
2029
2029
@final
2030
2030
@Substitution (name = "groupby" )
2031
- @Appender ( _common_see_also )
2031
+ @Substitution ( see_also = _common_see_also )
2032
2032
def count (self ) -> NDFrameT :
2033
2033
"""
2034
2034
Compute count of group, excluding missing values.
@@ -2037,6 +2037,38 @@ def count(self) -> NDFrameT:
2037
2037
-------
2038
2038
Series or DataFrame
2039
2039
Count of values within each group.
2040
+ %(see_also)s
2041
+ Examples
2042
+ --------
2043
+ For SeriesGroupBy:
2044
+
2045
+ >>> lst = ['a', 'a', 'b']
2046
+ >>> ser = pd.Series([1, 2, np.nan], index=lst)
2047
+ >>> ser
2048
+ a 1.0
2049
+ a 2.0
2050
+ b NaN
2051
+ dtype: float64
2052
+ >>> ser.groupby(level=0).count()
2053
+ a 2
2054
+ b 0
2055
+ dtype: int64
2056
+
2057
+ For DataFrameGroupBy:
2058
+
2059
+ >>> data = [[1, np.nan, 3], [1, np.nan, 6], [7, 8, 9]]
2060
+ >>> df = pd.DataFrame(data, columns=["a", "b", "c"],
2061
+ ... index=["cow", "horse", "bull"])
2062
+ >>> df
2063
+ a b c
2064
+ cow 1 NaN 3
2065
+ horse 1 NaN 6
2066
+ bull 7 8.0 9
2067
+ >>> df.groupby("a").count()
2068
+ b c
2069
+ a
2070
+ 1 0 2
2071
+ 7 1 1
2040
2072
"""
2041
2073
data = self ._get_data_to_aggregate ()
2042
2074
ids , _ , ngroups = self .grouper .group_info
@@ -3890,7 +3922,7 @@ def rank(
3890
3922
3891
3923
@final
3892
3924
@Substitution (name = "groupby" )
3893
- @Appender ( _common_see_also )
3925
+ @Substitution ( see_also = _common_see_also )
3894
3926
def cumprod (
3895
3927
self , axis : Axis | lib .NoDefault = lib .no_default , * args , ** kwargs
3896
3928
) -> NDFrameT :
@@ -3900,6 +3932,41 @@ def cumprod(
3900
3932
Returns
3901
3933
-------
3902
3934
Series or DataFrame
3935
+ %(see_also)s
3936
+ Examples
3937
+ --------
3938
+ For SeriesGroupBy:
3939
+
3940
+ >>> lst = ['a', 'a', 'b']
3941
+ >>> ser = pd.Series([6, 2, 0], index=lst)
3942
+ >>> ser
3943
+ a 6
3944
+ a 2
3945
+ b 0
3946
+ dtype: int64
3947
+ >>> ser.groupby(level=0).cumprod()
3948
+ a 6
3949
+ a 12
3950
+ b 0
3951
+ dtype: int64
3952
+
3953
+ For DataFrameGroupBy:
3954
+
3955
+ >>> data = [[1, 8, 2], [1, 2, 5], [2, 6, 9]]
3956
+ >>> df = pd.DataFrame(data, columns=["a", "b", "c"],
3957
+ ... index=["cow", "horse", "bull"])
3958
+ >>> df
3959
+ a b c
3960
+ cow 1 8 2
3961
+ horse 1 2 5
3962
+ bull 2 6 9
3963
+ >>> df.groupby("a").groups
3964
+ {1: ['cow', 'horse'], 2: ['bull']}
3965
+ >>> df.groupby("a").cumprod()
3966
+ b c
3967
+ cow 8 2
3968
+ horse 16 10
3969
+ bull 6 9
3903
3970
"""
3904
3971
nv .validate_groupby_func ("cumprod" , args , kwargs , ["numeric_only" , "skipna" ])
3905
3972
if axis is not lib .no_default :
@@ -3916,7 +3983,7 @@ def cumprod(
3916
3983
3917
3984
@final
3918
3985
@Substitution (name = "groupby" )
3919
- @Appender ( _common_see_also )
3986
+ @Substitution ( see_also = _common_see_also )
3920
3987
def cumsum (
3921
3988
self , axis : Axis | lib .NoDefault = lib .no_default , * args , ** kwargs
3922
3989
) -> NDFrameT :
@@ -3926,6 +3993,41 @@ def cumsum(
3926
3993
Returns
3927
3994
-------
3928
3995
Series or DataFrame
3996
+ %(see_also)s
3997
+ Examples
3998
+ --------
3999
+ For SeriesGroupBy:
4000
+
4001
+ >>> lst = ['a', 'a', 'b']
4002
+ >>> ser = pd.Series([6, 2, 0], index=lst)
4003
+ >>> ser
4004
+ a 6
4005
+ a 2
4006
+ b 0
4007
+ dtype: int64
4008
+ >>> ser.groupby(level=0).cumsum()
4009
+ a 6
4010
+ a 8
4011
+ b 0
4012
+ dtype: int64
4013
+
4014
+ For DataFrameGroupBy:
4015
+
4016
+ >>> data = [[1, 8, 2], [1, 2, 5], [2, 6, 9]]
4017
+ >>> df = pd.DataFrame(data, columns=["a", "b", "c"],
4018
+ ... index=["fox", "gorilla", "lion"])
4019
+ >>> df
4020
+ a b c
4021
+ fox 1 8 2
4022
+ gorilla 1 2 5
4023
+ lion 2 6 9
4024
+ >>> df.groupby("a").groups
4025
+ {1: ['fox', 'gorilla'], 2: ['lion']}
4026
+ >>> df.groupby("a").cumsum()
4027
+ b c
4028
+ fox 8 2
4029
+ gorilla 10 7
4030
+ lion 6 9
3929
4031
"""
3930
4032
nv .validate_groupby_func ("cumsum" , args , kwargs , ["numeric_only" , "skipna" ])
3931
4033
if axis is not lib .no_default :
@@ -3942,7 +4044,7 @@ def cumsum(
3942
4044
3943
4045
@final
3944
4046
@Substitution (name = "groupby" )
3945
- @Appender ( _common_see_also )
4047
+ @Substitution ( see_also = _common_see_also )
3946
4048
def cummin (
3947
4049
self ,
3948
4050
axis : AxisInt | lib .NoDefault = lib .no_default ,
@@ -3955,6 +4057,47 @@ def cummin(
3955
4057
Returns
3956
4058
-------
3957
4059
Series or DataFrame
4060
+ %(see_also)s
4061
+ Examples
4062
+ --------
4063
+ For SeriesGroupBy:
4064
+
4065
+ >>> lst = ['a', 'a', 'a', 'b', 'b', 'b']
4066
+ >>> ser = pd.Series([1, 6, 2, 3, 0, 4], index=lst)
4067
+ >>> ser
4068
+ a 1
4069
+ a 6
4070
+ a 2
4071
+ b 3
4072
+ b 0
4073
+ b 4
4074
+ dtype: int64
4075
+ >>> ser.groupby(level=0).cummin()
4076
+ a 1
4077
+ a 1
4078
+ a 1
4079
+ b 3
4080
+ b 0
4081
+ b 0
4082
+ dtype: int64
4083
+
4084
+ For DataFrameGroupBy:
4085
+
4086
+ >>> data = [[1, 0, 2], [1, 1, 5], [6, 6, 9]]
4087
+ >>> df = pd.DataFrame(data, columns=["a", "b", "c"],
4088
+ ... index=["snake", "rabbit", "turtle"])
4089
+ >>> df
4090
+ a b c
4091
+ snake 1 0 2
4092
+ rabbit 1 1 5
4093
+ turtle 6 6 9
4094
+ >>> df.groupby("a").groups
4095
+ {1: ['snake', 'rabbit'], 6: ['turtle']}
4096
+ >>> df.groupby("a").cummin()
4097
+ b c
4098
+ snake 0 2
4099
+ rabbit 0 2
4100
+ turtle 6 9
3958
4101
"""
3959
4102
skipna = kwargs .get ("skipna" , True )
3960
4103
if axis is not lib .no_default :
@@ -3976,7 +4119,7 @@ def cummin(
3976
4119
3977
4120
@final
3978
4121
@Substitution (name = "groupby" )
3979
- @Appender ( _common_see_also )
4122
+ @Substitution ( see_also = _common_see_also )
3980
4123
def cummax (
3981
4124
self ,
3982
4125
axis : AxisInt | lib .NoDefault = lib .no_default ,
@@ -3989,6 +4132,47 @@ def cummax(
3989
4132
Returns
3990
4133
-------
3991
4134
Series or DataFrame
4135
+ %(see_also)s
4136
+ Examples
4137
+ --------
4138
+ For SeriesGroupBy:
4139
+
4140
+ >>> lst = ['a', 'a', 'a', 'b', 'b', 'b']
4141
+ >>> ser = pd.Series([1, 6, 2, 3, 1, 4], index=lst)
4142
+ >>> ser
4143
+ a 1
4144
+ a 6
4145
+ a 2
4146
+ b 3
4147
+ b 1
4148
+ b 4
4149
+ dtype: int64
4150
+ >>> ser.groupby(level=0).cummax()
4151
+ a 1
4152
+ a 6
4153
+ a 6
4154
+ b 3
4155
+ b 3
4156
+ b 4
4157
+ dtype: int64
4158
+
4159
+ For DataFrameGroupBy:
4160
+
4161
+ >>> data = [[1, 8, 2], [1, 1, 0], [2, 6, 9]]
4162
+ >>> df = pd.DataFrame(data, columns=["a", "b", "c"],
4163
+ ... index=["cow", "horse", "bull"])
4164
+ >>> df
4165
+ a b c
4166
+ cow 1 8 2
4167
+ horse 1 1 0
4168
+ bull 2 6 9
4169
+ >>> df.groupby("a").groups
4170
+ {1: ['cow', 'horse'], 2: ['bull']}
4171
+ >>> df.groupby("a").cummax()
4172
+ b c
4173
+ cow 8 2
4174
+ horse 8 2
4175
+ bull 6 9
3992
4176
"""
3993
4177
skipna = kwargs .get ("skipna" , True )
3994
4178
if axis is not lib .no_default :
0 commit comments