I have a dictionary of dictionaries where the keys of the inner dictionary represents bins of a histogram and the values represent the frequency. I want to calculate the mean bin and the std of the bins.
dict = {'Group 1' : {1 : 100, 2:300, 4:100, 5:50},
{'Group 2' : {1 : 50, 2: 300},
{'Group 3' : {4 : 100, 5: 200},
...}
Example
For Group 1
I want to get the mean and std identical to taking the mean and std of a list of 100 1's, 300 2's, 100 4's, 50 5's
l = []
l.extend([1 for j in range(0,100)])
l.extend([2 for j in range(0,300)])
l.extend([4 for j in range(0,100)])
l.extend([5 for j in range(0,50)])
np.mean(l) = 2.45
np.std(l) = 1.23
What would be the best way to iterate over each dictionary and transform it such that I get a dictionary of dictionaries representing the mean and std of the bins of the inner dictionaries?
transformed_dictionary = {'Group 1' : {'mean': 2.45 , 'std' : 1.23},
'Group 2' : {...},
...}
What could be an efficient way of doing this?