How To Do Backward Resampling On Time Series Data Starting From The Last Row?
I have rows of data (per second) that I used to resample by two hour, and for each feature I applied different calculation, in short: data = data.resample('2H').agg({'id':'first','
Solution 1:
You can do this by applying a transformation to your time stamp, resampling on the transformed index and then reverting the transformation.
end_time = data.index[-1]
data['time to end'] = end_time - data.index
data.set_index('time to end', inplace=True)
data = data.resample('2h').mean() # Or your function
data['datetime'] = end_time - data.index
data.set_index('datetime', inplace=True)
Solution 2:
This was driving me crazy too. I kept feeling like resample should just do what I wanted. Ultimately I got it to work by using the origin parameter.
periods = pd.date_range("2020-10-17 15:53:03", "2020-10-17 15:56:56", freq="1s")
ts = pd.Series(range(len(periods)), index=periods)
resampled = ts.resample('60s', origin=ts.index[-1], closed='right', label='right')
Post a Comment for "How To Do Backward Resampling On Time Series Data Starting From The Last Row?"