Converting an irregular time series to a regular time series: Resampling

Raghav Sharma
2 min readFeb 2, 2024

--

One of the primary prerequisites for any statistical treatment of a given time series is that it should be a regular time series. A regular time series can be defined as a time series that is spaced regularly in time. The time period between any two consecutive data points is the same, throughout the time series. A time series that does not adhere to the above definition is termed an irregular time series.

As an example, consider the following time series:

Sample irregular time series

To convert this irregular time series into a regular time series, the resampling process needs to be performed. One of the ways to perform resampling is by using the Pandas library in Python. The algorithm for resampling using Pandas is as follows:

  1. Convert the time series to a date-time format (if it’s not in the date-time format already).
#Converting to date-time format
df3_vib_spindle.set_index(pd.to_datetime(df3_vib_spindle['time'], unit='s'), inplace=True)
df3_vib_spindle.drop('time', axis=1, inplace=True)
Time Series converted to Date-Time format

2. Resampling the series and filling in the gaps with interpolation. This can be achieved easily with one line of pandas code.

df3_vib_spindle_resampled = df3_vib_spindle.resample('1S').interpolate(method = 'linear')

The time series has now been converted to a regular time series with a time period of one second and linear interpolation has been used to fill the gaps.

Regular Time Series

Want to see forecasting as well as anomaly detection applied to this now regular time series? Check out my blog: https://medium.com/@ras325/getting-started-with-analyzing-forecasting-and-detecting-anomalies-using-machining-data-4e048135b98

--

--

Raghav Sharma
Raghav Sharma

Written by Raghav Sharma

MS in Mechanical Engineering | Machine Learning enthusiast | Additive Manufacturing junkie | Algorithm fan-boy

Responses (1)