Skip to content

DOC: Fixing EX01 - Added examples #53909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
pandas.io.stata.StataReader.value_labels \
pandas.io.stata.StataReader.variable_labels \
pandas.io.stata.StataWriter.write_file \
pandas.core.resample.Resampler.asfreq \
pandas.core.resample.Resampler.count \
pandas.core.resample.Resampler.nunique \
pandas.core.resample.Resampler.max \
pandas.core.resample.Resampler.mean \
pandas.core.resample.Resampler.median \
pandas.core.resample.Resampler.min \
pandas.core.resample.Resampler.ohlc \
pandas.core.resample.Resampler.prod \
pandas.core.resample.Resampler.size \
Expand Down
16 changes: 16 additions & 0 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ def nunique(self, dropna: bool = True) -> Series | DataFrame:

Examples
--------
For SeriesGroupby:

>>> lst = ['a', 'a', 'b', 'b']
>>> ser = pd.Series([1, 2, 3, 3], index=lst)
Expand All @@ -646,6 +647,21 @@ def nunique(self, dropna: bool = True) -> Series | DataFrame:
a 2
b 1
dtype: int64

For Resampler:

>>> ser = pd.Series([1, 2, 3, 3], index=pd.DatetimeIndex(
... ['2023-01-01', '2023-01-15', '2023-02-01', '2023-02-15']))
>>> ser
2023-01-01 1
2023-01-15 2
2023-02-01 3
2023-02-15 3
dtype: int64
>>> ser.resample('MS').nunique()
2023-01-01 2
2023-02-01 1
Freq: MS, dtype: int64
"""
ids, _, _ = self.grouper.group_info

Expand Down
29 changes: 29 additions & 0 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -2167,6 +2167,21 @@ def count(self) -> NDFrameT:
a
1 0 2
7 1 1

For Resampler:

>>> ser = pd.Series([1, 2, 3, 4], index=pd.DatetimeIndex(
... ['2023-01-01', '2023-01-15', '2023-02-01', '2023-02-15']))
>>> ser
2023-01-01 1
2023-01-15 2
2023-02-01 3
2023-02-15 4
dtype: int64
>>> ser.resample('MS').count()
2023-01-01 2
2023-02-01 2
Freq: MS, dtype: int64
"""
data = self._get_data_to_aggregate()
ids, _, ngroups = self.grouper.group_info
Expand Down Expand Up @@ -2350,6 +2365,20 @@ def median(self, numeric_only: bool = False):
a b
dog 3.0 4.0
mouse 7.0 3.0

For Resampler:

>>> ser = pd.Series([1, 2, 3, 3, 4, 5],
... index=pd.DatetimeIndex(['2023-01-01',
... '2023-01-10',
... '2023-01-15',
... '2023-02-01',
... '2023-02-10',
... '2023-02-15']))
>>> ser.resample('MS').median()
2023-01-01 2.0
2023-02-01 4.0
Freq: MS, dtype: float64
"""
result = self._cython_agg_general(
"median",
Expand Down
77 changes: 77 additions & 0 deletions pandas/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,22 @@ def asfreq(self, fill_value=None):
--------
Series.asfreq: Convert TimeSeries to specified frequency.
DataFrame.asfreq: Convert TimeSeries to specified frequency.

Examples
--------

>>> ser = pd.Series([1, 2, 3, 4], index=pd.DatetimeIndex(
... ['2023-01-01', '2023-01-31', '2023-02-01', '2023-02-28']))
>>> ser
2023-01-01 1
2023-01-31 2
2023-02-01 3
2023-02-28 4
dtype: int64
>>> ser.resample('MS').asfreq()
2023-01-01 1
2023-02-01 3
Freq: MS, dtype: int64
"""
return self._upsample("asfreq", fill_value=fill_value)

Expand Down Expand Up @@ -1116,6 +1132,29 @@ def min(
*args,
**kwargs,
):
"""
Compute min value of group.

Returns
-------
Series or DataFrame

Examples
--------
>>> ser = pd.Series([1, 2, 3, 4], index=pd.DatetimeIndex(
... ['2023-01-01', '2023-01-15', '2023-02-01', '2023-02-15']))
>>> ser
2023-01-01 1
2023-01-15 2
2023-02-01 3
2023-02-15 4
dtype: int64
>>> ser.resample('MS').min()
2023-01-01 1
2023-02-01 3
Freq: MS, dtype: int64
"""

maybe_warn_args_and_kwargs(type(self), "min", args, kwargs)
nv.validate_resampler_func("min", args, kwargs)
return self._downsample("min", numeric_only=numeric_only, min_count=min_count)
Expand All @@ -1127,6 +1166,28 @@ def max(
*args,
**kwargs,
):
"""
Compute max value of group.

Returns
-------
Series or DataFrame

Examples
--------
>>> ser = pd.Series([1, 2, 3, 4], index=pd.DatetimeIndex(
... ['2023-01-01', '2023-01-15', '2023-02-01', '2023-02-15']))
>>> ser
2023-01-01 1
2023-01-15 2
2023-02-01 3
2023-02-15 4
dtype: int64
>>> ser.resample('MS').max()
2023-01-01 2
2023-02-01 4
Freq: MS, dtype: int64
"""
maybe_warn_args_and_kwargs(type(self), "max", args, kwargs)
nv.validate_resampler_func("max", args, kwargs)
return self._downsample("max", numeric_only=numeric_only, min_count=min_count)
Expand Down Expand Up @@ -1183,6 +1244,22 @@ def mean(
-------
DataFrame or Series
Mean of values within each group.

Examples
--------

>>> ser = pd.Series([1, 2, 3, 4], index=pd.DatetimeIndex(
... ['2023-01-01', '2023-01-15', '2023-02-01', '2023-02-15']))
>>> ser
2023-01-01 1
2023-01-15 2
2023-02-01 3
2023-02-15 4
dtype: int64
>>> ser.resample('MS').mean()
2023-01-01 1.5
2023-02-01 3.5
Freq: MS, dtype: float64
"""
maybe_warn_args_and_kwargs(type(self), "mean", args, kwargs)
nv.validate_resampler_func("mean", args, kwargs)
Expand Down