slice_date_range

date_range(x, start_date, end_date, business_days_only=False)[source]

Create a time series from a (sub-)range of dates in an existing time series.

Parameters
  • x (Series) – time series

  • start_date (Union[date, int]) – start date for the sliced time series. If integer, the number of days after the first date

  • end_date (Union[date, int]) – end date for the sliced time series. If integer the number of days before the last date

  • business_days_only (bool) – whether to include only business dates in the sliced ranges

Return type

Series

Returns

sliced time series

Usage

Returns a restricted (“sliced”) time series based on start and end dates:

\(Y_t = R_t |_{start < t < end}\)

Examples

Slice the first and last week of a time series:

>>> series = generate_series(100)
>>> sliced_series = date_range(series,7,7)

See also

day() :func: lag