title: pandas rolling computation with window based on values instead of counts
body: <p>I'm looking for a way to do something like the various <code>rolling_*</code> functions of <code>pandas</code>, but I want the window of the rolling computation to be defined by a range of values (say, a range of values of a column of the DataFrame), not by the number of rows in the window.</p>
  
  <p>As an example, suppose I have this data:</p>
  
  <pre><code>&gt;&gt;&gt; print d
     RollBasis  ToRoll
  0          1       1
  1          1       4
  2          1      -5
  3          2       2
  4          3      -4
  5          5      -2
  6          8       0
  7         10     -13
  8         12      -2
  9         13      -5
  </code></pre>
  
  <p>If I do something like <code>rolling_sum(d, 5)</code>, I get a rolling sum in which each window contains 5 rows.  But what I want is a rolling sum in which each window contains a certain range of values of <code>RollBasis</code>.  That is, I'd like to be able to do something like <code>d.roll_by(sum, 'RollBasis', 5)</code>, and get a result where the first window contains all rows whose <code>RollBasis</code> is between 1 and 5, then the second window contains all rows whose <code>RollBasis</code> is between 2 and 6, then the third window contains all rows whose <code>RollBasis</code> is between 3 and 7, etc.  The windows will not have equal numbers of rows, but the range of <code>RollBasis</code> values selected in each window will be the same.  So the output should be like:</p>
  
  <pre><code>&gt;&gt;&gt; d.roll_by(sum, 'RollBasis', 5)
      1    -4    # sum of elements with 1 &lt;= Rollbasis &lt;= 5
      2    -4    # sum of elements with 2 &lt;= Rollbasis &lt;= 6
      3    -6    # sum of elements with 3 &lt;= Rollbasis &lt;= 7
      4    -2    # sum of elements with 4 &lt;= Rollbasis &lt;= 8
      # etc.
  </code></pre>
  
  <p>I can't do this with <code>groupby</code>, because <code>groupby</code> always produces disjoint groups.  I can't do it with the rolling functions, because their windows always roll by number of rows, not by values.  So how can I do it?</p>