Function to calculate value from first row in Python Pandas
<p>Is there any function in pandas to simulate excel formula like '=sum($A$1:A10'(for 10th row), i.e. the formula should take rolling data from 1st row.</p>

<p>Pandas rolling function needs a integer value as window argument.</p>

<p>The equivalent of <code>=SUM($A$1:A1)</code> in pandas is <code>.expanding().sum()</code> (requires pandas 0.18.0):</p>

<pre><code>ser = pd.Series([1, 2, 3, 4])

ser
Out[3]: 
0    1
1    2
2    3
3    4
dtype: int64

ser.expanding().sum()
Out[4]: 
0     1.0
1     3.0
2     6.0
3    10.0
</code></pre>

<p>You can also apply a generic function via apply:</p>

<pre><code>ser.expanding().apply(lambda x: np.percentile(x, 90))
Out: 
0    1.0
1    1.9
2    2.8
3    3.7
dtype: float64
</code></pre>

<p>Or directly with quantile:</p>

<pre><code>ser.expanding().quantile(0.9)
Out[15]: 
0    1.0
1    1.0
2    2.0
3    3.0
dtype: float64
</code></pre>

<p>Note that 90th percentile is equal to 0.9th quantile. However, Series.quantile and Series.expanding.quantile are returning different results which is probably <a href="https://github.com/pydata/pandas/issues/8084" rel="nofollow">a bug</a>.</p>

<p>np.percentile returns the same results as Excel's PERCENTILE.INC. For PERCENTILE.EXC, I've previously wrote a small function <a href="http://stackoverflow.com/a/38597798/2285236">here</a>.</p>

python pandas numpy