Does pandas / scipy / numpy have a cumulative standard deviation function?

I have a pandas series. I need to get sigma_i, which is the standard deviation of the series to index i. Is there any existing function that efficiently calculates this?

I noticed that there are cummax, cummin functions.

+5
python numpy scipy pandas
Jun 23 '14 at 15:24
source share
2 answers

See pandas.expanding_std .

eg:

 import numpy as np import matplotlib.pyplot as plt import pandas %matplotlib inline data = pandas.Series(np.random.normal(size=37)) full_std = np.std(data) expand_std = pandas.expanding_std(data, min_periods=1) fig, ax = plt.subplots() expand_std.plot(ax=ax, color='k', linewidth=1.5, label='Expanded Std. Dev.') ax.axhline(y=full_std, color='g', label='Full Value') ax.legend() 

Edit: oops, forgot the picture:

enter image description here

+9
Jun 23 '14 at 17:01
source share

This also works:

 data.expanding(min_periods=1).std() 

Where the data is an instance of pd.Series ().

0
Nov 29 '17 at 2:38 on
source share



All Articles