Skip to content

DOC: Add reference to frequency strings #13632

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

Closed
Closed
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
13 changes: 8 additions & 5 deletions doc/source/timeseries.rst
Original file line number Diff line number Diff line change
Expand Up @@ -567,11 +567,11 @@ DateOffset objects
------------------

In the preceding examples, we created DatetimeIndex objects at various
frequencies by passing in frequency strings like 'M', 'W', and 'BM to the
``freq`` keyword. Under the hood, these frequency strings are being translated
into an instance of pandas ``DateOffset``, which represents a regular
frequency increment. Specific offset logic like "month", "business day", or
"one hour" is represented in its various subclasses.
frequencies by passing in :ref:`frequency strings <timeseries.offset_aliases>`
like 'M', 'W', and 'BM to the ``freq`` keyword. Under the hood, these frequency
strings are being translated into an instance of pandas ``DateOffset``,
which represents a regular frequency increment. Specific offset logic like
"month", "business day", or "one hour" is represented in its various subclasses.

.. csv-table::
:header: "Class name", "Description"
Expand Down Expand Up @@ -953,6 +953,9 @@ You can use keyword arguments suported by either ``BusinessHour`` and ``CustomBu
# Monday is skipped because it's a holiday, business hour starts from 10:00
dt + bhour_mon * 2


.. _timeseries.offset_aliases:

Offset Aliases
~~~~~~~~~~~~~~

Expand Down
6 changes: 6 additions & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3938,6 +3938,9 @@ def asfreq(self, freq, method=None, how=None, normalize=False):
Returns
-------
converted : type of caller

To learn more about the frequency strings, please see `this link
<http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases>`__.
"""
from pandas.tseries.resample import asfreq
return asfreq(self, freq, method=method, how=how, normalize=normalize)
Expand Down Expand Up @@ -4009,6 +4012,9 @@ def resample(self, rule, how=None, axis=0, fill_method=None, closed=None,
range from 0 through 4. Defaults to 0


To learn more about the offset strings, please see `this link
<http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases>`__.

Examples
--------

Expand Down
21 changes: 21 additions & 0 deletions pandas/stats/moments.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ def rolling_count(arg, window, **kwargs):
The `freq` keyword is used to conform time series data to a specified
frequency by resampling the data. This is done with the default parameters
of :meth:`~pandas.Series.resample` (i.e. using the `mean`).

To learn more about the frequency strings, please see `this link
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are all deprecated, but ok I guess.

<http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases>`__.
"""
return ensure_compat('rolling', 'count', arg, window=window, **kwargs)

Expand Down Expand Up @@ -521,6 +524,9 @@ def rolling_quantile(arg, window, quantile, min_periods=None, freq=None,
The `freq` keyword is used to conform time series data to a specified
frequency by resampling the data. This is done with the default parameters
of :meth:`~pandas.Series.resample` (i.e. using the `mean`).

To learn more about the frequency strings, please see `this link
<http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases>`__.
"""
return ensure_compat('rolling',
'quantile',
Expand Down Expand Up @@ -570,6 +576,9 @@ def rolling_apply(arg, window, func, min_periods=None, freq=None,
The `freq` keyword is used to conform time series data to a specified
frequency by resampling the data. This is done with the default parameters
of :meth:`~pandas.Series.resample` (i.e. using the `mean`).

To learn more about the frequency strings, please see `this link
<http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases>`__.
"""
return ensure_compat('rolling',
'apply',
Expand Down Expand Up @@ -642,6 +651,9 @@ def rolling_window(arg, window=None, win_type=None, min_periods=None,
The `freq` keyword is used to conform time series data to a specified
frequency by resampling the data. This is done with the default parameters
of :meth:`~pandas.Series.resample` (i.e. using the `mean`).

To learn more about the frequency strings, please see `this link
<http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases>`__.
"""
func = 'mean' if mean else 'sum'
return ensure_compat('rolling',
Expand Down Expand Up @@ -707,6 +719,9 @@ def expanding_count(arg, freq=None):
The `freq` keyword is used to conform time series data to a specified
frequency by resampling the data. This is done with the default parameters
of :meth:`~pandas.Series.resample` (i.e. using the `mean`).

To learn more about the frequency strings, please see `this link
<http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases>`__.
"""
return ensure_compat('expanding', 'count', arg, freq=freq)

Expand Down Expand Up @@ -735,6 +750,9 @@ def expanding_quantile(arg, quantile, min_periods=1, freq=None):
The `freq` keyword is used to conform time series data to a specified
frequency by resampling the data. This is done with the default parameters
of :meth:`~pandas.Series.resample` (i.e. using the `mean`).

To learn more about the frequency strings, please see `this link
<http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases>`__.
"""
return ensure_compat('expanding',
'quantile',
Expand Down Expand Up @@ -818,6 +836,9 @@ def expanding_apply(arg, func, min_periods=1, freq=None,
The `freq` keyword is used to conform time series data to a specified
frequency by resampling the data. This is done with the default parameters
of :meth:`~pandas.Series.resample` (i.e. using the `mean`).

To learn more about the frequency strings, please see `this link
<http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases>`__.
"""
return ensure_compat('expanding',
'apply',
Expand Down
12 changes: 12 additions & 0 deletions pandas/tseries/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ class DatetimeIndex(DatelikeOps, TimelikeOps, DatetimeIndexOpsMixin,
Attempt to infer fall dst-transition hours based on order
name : object
Name to be stored in the index

To learn more about the frequency strings, please see `this link
<http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases>`__.
"""

_typ = 'datetimeindex'
Expand Down Expand Up @@ -2071,6 +2074,9 @@ def date_range(start=None, end=None, periods=None, freq='D', tz=None,
-----
2 of start, end, or periods must be specified

To learn more about the frequency strings, please see `this link
<http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases>`__.

Returns
-------
rng : DatetimeIndex
Expand Down Expand Up @@ -2111,6 +2117,9 @@ def bdate_range(start=None, end=None, periods=None, freq='B', tz=None,
-----
2 of start, end, or periods must be specified

To learn more about the frequency strings, please see `this link
<http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases>`__.

Returns
-------
rng : DatetimeIndex
Expand Down Expand Up @@ -2162,6 +2171,9 @@ def cdate_range(start=None, end=None, periods=None, freq='C', tz=None,
-----
2 of start, end, or periods must be specified

To learn more about the frequency strings, please see `this link
<http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases>`__.

Returns
-------
rng : DatetimeIndex
Expand Down
6 changes: 6 additions & 0 deletions pandas/tseries/tdi.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ class TimedeltaIndex(DatetimeIndexOpsMixin, TimelikeOps, Int64Index):
the 'left', 'right', or both sides (None)
name : object
Name to be stored in the index

To learn more about the frequency strings, please see `this link
<http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases>`__.
"""

_typ = 'timedeltaindex'
Expand Down Expand Up @@ -1001,6 +1004,9 @@ def timedelta_range(start=None, end=None, periods=None, freq='D',
Returns
-------
rng : TimedeltaIndex

To learn more about the frequency strings, please see `this link
<http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases>`__.
"""
return TimedeltaIndex(start=start, end=end, periods=periods,
freq=freq, name=name,
Expand Down