0

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')
Naj_m_Om
  • 33
  • 6
  • Do you think [this](https://stackoverflow.com/a/36684166/4365143) answer your question? – taipei May 29 '22 at 03:53
  • I did apply resample method, but it doesn’t produce 1 hour a head. It produces 5 minutes time frame on the same length of the data – Naj_m_Om May 29 '22 at 21:17

1 Answers1

0

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
ArchAngelPwn
  • 2,891
  • 1
  • 4
  • 17
  • I appreciate your response, I will test this and update you with my results. Thanks – Naj_m_Om May 29 '22 at 20:44
  • I worked not the way I need it. I need 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'! any suggestion! – Naj_m_Om May 30 '22 at 13:05
  • I'm not sure I understand the problem since you do not have any mention of '2022-04-26 15:02:00+00:00' in your data set. Could you update your post to include some expected results? – ArchAngelPwn May 30 '22 at 13:13
  • sure I will! by the way, In your previous suggestion, the needed time interval is produced, but it was included in the overlapping range – Naj_m_Om May 30 '22 at 13:23
  • Date Fast_Forward_One_Hour 40 2022-04-26 14:22:00+00:00 2022-04-26 15:22:00+00:00 41 2022-04-26 14:27:00+00:00 2022-04-26 15:27:00+00:00 42 2022-04-26 14:32:00+00:00 2022-04-26 15:32:00+00:00 43 2022-04-26 14:37:00+00:00 2022-04-26 15:37:00+00:00 44 2022-04-26 14:42:00+00:00 2022-04-26 15:42:00+00:00 45 2022-04-26 14:47:00+00:00 2022-04-26 15:47:00+00:00 46 2022-04-26 14:52:00+00:00 2022-04-26 15:52:00+00:00 47 2022-04-26 14:57:00+00:00 2022-04-26 15:57:00+00:00 – Naj_m_Om May 30 '22 at 13:28
  • I was trying to include the result but it is too long – Naj_m_Om May 30 '22 at 13:29
  • You need to edit your original post to include everything – ArchAngelPwn May 30 '22 at 13:30
  • yes, I have done that – Naj_m_Om May 30 '22 at 13:33