I have a pandas dataframe which is sorted by a date column. However I wish to ensure a minimum time interval between observations. Say for simplicity this window is 10 minutes, what this means is that if my first observation occurred at 8:05 AM then the second observation must occur at at least 8:15 AM. Any observations occurring between 8:05-8:15 AM must be dropped from the dataframe. Say without loss of generality that after dropping observations the second observation occurs at 8:17 AM. Then all observations between 8:17-8:27 AM are dropped to find the third data point and this process continues.
I have a script which works but iterates over the rows one at a time and is excruciatingly slow as the dataframe has hundreds of thousands of rows. My current script (window is the minimum threshold in minutes):
cur_time = df.iloc[0].Date

for idx, row in df[1:].iterrows():

time_diff = (row.Date - cur_time).total_seconds()

if time_diff > window*60:

    cur_time = row.Date

else:

    trades_df.drop(idx, inplace=True)

Can anyone think of a more speed optimized way of doing this operation? If I switch to the Date column as the index are there functions readily available for performing this function?
Edit: After doing further research the function that I'm looking for is similar to df.resample(window + 'M').first(). However the issue with using this is that my data set is sparsely spaced. I.e. I don't have data for every minute, the gap between data points could be 1 second or it could be 1 month.

Ensuring a minimum time interval between successive observations in a Pandas dataframe
With your condition mentioned in comments, I think you can't vectorize whole code. However, you can browse through the dataset faster:
window = 10
# convert date as numpy array (in seconds)
arr = df['Date'].values.astype(float) / 1e9
# compute dense matrix using numpy broadcasting
m = arr - arr[:, None] > window * 60
locs = []  # list of valid observations
idx = 0  # first date is always valid

while True:
    # append the current observation
    locs.append(idx)
    if m[idx].sum() == 0:
        # no more observations to check
        break
    # next valid observation
    idx = np.argmax(m[idx])

out = df.iloc[locs]

Output:
>>> out
                  Date
0  2023-06-01 00:02:10
3  2023-06-01 00:14:20
8  2023-06-01 00:24:42
11 2023-06-01 00:35:35
13 2023-06-01 00:48:39

>>> locs
[0, 3, 8, 11, 13]

Minimal Reproducible Example:
import numpy as np
import pandas as pd

np.random.seed(42)
offsets = pd.to_timedelta(np.random.randint(0, 60*60, 20), unit='S')
df = (pd.DataFrame({'Date': pd.Timestamp('2023-06-01') + offsets})
        .sort_values('Date', ignore_index=True))
print(df)

# Output
                  Date
0  2023-06-01 00:02:10  # OK, first value is always valid
1  2023-06-01 00:05:30
2  2023-06-01 00:07:46
3  2023-06-01 00:14:20  # OK, 00:02:10 + 10min < 00:14:20
4  2023-06-01 00:18:15
5  2023-06-01 00:18:50
6  2023-06-01 00:20:38
7  2023-06-01 00:21:34
8  2023-06-01 00:24:42  # OK, 00:14:20 + 10min < 00:24:42
9  2023-06-01 00:27:18
10 2023-06-01 00:28:05
11 2023-06-01 00:35:35  # OK, 00:24:42 + 10min < 00:35:35
12 2023-06-01 00:36:09
13 2023-06-01 00:48:39  # OK, 00:35:35 + 10min < 00:48:39
14 2023-06-01 00:51:32
15 2023-06-01 00:52:51
16 2023-06-01 00:52:54
17 2023-06-01 00:56:20
18 2023-06-01 00:57:24
19 2023-06-01 00:58:27

