Documentation Index
Fetch the complete documentation index at: https://nixtla.io/docs/llms.txt
Use this file to discover all available pages before exploring further.
Missing Values in Time Series
TimeGPT can handle missing values in your target series, but it needs a continuous series of timestamps. While you may have multiple series starting and ending on different dates, each one must maintain a continuous date sequence. Any unobserved values in your target series can be labelled asNaN.
Whenever possible, we recommend to fill missing values by interpolation or any other method that makes
sense in your particular context.
This tutorial shows you how to handle missing values for use with TimeGPT. For
reference, this tutorial is based on the skforecast tutorial:
Forecasting Time Series with Missing Values.
Tutorial
Step 1: Load Data
Load the daily bike rental counts dataset using pandas. Note that the original column names are in Spanish; you will rename them to matchds and y.
| ds | y | |
|---|---|---|
| 0 | 2014-06-23 | 99 |
| 1 | 2014-06-24 | 72 |
| 2 | 2014-06-25 | 119 |
| 3 | 2014-06-26 | 135 |
| 4 | 2014-06-27 | 149 |
unique_id) to handle multiple series if needed:
Step 2: Initialize TimeGPT
Initialize aNixtlaClient object with your Nixtla API key:
Step 3: Visualize Data
Plot your dataset and examine the gaps introduced above:
max_insample_length argument of the plot method or you
can simply zoom in on the plot.

Step 4: Fill Missing Dates
You can usefill_gaps from utilsforecast to insert the missing dates:
Before using TimeGPT, we need to ensure that all timestamps from the start date to the end date are present in the data.
Missing values in the series can be present as NaN.
To address the first issue, we will use the fill_gaps function from utilsforecast,
a Python package from Nixtla that provides essential utilities for time series
forecasting, such as functions for data preprocessing, plotting, and evaluation.
The fill_gaps function will fill in the missing dates in the data. To do this,
it requires the following arguments:
df: The DataFrame containing the time series data.freq(str or int): The frequency of the data.
NOTE: In this tutorial, the data contains only one time series. However, TimeGPT supports passing multiple series to the model. In this case, none of the time series can have missing values from their individual earliest timestamp until their individual latest timestamp. If these individual time series have missing values, the user must decide how to fill these gaps for the individual time series. TheNow we need to decide whether to fill the missing values in the target column or not. In this tutorial, we decide to use interpolation, but it is important to consider the specific context of your data when selecting a filling strategy. For example, if you are dealing with daily retail data, a missing value most likely indicates that there were no sales on that day, and you can fill it with zero. Conversely, if you are working with hourly temperature data, a missing value probably means that the sensor was not functioning, and you might prefer to keep the value asfill_gapsfunction provides a couple of additional arguments to assist with this (refer to the documentation for complete details), namelystartandend.
NaN.
In this case, we will handle the newly inserted missing values by interpolation.
Step 5: Forecast with TimeGPT
Typically, a horizon > 2 times the typical seasonality is considered long. In this case, the data has a seasonality of 7 days and a horizon of 93 days. Since the forecast horizon is long compared to the frequency of the data (daily), we will usetimegpt-1-long-horizon model.

utilsforecast. We will use Mean Absolute Error (MAE)
as the evaluation metric, but you can choose others like MSE, RMSE, etc.:
| unique_id | metric | TimeGPT | |
|---|---|---|---|
| 0 | id1 | mae | 1824.693059 |
Step 6: Conclusion
- Always ensure that your data is free of missing dates before forecasting with TimeGPT.
- Select a gap-filling strategy based on your domain knowledge (linear interpolation, constant filling, etc.).
- You may want to keep missing values as
NaNif no gap-filling strategy makes sense in your context.