make_future_timeseries

make_future_timeseries(idx, length_out, freq=None, force_regular=False)

Make future dates for a time series.

The function make_future_timeseries takes a pandas Series or DateTimeIndex and generates a future sequence of dates based on the frequency of the input series.

Parameters

Name Type Description Default
idx pd.Series or pd.DateTimeIndex The idx parameter is the input time series data. It can be either a pandas Series or a pandas DateTimeIndex. It represents the existing dates in the time series. required
length_out int The parameter length_out is an integer that represents the number of future dates to generate for the time series. required
freq str The frequency parameter is a string that specifies the frequency of the future dates. If frequency is set to None, the frequency of the future dates will be inferred from the input data (e.g. business calendars might be used). The default value is None. None
force_regular bool The force_regular parameter is a boolean flag that determines whether the frequency of the future dates should be forced to be regular. If force_regular is set to True, the frequency of the future dates will be forced to be regular. If force_regular is set to False, the frequency of the future dates will be inferred from the input data (e.g. business calendars might be used). The default value is False. False

Returns

Type Description
pd.Series A pandas Series object containing future dates.

Examples

import pandas as pd
import pytimetk as tk

# Works with a single date (must provide a length out and frequency if only 
# 1 date is provided)
tk.make_future_timeseries("2011-01-01", 5, "D")
0   2011-01-02
1   2011-01-03
2   2011-01-04
3   2011-01-05
4   2011-01-06
dtype: datetime64[ns]
# DateTimeIndex: Generate 5 future dates (with inferred frequency)

dates = pd.Series(pd.to_datetime(['2022-01-01', '2022-01-02', '2022-01-03', '2022-01-04']))

future_dates_dt = tk.make_future_timeseries(dates, 5)
future_dates_dt
0   2022-01-05
1   2022-01-06
2   2022-01-07
3   2022-01-08
4   2022-01-09
dtype: datetime64[ns]
# Series: Generate 5 future dates
pd.Series(future_dates_dt).make_future_timeseries(5)
0   2022-01-10
1   2022-01-11
2   2022-01-12
3   2022-01-13
4   2022-01-14
dtype: datetime64[ns]
# Hourly Frequency: Generate 5 future dates
timestamps = ["2023-01-01 01:00", "2023-01-01 02:00", "2023-01-01 03:00", "2023-01-01 04:00", "2023-01-01 05:00"]

dates = pd.to_datetime(timestamps)

tk.make_future_timeseries(dates, 5)
0   2023-01-01 06:00:00
1   2023-01-01 07:00:00
2   2023-01-01 08:00:00
3   2023-01-01 09:00:00
4   2023-01-01 10:00:00
dtype: datetime64[ns]
# Monthly Frequency: Generate 4 future dates
dates = pd.to_datetime(["2021-01-01", "2021-02-01", "2021-03-01", "2021-04-01"])

tk.make_future_timeseries(dates, 4)
0   2021-05-01
1   2021-06-01
2   2021-07-01
3   2021-08-01
dtype: datetime64[ns]
# Quarterly Frequency: Generate 4 future dates
dates = pd.to_datetime(["2021-01-01", "2021-04-01", "2021-07-01", "2021-10-01"])

tk.make_future_timeseries(dates, 4)
0   2022-01-01
1   2022-04-01
2   2022-07-01
3   2022-10-01
dtype: datetime64[ns]
# Irregular Dates: Business Days
dates = pd.to_datetime(["2021-01-01", "2021-01-04", "2021-01-05", "2021-01-06"])

tk.get_frequency(dates)

tk.make_future_timeseries(dates, 4)
0   2021-01-07
1   2021-01-08
2   2021-01-11
3   2021-01-12
dtype: datetime64[ns]
# Irregular Dates: Business Days (Force Regular)    
tk.make_future_timeseries(dates, 4, force_regular=True)
0   2021-01-07
1   2021-01-08
2   2021-01-09
3   2021-01-10
dtype: datetime64[ns]