I have two datetimes between which I would like to generate regular intervals of 4 hours (excluding the last interval, which can be less than 4 hours if there are less than 4 hours between the previous timestamp and end).
I am stuck on interval generation with pandas.date_range, which only returns the end timestamp. For example:
import pandas
from datetime import datetime
start = datetime(2021, 4, 2, 20, 40, 0)
end = datetime(2021, 4, 4, 18, 20, 0)
dates = pandas.date_range(start=end, end=end, freq='4H')
dates
DatetimeIndex(['2021-04-04 18:20:00'], dtype='datetime64[ns]', freq='4H')
The aim is to generate a list of datetime pairs such as:
[['2021-04-02 20:40:00', '2021-04-03 00:40:00'], ['2021-04-03 00:40:00', '2021-04-03 04:40:00']...['2021-04-04 16:40:00', '2021-04-04 18:20:00']] #last pair can be cut off by `end`.
What am I doing wrong in the syntax and how would one go about generating a paired list of intervals from using pandas.date_range ?