title: How to get rolling pandas dataframe subsets
body: <p>I would like to get dataframe subsets in a "rolling" manner.
  I tried several things without success, here is an example of what I would like to do. Let's consider dataframe.</p>
  
  <pre><code>df
       var1      var2
  0    43         74
  1    44         74
  2    45         66
  3    46        268
  4    47         66
  </code></pre>
  
  <p>I would like to create a new column with the following function which performs a conditional sum:</p>
  
  <pre><code>def func(x):
      tmp = (x["var1"] * (x["var2"] == 74)).sum()
      return tmp
  </code></pre>
  
  <p>and calling it like this</p>
  
  <pre><code>df["newvar"] = df.rolling(2, min_periods=1).apply(func)
  </code></pre>
  
  <p>That would mean that the function would be applied on dataframe basis, and not for each row or column</p>
  
  <p>It would return</p>
  
  <pre><code>     var1      var2      newvar
  0    43         74         43          # 43
  1    44         74         87          # 43 * 1 + 44 * 1
  2    45         66         44          # 44 * 1 + 45 * 0
  3    46        268         0           # 45 * 0 + 46 * 0
  4    47         66         0           # 46 * 0 + 47 * 0
  </code></pre>
  
  <p>Is there a pythonic way to do this?
  This is just an example but the condition (always based on the sub-dataframe values depends on more than 2 columns.</p>