Is there a vectorized operation to calculate the cumulative and rolling standard deviation (SD) of a Python DataFrame?
For example, I want to add a column 'c' which calculates the cumulative SD based on column 'a', i.e. in index 0, it shows NaN due to 1 data point, and in index 1, it calculates SD based on 2 data points, and so on.
The same question goes to rolling SD too. Is there an efficient way to calculate without iterating through df.itertuples()?
import numpy as np
import pandas as pd
def main():
np.random.seed(123)
df = pd.DataFrame(np.random.randn(10, 2), columns=['a', 'b'])
print(df)
if __name__ == '__main__':
main()