I am working with two pandas Series with Timestamps as indices. One Series is a coarse model with a fixed frequency, the other one are data with no fixed frequency. I would like to subtract the model from the data and (linearly or spline) interpolate the values of the model.
Here is an example:
import numpy as np
import pandas as pd
# generate model with fixed freq
model = pd.Series(range(5),index=pd.date_range('2017-06-19T12:05:00', '2017-06-19T12:25:00', freq="5 min"))
# generate data and add more_data to make frequency irregular
data = pd.Series(np.arange(10)+0.3,index=pd.date_range('2017-06-19T12:06:00',
'2017-06-19T12:24:00', freq="2 min"))
more_data = pd.Series([-10, -20], index=[pd.Timestamp('2017-06-19T12:07:35'),
pd.Timestamp('2017-06-19T12:09:10')])
data = data.append(more_data).sort_index()
I tried
data - model.interpolate()[data.index]
but that only gives me non-NaN values where the timestamps of the model and the data overlap.
I understand that I could resample the data to fit the frequency of the model () but I do want to have the data minus the model at the original timestamps of the data.