Issue
I got this date range:
import pandas as pd
import datetime as dt
date = '2020-09-01 10:00:00'
date_range = pd.date_range(date, freq='60min', periods=5)
Out:
DatetimeIndex(['2020-09-01 10:00:00', '2020-09-01 11:00:00',
'2020-09-01 12:00:00', '2020-09-01 13:00:00',
'2020-09-01 14:00:00'],
dtype='datetime64[ns]', freq='60T')
I want to keep follow this specific sequence of hours but changing the dates for an year. Something like that:
DatetimeIndex(['2020-09-01 10:00:00', '2020-09-01 11:00:00',
'2020-09-01 12:00:00', '2020-09-01 13:00:00',
'2020-09-01 14:00:00', '2020-09-02 10:00:00',
'2020-09-02 11:00:00', '2020-09-02 12:00:00',
'2020-09-02 13:00:00', '2020-09-02 14:00:00'
'...', '2021-09-01 10:00:00',
'2021-09-01 11:00:00', '2021-09-01 12:00:00',
'22021-09-01 13:00:00', '2021-09-01 14:00:00'],
dtype='datetime64[ns]', freq='60T')
Solution
Use two date_range
:
date = "2020-09-01 10:00:00"
date_range = list()
for dt in pd.date_range(date, periods=365, freq="D"):
date_range += pd.date_range(dt, freq="60min", periods=5)
Answered By - not_speshal
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.