title: Advanced Slicing of Intervals in Pandas Dataframe
body: <p>I need to slice several intervals out of one dataframe indexed with Freq: 120T. The start date of each of the desired intervals is given by a second dataframe indexed with Freq: None.  The idea is that I need to take each of those start dates and include a time and  # of periods to build each interval. The time attribute and the periods are the same for all intervals.</p>
  
  <p>Let's look at this mess with an example</p>
  
  <p>Say our start time is '18:00:00' and our # of periods is 3. The dataframe to be sliced is df1 and the dataframe that contains the start dates is df2.</p>
  
  <p>df1 </p>
  
  <pre><code>                      A   B     
  DateTime                                               
  2005-09-06 16:00:00   1   5  
  2005-09-06 18:00:00   2   6  
  2005-09-06 20:00:00   3   7  
  2005-09-06 22:00:00   4   8 
  2005-12-07 16:00:00   9   8  
  2005-12-07 18:00:00   7   6  
  2005-12-07 20:00:00   5   4  
  2005-12-07 22:00:00   3   2  
  
  &lt;class 'pandas.tseries.index.DatetimeIndex'&gt;
  [2005-09-06 16:00:00, ..., 2005-12-07 22:00:00]
  Length: 8, Freq: 120T, Timezone: None
  </code></pre>
  
  <p>df2 </p>
  
  <pre><code>             Num
  DateTime                                                                    
  2005-09-07     1
  2005-12-07     2
  
  &lt;class 'pandas.tseries.index.DatetimeIndex'&gt;
  [2005-09-07, 2005-12-07]
  Length: 2, Freq: None, Timezone: None
  </code></pre>
  
  <p>Desired Output:</p>
  
  <pre><code>df3 = func(source=df1['B'], start_dates=df2.index, time_start='18:00:00', periods=3)
  
             1   2
  18:00:00   6   6  
  20:00:00   7   4  
  22:00:00   8   2 
  </code></pre>
  
  <p>What have I done and considerations:</p>
  
  <p>One of the difficulties is that the data in df1 is in 120T frequency but is only business days. Taking this into account, I would do something like this:</p>
  
  <pre><code>start = df2.index[0]   ##  And somehow add to this formula the fact that we want to start at         
                             '18:00'
  df3 = df1['B'][(df1.index &gt; start) &amp; (df1.index &lt; start + 3)]  ##  Somehow iterate this over the 
                                                                     dates in the df2 index
  </code></pre>
  
  <p>I appreciate any insight</p>
  
  <p>Thanks in advance</p>