title: Get pandas items at selected intervals
body: <p>I am trying to find a faster way of selecting dates at varying intervals. Currently, I am looping through the data frame and then finding the required interval spans using <code>iloc</code>. The performance is causing a bottleneck though. The files are huge and there many of them, so any help welcome.</p>
  <pre><code>#example
  df = pd.DataFrame(pd.date_range(start='01/01/1980', end='01/01/2020'), columns=['DT'])
  
  n = 5
  spans = []
  max_len = len(df) - n
  for k in df.index:
      if k &lt; max_len:
          spans.append([df.iloc[k].DT, df.iloc[k + n].DT])
  </code></pre>
  <p>Is there a &quot;better&quot; way of doing this, i.e. faster. Thanks.</p>