I’d like to return all rows from a dataframe, tos
, for 5 minute intervals.
To start, I’m simply looping to allow space for processing the collected rows, but not opposed to vectorizing if it makes sense.
tos
Time TickType Price Size
0 2023-08-13 15:10:46.166268 1 4487.2500 1
1 2023-08-13 15:10:47.375489 1 4487.0000 1
2 2023-08-13 15:10:54.656049 1 4487.2500 2
3 2023-08-13 15:10:57.626667 1 4487.0000 1
4 2023-08-13 15:10:57.627504 1 4487.0000 1
... ... ... ...
380508 2023-08-14 13:59:59.504712 1 4506.5000 1
380509 2023-08-14 13:59:59.504954 1 4506.5000 1
380510 2023-08-14 13:59:59.505058 1 4506.7500 14
380511 2023-08-14 14:00:00.107130 1 4506.7500 8
380512 2023-08-14 14:00:00.107344 1 4506.5000 1
Starting here to debug:
import pandas as pd
st = datetime.datetime(2023,8,13,15,10)
end = datetime.datetime(2023,8,14,14,00)
int_range = pd.date_range(st, end, freq='5min', inclusive='both')
for i, k in enumerate(int_range):
a = tos.set_index('Time').between_time(k, int_range[i+1])
print(a)
Which gives the following error:
ValueError: Cannot convert arg [Timestamp('2023-08-13 15:10:47.284558', freq='5T')] to a time
Is there a better approach to doing this and how to get around the error?
5