Skip to content

Commit 2a2002d

Browse files
authored
DOC: Fixing EX01 - Added examples (#53573)
Added examples
1 parent 97c4ef6 commit 2a2002d

File tree

2 files changed

+164
-13
lines changed

2 files changed

+164
-13
lines changed

ci/code_checks.sh

-10
Original file line numberDiff line numberDiff line change
@@ -263,22 +263,12 @@ 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.diff \
267266
pandas.core.groupby.DataFrameGroupBy.ffill \
268-
pandas.core.groupby.DataFrameGroupBy.median \
269267
pandas.core.groupby.DataFrameGroupBy.ohlc \
270-
pandas.core.groupby.DataFrameGroupBy.skew \
271-
pandas.core.groupby.DataFrameGroupBy.std \
272-
pandas.core.groupby.DataFrameGroupBy.var \
273-
pandas.core.groupby.SeriesGroupBy.diff \
274268
pandas.core.groupby.SeriesGroupBy.fillna \
275269
pandas.core.groupby.SeriesGroupBy.ffill \
276-
pandas.core.groupby.SeriesGroupBy.median \
277270
pandas.core.groupby.SeriesGroupBy.nunique \
278271
pandas.core.groupby.SeriesGroupBy.ohlc \
279-
pandas.core.groupby.SeriesGroupBy.skew \
280-
pandas.core.groupby.SeriesGroupBy.std \
281-
pandas.core.groupby.SeriesGroupBy.var \
282272
pandas.core.groupby.SeriesGroupBy.hist \
283273
pandas.core.groupby.DataFrameGroupBy.plot \
284274
pandas.core.groupby.SeriesGroupBy.plot \

pandas/core/groupby/groupby.py

+164-3
Original file line numberDiff line numberDiff line change
@@ -2217,6 +2217,44 @@ def median(self, numeric_only: bool = False):
22172217
-------
22182218
Series or DataFrame
22192219
Median of values within each group.
2220+
2221+
Examples
2222+
--------
2223+
For SeriesGroupBy:
2224+
2225+
>>> lst = ['a', 'a', 'a', 'b', 'b', 'b']
2226+
>>> ser = pd.Series([7, 2, 8, 4, 3, 3], index=lst)
2227+
>>> ser
2228+
a 7
2229+
a 2
2230+
a 8
2231+
b 4
2232+
b 3
2233+
b 3
2234+
dtype: int64
2235+
>>> ser.groupby(level=0).median()
2236+
a 7.0
2237+
b 3.0
2238+
dtype: float64
2239+
2240+
For DataFrameGroupBy:
2241+
2242+
>>> data = {'a': [1, 3, 5, 7, 7, 8, 3], 'b': [1, 4, 8, 4, 4, 2, 1]}
2243+
>>> df = pd.DataFrame(data, index=['dog', 'dog', 'dog',
2244+
... 'mouse', 'mouse', 'mouse', 'mouse'])
2245+
>>> df
2246+
a b
2247+
dog 1 1
2248+
dog 3 4
2249+
dog 5 8
2250+
mouse 7 4
2251+
mouse 7 4
2252+
mouse 8 2
2253+
mouse 3 1
2254+
>>> df.groupby(level=0).median()
2255+
a b
2256+
dog 3.0 4.0
2257+
mouse 7.0 3.0
22202258
"""
22212259
result = self._cython_agg_general(
22222260
"median",
@@ -2227,7 +2265,7 @@ def median(self, numeric_only: bool = False):
22272265

22282266
@final
22292267
@Substitution(name="groupby")
2230-
@Appender(_common_see_also)
2268+
@Substitution(see_also=_common_see_also)
22312269
def std(
22322270
self,
22332271
ddof: int = 1,
@@ -2275,6 +2313,44 @@ def std(
22752313
-------
22762314
Series or DataFrame
22772315
Standard deviation of values within each group.
2316+
%(see_also)s
2317+
Examples
2318+
--------
2319+
For SeriesGroupBy:
2320+
2321+
>>> lst = ['a', 'a', 'a', 'b', 'b', 'b']
2322+
>>> ser = pd.Series([7, 2, 8, 4, 3, 3], index=lst)
2323+
>>> ser
2324+
a 7
2325+
a 2
2326+
a 8
2327+
b 4
2328+
b 3
2329+
b 3
2330+
dtype: int64
2331+
>>> ser.groupby(level=0).std()
2332+
a 3.21455
2333+
b 0.57735
2334+
dtype: float64
2335+
2336+
For DataFrameGroupBy:
2337+
2338+
>>> data = {'a': [1, 3, 5, 7, 7, 8, 3], 'b': [1, 4, 8, 4, 4, 2, 1]}
2339+
>>> df = pd.DataFrame(data, index=['dog', 'dog', 'dog',
2340+
... 'mouse', 'mouse', 'mouse', 'mouse'])
2341+
>>> df
2342+
a b
2343+
dog 1 1
2344+
dog 3 4
2345+
dog 5 8
2346+
mouse 7 4
2347+
mouse 7 4
2348+
mouse 8 2
2349+
mouse 3 1
2350+
>>> df.groupby(level=0).std()
2351+
a b
2352+
dog 2.000000 3.511885
2353+
mouse 2.217356 1.500000
22782354
"""
22792355
if maybe_use_numba(engine):
22802356
from pandas.core._numba.kernels import sliding_var
@@ -2290,7 +2366,7 @@ def std(
22902366

22912367
@final
22922368
@Substitution(name="groupby")
2293-
@Appender(_common_see_also)
2369+
@Substitution(see_also=_common_see_also)
22942370
def var(
22952371
self,
22962372
ddof: int = 1,
@@ -2338,6 +2414,44 @@ def var(
23382414
-------
23392415
Series or DataFrame
23402416
Variance of values within each group.
2417+
%(see_also)s
2418+
Examples
2419+
--------
2420+
For SeriesGroupBy:
2421+
2422+
>>> lst = ['a', 'a', 'a', 'b', 'b', 'b']
2423+
>>> ser = pd.Series([7, 2, 8, 4, 3, 3], index=lst)
2424+
>>> ser
2425+
a 7
2426+
a 2
2427+
a 8
2428+
b 4
2429+
b 3
2430+
b 3
2431+
dtype: int64
2432+
>>> ser.groupby(level=0).var()
2433+
a 10.333333
2434+
b 0.333333
2435+
dtype: float64
2436+
2437+
For DataFrameGroupBy:
2438+
2439+
>>> data = {'a': [1, 3, 5, 7, 7, 8, 3], 'b': [1, 4, 8, 4, 4, 2, 1]}
2440+
>>> df = pd.DataFrame(data, index=['dog', 'dog', 'dog',
2441+
... 'mouse', 'mouse', 'mouse', 'mouse'])
2442+
>>> df
2443+
a b
2444+
dog 1 1
2445+
dog 3 4
2446+
dog 5 8
2447+
mouse 7 4
2448+
mouse 7 4
2449+
mouse 8 2
2450+
mouse 3 1
2451+
>>> df.groupby(level=0).var()
2452+
a b
2453+
dog 4.000000 12.333333
2454+
mouse 4.916667 2.250000
23412455
"""
23422456
if maybe_use_numba(engine):
23432457
from pandas.core._numba.kernels import sliding_var
@@ -4569,7 +4683,7 @@ def shift(
45694683

45704684
@final
45714685
@Substitution(name="groupby")
4572-
@Appender(_common_see_also)
4686+
@Substitution(see_also=_common_see_also)
45734687
def diff(
45744688
self, periods: int = 1, axis: AxisInt | lib.NoDefault = lib.no_default
45754689
) -> NDFrameT:
@@ -4594,6 +4708,53 @@ def diff(
45944708
-------
45954709
Series or DataFrame
45964710
First differences.
4711+
%(see_also)s
4712+
Examples
4713+
--------
4714+
For SeriesGroupBy:
4715+
4716+
>>> lst = ['a', 'a', 'a', 'b', 'b', 'b']
4717+
>>> ser = pd.Series([7, 2, 8, 4, 3, 3], index=lst)
4718+
>>> ser
4719+
a 7
4720+
a 2
4721+
a 8
4722+
b 4
4723+
b 3
4724+
b 3
4725+
dtype: int64
4726+
>>> ser.groupby(level=0).diff()
4727+
a NaN
4728+
a -5.0
4729+
a 6.0
4730+
b NaN
4731+
b -1.0
4732+
b 0.0
4733+
dtype: float64
4734+
4735+
For DataFrameGroupBy:
4736+
4737+
>>> data = {'a': [1, 3, 5, 7, 7, 8, 3], 'b': [1, 4, 8, 4, 4, 2, 1]}
4738+
>>> df = pd.DataFrame(data, index=['dog', 'dog', 'dog',
4739+
... 'mouse', 'mouse', 'mouse', 'mouse'])
4740+
>>> df
4741+
a b
4742+
dog 1 1
4743+
dog 3 4
4744+
dog 5 8
4745+
mouse 7 4
4746+
mouse 7 4
4747+
mouse 8 2
4748+
mouse 3 1
4749+
>>> df.groupby(level=0).diff()
4750+
a b
4751+
dog NaN NaN
4752+
dog 2.0 3.0
4753+
dog 2.0 4.0
4754+
mouse NaN NaN
4755+
mouse 0.0 0.0
4756+
mouse 1.0 -2.0
4757+
mouse -5.0 -1.0
45974758
"""
45984759
if axis is not lib.no_default:
45994760
axis = self.obj._get_axis_number(axis)

0 commit comments

Comments
 (0)