I have a list of date which I create using the function date_range
of pandas. In that list, there are dates from 01 January 2019 00:00:00
to 31 December 2019 00:00:00
. Now there is gap of 15 mins in each time interval, so in a day there will be a total of 96 15mins blocks((24*60)/15). So list will be like:
modelStartDate = "01/01/2019"
modelEndDate = "31/12/2019"
interval = 15
dateTime = pd.date_range(start=modelStartDate, end=modelEndDate, freq=str(interval) + 'min')
print(dateTime)
output:
DatetimeIndex(['2019-01-01 00:00:00', '2019-01-01 00:15:00',
'2019-01-01 00:30:00', '2019-01-01 00:45:00',
'2019-01-01 01:00:00', '2019-01-01 01:15:00',
'2019-01-01 01:30:00', '2019-01-01 01:45:00',
'2019-01-01 02:00:00', '2019-01-01 02:15:00',
...
'2019-12-30 21:45:00', '2019-12-30 22:00:00',
'2019-12-30 22:15:00', '2019-12-30 22:30:00',
'2019-12-30 22:45:00', '2019-12-30 23:00:00',
'2019-12-30 23:15:00', '2019-12-30 23:30:00',
'2019-12-30 23:45:00', '2019-12-31 00:00:00'],
dtype='datetime64[ns]', length=34945, freq='15T')
So I am doing some calculations which requires some counters and what I want to do is that I want to reset the counter on every new day. So do this task I have two ways: first, where I can simply divide the list into 96 blocks and reset the counter after every 96th block and second, I want to go through this list and see in actual when is the new days and reset the counter only when the it found that there is a new day. first approach:
modelStartDate = "01/01/2019"
modelEndDate = "31/12/2019"
interval = 15
dateTime = pd.date_range(start=modelStartDate, end=modelEndDate, freq=str(interval) + 'min')
for i in range(len(dateTime)):
if i % 96 == 0:
print("new date at ", i)
second approach: I don't know how to approach that. So can someone please help. In the desired output I don't want anything particular, just can simply tell that that's the new date on a new day. So after every 96th block output will look like:
new date: 02/01/2019 00:00:00
new date: 03/ 01/2019 00:00:00
and so on