Python dataframe sum rows
<p>If I have a dataframe with <code>n</code> rows, is there a way to set the ith row to be sum of <code>row[i]</code> and <code>row[i-1]</code> and do this so that the assignment to earlier rows is reflected in the latter rows? I would really like to avoid loops if possible.</p>

<p>Example DF:</p>

<pre><code>             SPY   AAPL   GOOG
2011-01-10  0.44  -0.81   1.80
2011-01-11  0.00   0.00   0.00
2011-01-12 -1.11  -2.77  -0.86
2011-01-13 -0.91  -4.02  -0.68
</code></pre>

<p>Sample pseudo code of summing two rows:</p>

<pre><code>DF[2011-01-11] = DF[2011-01-10] + DF[2011-01-11]
DF[2011-01-12] = DF[2011-01-11] + DF[2011-01-12]
</code></pre>

<p>and so on.</p>

<p>Use <code>DF.shift()</code></p>

<pre><code>DF + DF.shift()
</code></pre>

python pandas dataframe