TimeSince
Compute element-wise time elapsed between time index and a reference start time.
Quickstart
from sktime.transformations.time_since import TimeSince
estimator = TimeSince(start: list [str | datetime | Period | None ] | None=None, *, to_numeric: bool | None=True, freq: str | None=None, keep_original_columns: bool | None=False, positive_only: bool | None=False)Parameters(5)
- starta list of start times, optional, default=None (use earliest time in index)
a “start time” can be one of the following types:
int: Start time to compute the time elapsed, use when index is integer.
- time-like:
PeriodordatetimeStart time to compute the time elapsed.
- to_numericstring, optional (default=True)
Return the integer number of periods elapsed since
start; the period is defined by the frequency of the data. Converts datetime types to pd.Period before calculating time differences.- freq‘str’, optional, default=None
Only used when X has a pd.DatetimeIndex without a specified frequency. Specifies the frequency of the index of your data. The string should match a pandas offset alias:
https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases
- keep_original_columnsboolean, optional, default=False
Keep original columns in X passed to
.transform().- positive_onlyboolean, optional, default=False
Clips negative values to zero when
to_numericis True.
Examples
>>> from sktime.datasets import load_airline
>>> from sktime.transformations.time_since import TimeSince
>>> X = load_airline () Create a single column with time elapsed since start date of time series. The output is in units of integer number of months, same as the index freq.
>>> transformer = TimeSince ()
>>> Xt = transformer. fit_transform (X) Create multiple columns with different start times. The output is in units of integer number of months, same as the index freq.
>>> transformer = TimeSince (["2000-01", "2000-02" ])
>>> Xt = transformer. fit_transform (X)