Compute the running max for a dataframe in pandas
<p>Given:</p>

<pre class="lang-py prettyprint-override"><code>d = {
    'High': [954,
             953,
             952,
             955,
             956,
             952,
             951,
             950,
            ]
}
df = pandas.DataFrame(d)
</code></pre>

<p>I want to add another column which is the max at each index from the beginning. For example the desired column would be:</p>

<pre class="lang-py prettyprint-override"><code>'Max': [954, 
        954, 
        954, 
        955, 
        956, 
        956, 
        956, 
        956]
</code></pre>

<p>I tried with a pandas rolling function but the window cannot be dynamic it seems</p>

<p>Use <code>cummax</code></p>

<pre><code>df.High.cummax()

0    954
1    954
2    954
3    955
4    956
5    956
6    956
7    956
Name: High, dtype: int64
</code></pre>

<hr>

<pre><code>df['Max'] = df.High.cummax()
df
</code></pre>

<p><a href="http://i.stack.imgur.com/IfnS4.png" rel="nofollow"><img src="http://i.stack.imgur.com/IfnS4.png" alt="enter image description here"></a></p>

python pandas