Skip to content

Commit 1b33bf6

Browse files
authored
DOC: Fixing EX01 - Added examples (#53909)
* Examples Resampler.asfreq, count, nunique, max, mean, median * Example Resampler.min * Added Returns section to min and max * Changed M to MS and examples results accordingly
1 parent 6e789c1 commit 1b33bf6

File tree

4 files changed

+122
-7
lines changed

4 files changed

+122
-7
lines changed

ci/code_checks.sh

-7
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
118118
pandas.io.stata.StataReader.value_labels \
119119
pandas.io.stata.StataReader.variable_labels \
120120
pandas.io.stata.StataWriter.write_file \
121-
pandas.core.resample.Resampler.asfreq \
122-
pandas.core.resample.Resampler.count \
123-
pandas.core.resample.Resampler.nunique \
124-
pandas.core.resample.Resampler.max \
125-
pandas.core.resample.Resampler.mean \
126-
pandas.core.resample.Resampler.median \
127-
pandas.core.resample.Resampler.min \
128121
pandas.core.resample.Resampler.ohlc \
129122
pandas.core.resample.Resampler.prod \
130123
pandas.core.resample.Resampler.size \

pandas/core/groupby/generic.py

+16
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ def nunique(self, dropna: bool = True) -> Series | DataFrame:
633633
634634
Examples
635635
--------
636+
For SeriesGroupby:
636637
637638
>>> lst = ['a', 'a', 'b', 'b']
638639
>>> ser = pd.Series([1, 2, 3, 3], index=lst)
@@ -646,6 +647,21 @@ def nunique(self, dropna: bool = True) -> Series | DataFrame:
646647
a 2
647648
b 1
648649
dtype: int64
650+
651+
For Resampler:
652+
653+
>>> ser = pd.Series([1, 2, 3, 3], index=pd.DatetimeIndex(
654+
... ['2023-01-01', '2023-01-15', '2023-02-01', '2023-02-15']))
655+
>>> ser
656+
2023-01-01 1
657+
2023-01-15 2
658+
2023-02-01 3
659+
2023-02-15 3
660+
dtype: int64
661+
>>> ser.resample('MS').nunique()
662+
2023-01-01 2
663+
2023-02-01 1
664+
Freq: MS, dtype: int64
649665
"""
650666
ids, _, _ = self.grouper.group_info
651667

pandas/core/groupby/groupby.py

+29
Original file line numberDiff line numberDiff line change
@@ -2167,6 +2167,21 @@ def count(self) -> NDFrameT:
21672167
a
21682168
1 0 2
21692169
7 1 1
2170+
2171+
For Resampler:
2172+
2173+
>>> ser = pd.Series([1, 2, 3, 4], index=pd.DatetimeIndex(
2174+
... ['2023-01-01', '2023-01-15', '2023-02-01', '2023-02-15']))
2175+
>>> ser
2176+
2023-01-01 1
2177+
2023-01-15 2
2178+
2023-02-01 3
2179+
2023-02-15 4
2180+
dtype: int64
2181+
>>> ser.resample('MS').count()
2182+
2023-01-01 2
2183+
2023-02-01 2
2184+
Freq: MS, dtype: int64
21702185
"""
21712186
data = self._get_data_to_aggregate()
21722187
ids, _, ngroups = self.grouper.group_info
@@ -2350,6 +2365,20 @@ def median(self, numeric_only: bool = False):
23502365
a b
23512366
dog 3.0 4.0
23522367
mouse 7.0 3.0
2368+
2369+
For Resampler:
2370+
2371+
>>> ser = pd.Series([1, 2, 3, 3, 4, 5],
2372+
... index=pd.DatetimeIndex(['2023-01-01',
2373+
... '2023-01-10',
2374+
... '2023-01-15',
2375+
... '2023-02-01',
2376+
... '2023-02-10',
2377+
... '2023-02-15']))
2378+
>>> ser.resample('MS').median()
2379+
2023-01-01 2.0
2380+
2023-02-01 4.0
2381+
Freq: MS, dtype: float64
23532382
"""
23542383
result = self._cython_agg_general(
23552384
"median",

pandas/core/resample.py

+77
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,22 @@ def asfreq(self, fill_value=None):
10831083
--------
10841084
Series.asfreq: Convert TimeSeries to specified frequency.
10851085
DataFrame.asfreq: Convert TimeSeries to specified frequency.
1086+
1087+
Examples
1088+
--------
1089+
1090+
>>> ser = pd.Series([1, 2, 3, 4], index=pd.DatetimeIndex(
1091+
... ['2023-01-01', '2023-01-31', '2023-02-01', '2023-02-28']))
1092+
>>> ser
1093+
2023-01-01 1
1094+
2023-01-31 2
1095+
2023-02-01 3
1096+
2023-02-28 4
1097+
dtype: int64
1098+
>>> ser.resample('MS').asfreq()
1099+
2023-01-01 1
1100+
2023-02-01 3
1101+
Freq: MS, dtype: int64
10861102
"""
10871103
return self._upsample("asfreq", fill_value=fill_value)
10881104

@@ -1116,6 +1132,29 @@ def min(
11161132
*args,
11171133
**kwargs,
11181134
):
1135+
"""
1136+
Compute min value of group.
1137+
1138+
Returns
1139+
-------
1140+
Series or DataFrame
1141+
1142+
Examples
1143+
--------
1144+
>>> ser = pd.Series([1, 2, 3, 4], index=pd.DatetimeIndex(
1145+
... ['2023-01-01', '2023-01-15', '2023-02-01', '2023-02-15']))
1146+
>>> ser
1147+
2023-01-01 1
1148+
2023-01-15 2
1149+
2023-02-01 3
1150+
2023-02-15 4
1151+
dtype: int64
1152+
>>> ser.resample('MS').min()
1153+
2023-01-01 1
1154+
2023-02-01 3
1155+
Freq: MS, dtype: int64
1156+
"""
1157+
11191158
maybe_warn_args_and_kwargs(type(self), "min", args, kwargs)
11201159
nv.validate_resampler_func("min", args, kwargs)
11211160
return self._downsample("min", numeric_only=numeric_only, min_count=min_count)
@@ -1127,6 +1166,28 @@ def max(
11271166
*args,
11281167
**kwargs,
11291168
):
1169+
"""
1170+
Compute max value of group.
1171+
1172+
Returns
1173+
-------
1174+
Series or DataFrame
1175+
1176+
Examples
1177+
--------
1178+
>>> ser = pd.Series([1, 2, 3, 4], index=pd.DatetimeIndex(
1179+
... ['2023-01-01', '2023-01-15', '2023-02-01', '2023-02-15']))
1180+
>>> ser
1181+
2023-01-01 1
1182+
2023-01-15 2
1183+
2023-02-01 3
1184+
2023-02-15 4
1185+
dtype: int64
1186+
>>> ser.resample('MS').max()
1187+
2023-01-01 2
1188+
2023-02-01 4
1189+
Freq: MS, dtype: int64
1190+
"""
11301191
maybe_warn_args_and_kwargs(type(self), "max", args, kwargs)
11311192
nv.validate_resampler_func("max", args, kwargs)
11321193
return self._downsample("max", numeric_only=numeric_only, min_count=min_count)
@@ -1183,6 +1244,22 @@ def mean(
11831244
-------
11841245
DataFrame or Series
11851246
Mean of values within each group.
1247+
1248+
Examples
1249+
--------
1250+
1251+
>>> ser = pd.Series([1, 2, 3, 4], index=pd.DatetimeIndex(
1252+
... ['2023-01-01', '2023-01-15', '2023-02-01', '2023-02-15']))
1253+
>>> ser
1254+
2023-01-01 1
1255+
2023-01-15 2
1256+
2023-02-01 3
1257+
2023-02-15 4
1258+
dtype: int64
1259+
>>> ser.resample('MS').mean()
1260+
2023-01-01 1.5
1261+
2023-02-01 3.5
1262+
Freq: MS, dtype: float64
11861263
"""
11871264
maybe_warn_args_and_kwargs(type(self), "mean", args, kwargs)
11881265
nv.validate_resampler_func("mean", args, kwargs)

0 commit comments

Comments
 (0)