title: Python Pandas rolling sum operation for subset of dataframe
body: <p>This is best explained through an example.</p>
  
  <p>I have the following dataframe (each row can be thought of as a transaction): </p>
  
  <pre><code>DATE        AMOUNT
  2017-01-29  10 
  2017-01-30  20
  2017-01-31  30
  2017-02-01  40
  2017-02-02  50
  2017-02-03  60
  </code></pre>
  
  <p>I would like to compute a 2-day rolling sum but only for rows in February.</p>
  
  <p>Code snippet I have currently:</p>
  
  <p><code>df.set_index('DATE',inplace=True)</code></p>
  
  <p><code>res=df.rolling('2d')['AMOUNT'].sum()</code></p>
  
  <p>which gives:</p>
  
  <pre><code>            AMOUNT 
  2017-01-29  10 
  2017-01-30  30 
  2017-01-31  50 
  2017-02-01  70 
  2017-02-02  90 
  2017-02-03  110
  </code></pre>
  
  <p>but I really only need the output in the last 3 rows, the operations on the first 3 rows are unnecessary. When the dataframe is huge, this incurs immense time complexity. How do I compute the rolling sum only for the last 3 rows (other than computing the rolling sum for all rows and then doing a row filtering operation after that)?</p>
  
  <p>*I cannot pre-filter the dataframe either because there wouldn't be the 'lookback' period in January for the correct rolling sum value to be obtained.</p>