I have a Pandas series. I need to get sigma_i, which is the standard deviation of a series up to index i
. Is there an existing function which efficiently calculates that?
I noticed that there are the cummax and cummin functions.
I have a Pandas series. I need to get sigma_i, which is the standard deviation of a series up to index i
. Is there an existing function which efficiently calculates that?
I noticed that there are the cummax and cummin functions.
See pandas.expanding_std
.
For instance:
import numpy as np
import matplotlib.pyplot as plt
import pandas
%matplotlib inlinedata = 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()