I am trying to optimize this block of slicing
for row in tempDF.itertuples(index=True):
# x and y come from somewhere else
tp = tempDF.iloc[x:y]
# created a vector of boolean based on
# https://datascience.stackexchange.com/questions/23264/
condition = (
(tp['date_minute'].dt.date == row.Index.date()) &
(tp['date_minute'] > row.Index) &
(pd.Timestamp('10:30').time() <= tp['date_minute'].dt.time) &
(tp['date_minute'].dt.time <= pd.Timestamp('17:35').time())
)
sliced = tp[condition]
Using the line_profiler
extension, about 17 % of the code execution time, of a larger piece, is spent on the condition
line. This is equivalent to about 2 seconds. As you can imagine, altogether the execution time is 12 seconds for a dataframe of 30,000 rows so I am trying to optimize as much as possible.
Is there a way of reducing the time spent in this block?
Thanks.