TimeSeriesDataFrame.fill_missing_values#

TimeSeriesDataFrame.fill_missing_values(method: str = 'auto', value: float = 0.0) TimeSeriesDataFrame[source]#

Fill missing values represented by NaN.

Parameters
  • method (str, default = "auto") –

    Method used to impute missing values.

    • ”auto” - first forward fill (to fill the in-between and trailing NaNs), then backward fill (to fill the leading NaNs)

    • ”ffill” or “pad” - propagate last valid observation forward. Note: missing values at the start of the time series are not filled.

    • ”bfill” or “backfill” - use next valid observation to fill gap. Note: this may result in information leakage; missing values at the end of the time series are not filled.

    • ”constant” - replace NaNs with the given constant value.

    • ”interpolate” - fill NaN values using linear interpolation. Note: this may result in information leakage.

  • value (float, default = 0.0) – Value used by the “constant” imputation method.

Examples

>>> print(ts_dataframe)
                    target
item_id timestamp
0       2019-01-01     NaN
        2019-01-02     NaN
        2019-01-03     1.0
        2019-01-04     NaN
        2019-01-05     NaN
        2019-01-06     2.0
        2019-01-07     NaN
1       2019-02-04     NaN
        2019-02-05     3.0
        2019-02-06     NaN
        2019-02-07     4.0
>>> print(ts_dataframe.fill_missing_values(method="auto"))
                    target
item_id timestamp
0       2019-01-01     1.0
        2019-01-02     1.0
        2019-01-03     1.0
        2019-01-04     1.0
        2019-01-05     1.0
        2019-01-06     2.0
        2019-01-07     2.0
1       2019-02-04     3.0
        2019-02-05     3.0
        2019-02-06     3.0
        2019-02-07     4.0