title: Pandas: moving sum over time window with condition
body: <p>I have a data frame that contains boolean failures (with a timestamp) for specific machines. I'd like to add a column that performs a moving sum, for that specific machine, of all failures in a specific time frame relative to the timestamp. For example, calculating how many failures happened for each machine between 8 days and 1 day before the failure in the line.</p>
  
  <p>This creates an example of the initial dataframe:</p>
  
  <pre><code>import pandas as pd
  df1=pd.DataFrame({"Machine":["M0","M2","M3","M0","M2","M3"],"Failure":[0,0,1,1,1,1],"Date-time":["2014-02-20 11:00:19.0","2014-02-21 12:29:55.0","2014-02-20 11:00:21.0","2014-02-19 09:10:19.0","2014-02-18 12:19:47.0","2014-02-20 1:33:00.0"]})
  </code></pre>
  
  <p>This creates an example output dataframe:</p>
  
  <pre><code>df1=pd.DataFrame({"Machine":["M0","M2","M3","M0","M2","M3"],"Number of failures, d-8 to d-1":[1,1,0,0,0,0],"Failure":[0,0,1,1,1,1],"Date-time":["2014-02-20 11:00:19.0","2014-02-21 12:29:55.0","2014-02-20 11:00:21.0","2014-02-19 09:10:19.0","2014-02-18 12:19:47.0","2014-02-20 1:33:00.0"]})
  </code></pre>