Upsampling with a polynomial interpolation
Another common interpolation method is to use a polynomial or a spline to connect the values. This creates more curves and can look realistic on many datasets. Using a spline interpolation requires you to specify the order (number of terms in the polynomial).
Python3
# use interpolate function with method polynomial # This upsamples the values of the remaining # days with a quadratic function of degree 2. interpolated = upsampled.interpolate(method = 'polynomial' , order = 2 ) # Printing the polynomial interpolated value print (interpolated) |
Output:
Thus, we can use resample() and interpolate() function to upsample the data. Try this out using different configurations of these functions.
How to Resample Time Series Data in Python?
In time series, data consistency is of prime importance, resampling ensures that the data is distributed with a consistent frequency. Resampling can also provide a different perception of looking at the data, in other words, it can add additional insights about the data based on the resampling frequency.
resample() function: It is a primarily used for time series data.
Syntax:
# import the python pandas library import pandas as pd # syntax for the resample function. pd.series.resample(rule, axis=0, closed='left', convention='start', kind=None, offset=None, origin='start_day')
Resampling primarily involves changing the time-frequency of the original observations. The two popular methods of resampling in time series are as follows
- Upsampling
- Downsampling