Skip to content

Commit ac08921

Browse files
DeaMariaLeonim-vinicius
authored and
im-vinicius
committed
DOC: Fixing EX01 - Added examples (pandas-dev#53554)
* Example for count * Added examples
1 parent ff053ed commit ac08921

File tree

2 files changed

+189
-15
lines changed

2 files changed

+189
-15
lines changed

ci/code_checks.sh

-10
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
263263
pandas.core.window.ewm.ExponentialMovingWindow.cov \
264264
pandas.api.indexers.BaseIndexer \
265265
pandas.api.indexers.VariableOffsetWindowIndexer \
266-
pandas.core.groupby.DataFrameGroupBy.count \
267-
pandas.core.groupby.DataFrameGroupBy.cummax \
268-
pandas.core.groupby.DataFrameGroupBy.cummin \
269-
pandas.core.groupby.DataFrameGroupBy.cumprod \
270-
pandas.core.groupby.DataFrameGroupBy.cumsum \
271266
pandas.core.groupby.DataFrameGroupBy.diff \
272267
pandas.core.groupby.DataFrameGroupBy.ffill \
273268
pandas.core.groupby.DataFrameGroupBy.max \
@@ -283,11 +278,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
283278
pandas.core.groupby.DataFrameGroupBy.std \
284279
pandas.core.groupby.DataFrameGroupBy.sum \
285280
pandas.core.groupby.DataFrameGroupBy.var \
286-
pandas.core.groupby.SeriesGroupBy.count \
287-
pandas.core.groupby.SeriesGroupBy.cummax \
288-
pandas.core.groupby.SeriesGroupBy.cummin \
289-
pandas.core.groupby.SeriesGroupBy.cumprod \
290-
pandas.core.groupby.SeriesGroupBy.cumsum \
291281
pandas.core.groupby.SeriesGroupBy.diff \
292282
pandas.core.groupby.SeriesGroupBy.ffill \
293283
pandas.core.groupby.SeriesGroupBy.max \

pandas/core/groupby/groupby.py

+189-5
Original file line numberDiff line numberDiff line change
@@ -2028,7 +2028,7 @@ def all(self, skipna: bool = True):
20282028

20292029
@final
20302030
@Substitution(name="groupby")
2031-
@Appender(_common_see_also)
2031+
@Substitution(see_also=_common_see_also)
20322032
def count(self) -> NDFrameT:
20332033
"""
20342034
Compute count of group, excluding missing values.
@@ -2037,6 +2037,38 @@ def count(self) -> NDFrameT:
20372037
-------
20382038
Series or DataFrame
20392039
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
20402072
"""
20412073
data = self._get_data_to_aggregate()
20422074
ids, _, ngroups = self.grouper.group_info
@@ -3890,7 +3922,7 @@ def rank(
38903922

38913923
@final
38923924
@Substitution(name="groupby")
3893-
@Appender(_common_see_also)
3925+
@Substitution(see_also=_common_see_also)
38943926
def cumprod(
38953927
self, axis: Axis | lib.NoDefault = lib.no_default, *args, **kwargs
38963928
) -> NDFrameT:
@@ -3900,6 +3932,41 @@ def cumprod(
39003932
Returns
39013933
-------
39023934
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
39033970
"""
39043971
nv.validate_groupby_func("cumprod", args, kwargs, ["numeric_only", "skipna"])
39053972
if axis is not lib.no_default:
@@ -3916,7 +3983,7 @@ def cumprod(
39163983

39173984
@final
39183985
@Substitution(name="groupby")
3919-
@Appender(_common_see_also)
3986+
@Substitution(see_also=_common_see_also)
39203987
def cumsum(
39213988
self, axis: Axis | lib.NoDefault = lib.no_default, *args, **kwargs
39223989
) -> NDFrameT:
@@ -3926,6 +3993,41 @@ def cumsum(
39263993
Returns
39273994
-------
39283995
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
39294031
"""
39304032
nv.validate_groupby_func("cumsum", args, kwargs, ["numeric_only", "skipna"])
39314033
if axis is not lib.no_default:
@@ -3942,7 +4044,7 @@ def cumsum(
39424044

39434045
@final
39444046
@Substitution(name="groupby")
3945-
@Appender(_common_see_also)
4047+
@Substitution(see_also=_common_see_also)
39464048
def cummin(
39474049
self,
39484050
axis: AxisInt | lib.NoDefault = lib.no_default,
@@ -3955,6 +4057,47 @@ def cummin(
39554057
Returns
39564058
-------
39574059
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
39584101
"""
39594102
skipna = kwargs.get("skipna", True)
39604103
if axis is not lib.no_default:
@@ -3976,7 +4119,7 @@ def cummin(
39764119

39774120
@final
39784121
@Substitution(name="groupby")
3979-
@Appender(_common_see_also)
4122+
@Substitution(see_also=_common_see_also)
39804123
def cummax(
39814124
self,
39824125
axis: AxisInt | lib.NoDefault = lib.no_default,
@@ -3989,6 +4132,47 @@ def cummax(
39894132
Returns
39904133
-------
39914134
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
39924176
"""
39934177
skipna = kwargs.get("skipna", True)
39944178
if axis is not lib.no_default:

0 commit comments

Comments
 (0)