I bootstrapped a few hundred scenarios, and I’d like to assess the convergence of Mean and Standard Deviation over the runtime of the scenarios, if that makes sense.
Basically, I have a dataframe ordered by Scenario, with a column Value. I’d like to take the mean and std for each cell of the dataframe starting from scenario 0 and running up to the current scenario.
Here is sample code:
import pandas as pd
from io import StringIO
scenario_data = u"""
Value, Scenario
10, 000
15, 001
12, 002
9, 003
13, 004
8, 005
3, 006
11, 007
10, 008
9, 009
"""
df = pd.read_csv(StringIO(scenario_data))
And these are the results I want (rounded for this post):
Value, Scenario, Running Mean, Running StD
10, 000, 10, 0
15, 001, 12.5, 3.54 # Running Mean = (10+15)/2, similar formula for StD
12, 002, 12.33, 2.52 # Running Mean = (10+15+12)/3, etc
9, 003, 11.5, 2.65
13, 004, 11.8, 2.40
8, 005, 11.17, 2.64
3, 006, 10, 3.92
11, 007, 10.13, 3.64
10, 008, 10.11, 3.41
9, 009, 10, 3.23
Ideally, I would like to plot the mean and std as line graphs, as well, but that’s the easy part.