You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
solved problems of:
(a) calling functions dynamically [use getattr(()]
(b) dynamic storage of results [dict of dataframes]
(c) dynamic updates of scalars [dict of dicts - like a multi-level struct]
Output=pd.DataFrame(columns= ['Alpha', 'Beta', 'MAPprobability', 'Precision']) # empty Dataframe to input data into
29
28
29
+
#%% initialise storage
30
+
Output_collection= {} # empty dict in which to store dataframes
31
+
event_totals= {} # empty dict to store totals of events for each strategy
32
+
# initialise dataframes
33
+
forindex_strategyinrange(len(strategies)):
34
+
Output_collection[strategies[index_strategy]] =pd.DataFrame(columns= ['Alpha', 'Beta', 'MAPprobability', 'Precision']) # empty Dataframe to input data into
35
+
event_totals[strategies[index_strategy]] = {}; # create empty dict for this strategy
# store results - dynamically-defined dataframe...
58
+
new_row= {'Alpha':Alpha, 'Beta':Beta, 'MAPprobability':MAPprobability, 'Precision':precision} # create new row for dataframe as a dict
59
+
new_df=pd.DataFrame([new_row]) # have to convert to dataframe to use concat!!
60
+
Output_collection[strategies[index_strategy]] =pd.concat([Output_collection[strategies[index_strategy]], new_df], ignore_index=True) # add new row to dataframe
61
+
62
+
#%% plot results
63
+
# plotting time series of MAPprobability
64
+
plt.figure(figsize=(10, 5))
65
+
plt.plot(Output_collection['go_right'].MAPprobability, linewidth=0.75) # plots the time series
0 commit comments