title: Get sum of row differences with Pandas .diff()
body: <p>I am doing a time-series analysis where I need to calculate the change in several attributes over time. Pandas makes a simple version of this easy; the .diff(periods=n) function will calculate the difference between a row and the preceding n rows, however, that is not <em>quite</em> what I need...</p>
  <pre><code>df= pd.DataFrame({'day_num': [134, 135, 136, 137],
                      'swe': [38.8, 38.9, 37.6, 36.8],
                       'prcp': [0., 0.1, 0., 0.15],
                       'flow': [2930, 3350, 3900, 4090]})
  
  diff_3 = df.diff(periods=3)
  </code></pre>
  <p>returns:</p>
  <pre><code>   day_num   swe  prcp  flow
  0      134  38.8  0.00  2930
  1      135  38.9  0.00  3350
  2      136   37.6  0.00  3900
  3      137  36.8  0.15  4090
  </code></pre>
  <p>And:</p>
  <pre><code>  day_num  swe  prcp    flow
  0      NaN  NaN   NaN     NaN
  1      NaN  NaN   NaN     NaN
  2      NaN  NaN   NaN     NaN
  3      3.0 -2.0  0.15  1160.0
  </code></pre>
  <p>In the swe column(snow water equivalent in inches, literally the liquid water equivalent of a particular snowpack) , the 3 day difference for index 3 is -2.0, which equals 36.8 - 38.8. However, notice that there was an increase and decrease within the 3 day period. This means that a total of 2.1 inches (my desired output) of water melted and contributed to  streamflow (flow column) over that 3 day window. Min - max would not work either, because if I were to increase the n value to 7 or 14, there could easily be 'meltings' that are not accounted for in the output. What is needed is the sum of the single day differences over a span of n days. I eventually want to merge the diff_n columns back into the original dataset.</p>
  <p>Any ideas would be appreciated. Also, this is my first post so let me know how I can improve my format / content...</p>