Home > database >  Time delta applying to time series data
Time delta applying to time series data

Time:05-31

I need to produce one hour ahead of this data in a 5-minutes timeframe. I applied

timeAhead = times[-1]   pd.Timedelta(1, unit='hour')  
timeAhead

the outcome here is the last time step: Timestamp('2022-04-26 15:57:00 0000', tz='UTC', freq='300S')

However, I could not find a way to produce the 5 minutes range. the targeted results is on the one hour ahead to be started after '2022-04-26 14:57:00 00:00' like : '2022-04-26 15:02:00 00:00', '2022-04-26 15:07:00 00:00','2022-04-26 15:12:00 00:00'............'2022-04-26 15:57:00 00:00'!

DatetimeIndex(['2022-04-26 11:02:00 00:00', '2022-04-26 11:07:00 00:00',
                   '2022-04-26 11:12:00 00:00', '2022-04-26 11:17:00 00:00',
                   '2022-04-26 11:22:00 00:00', '2022-04-26 11:27:00 00:00',
                   '2022-04-26 11:32:00 00:00', '2022-04-26 11:37:00 00:00',
                   '2022-04-26 11:42:00 00:00', '2022-04-26 11:47:00 00:00',
                   '2022-04-26 11:52:00 00:00', '2022-04-26 11:57:00 00:00',
                   '2022-04-26 12:02:00 00:00', '2022-04-26 12:07:00 00:00',
                   '2022-04-26 12:12:00 00:00', '2022-04-26 12:17:00 00:00',
                   '2022-04-26 12:22:00 00:00', '2022-04-26 12:27:00 00:00',
                   '2022-04-26 12:32:00 00:00', '2022-04-26 12:37:00 00:00',
                   '2022-04-26 12:42:00 00:00', '2022-04-26 12:47:00 00:00',
                   '2022-04-26 12:52:00 00:00', '2022-04-26 12:57:00 00:00',
                   '2022-04-26 13:02:00 00:00', '2022-04-26 13:07:00 00:00',
                   '2022-04-26 13:12:00 00:00', '2022-04-26 13:17:00 00:00',
                   '2022-04-26 13:22:00 00:00', '2022-04-26 13:27:00 00:00',
                   '2022-04-26 13:32:00 00:00', '2022-04-26 13:37:00 00:00',
                   '2022-04-26 13:42:00 00:00', '2022-04-26 13:47:00 00:00',
                   '2022-04-26 13:52:00 00:00', '2022-04-26 13:57:00 00:00',
                   '2022-04-26 14:02:00 00:00', '2022-04-26 14:07:00 00:00',
                   '2022-04-26 14:12:00 00:00', '2022-04-26 14:17:00 00:00',
                   '2022-04-26 14:22:00 00:00', '2022-04-26 14:27:00 00:00',
                   '2022-04-26 14:32:00 00:00', '2022-04-26 14:37:00 00:00',
                   '2022-04-26 14:42:00 00:00', '2022-04-26 14:47:00 00:00',
                   '2022-04-26 14:52:00 00:00', '2022-04-26 14:57:00 00:00'],
                  dtype='datetime64[ns, UTC]', freq='300S')

CodePudding user response:

This will give you another column that is 1 hour ahead of the dates you provided.

data = {'Date' : ['2022-04-26 11:02:00 00:00', '2022-04-26 11:07:00 00:00',
                   '2022-04-26 11:12:00 00:00', '2022-04-26 11:17:00 00:00',
                   '2022-04-26 11:22:00 00:00', '2022-04-26 11:27:00 00:00',
                   '2022-04-26 11:32:00 00:00', '2022-04-26 11:37:00 00:00',
                   '2022-04-26 11:42:00 00:00', '2022-04-26 11:47:00 00:00',
                   '2022-04-26 11:52:00 00:00', '2022-04-26 11:57:00 00:00',
                   '2022-04-26 12:02:00 00:00', '2022-04-26 12:07:00 00:00',
                   '2022-04-26 12:12:00 00:00', '2022-04-26 12:17:00 00:00',
                   '2022-04-26 12:22:00 00:00', '2022-04-26 12:27:00 00:00',
                   '2022-04-26 12:32:00 00:00', '2022-04-26 12:37:00 00:00',
                   '2022-04-26 12:42:00 00:00', '2022-04-26 12:47:00 00:00',
                   '2022-04-26 12:52:00 00:00', '2022-04-26 12:57:00 00:00',
                   '2022-04-26 13:02:00 00:00', '2022-04-26 13:07:00 00:00',
                   '2022-04-26 13:12:00 00:00', '2022-04-26 13:17:00 00:00',
                   '2022-04-26 13:22:00 00:00', '2022-04-26 13:27:00 00:00',
                   '2022-04-26 13:32:00 00:00', '2022-04-26 13:37:00 00:00',
                   '2022-04-26 13:42:00 00:00', '2022-04-26 13:47:00 00:00',
                   '2022-04-26 13:52:00 00:00', '2022-04-26 13:57:00 00:00',
                   '2022-04-26 14:02:00 00:00', '2022-04-26 14:07:00 00:00',
                   '2022-04-26 14:12:00 00:00', '2022-04-26 14:17:00 00:00',
                   '2022-04-26 14:22:00 00:00', '2022-04-26 14:27:00 00:00',
                   '2022-04-26 14:32:00 00:00', '2022-04-26 14:37:00 00:00',
                   '2022-04-26 14:42:00 00:00', '2022-04-26 14:47:00 00:00',
                   '2022-04-26 14:52:00 00:00', '2022-04-26 14:57:00 00:00']}
df = pd.DataFrame(data)
df['Date'] = pd.to_datetime(df['Date'], infer_datetime_format=True)
df['Fast_Forward_One_Hour'] = df['Date']   datetime.timedelta(hours = 1)
df
  • Related