I have a data with two columns as shown below. i am trying to estimate a standard deviation of the second column for each of the values of the first column. So 284, 285 and 286 values should have their consecutive standard deviation values.
284 4
284 9
284 6
285 0
285 1
285 3
286 9
286 3
286 1
I managed to calculate the running sum, but am stuck on the mean value calculation. Here is my code so far:
b = [(line.split("\t")) for line in data]
sums = [(sum(float(v) for k, v in g)) for k, g in groupby(b, key=itemgetter(0))]
lens = [(len(float(v) for k, v in g)) for k, g in groupby(b, key=itemgetter(0))]
sums
works fine and calculates the summation per each change of the first column, however len()
does not work and crashes with message:
TypeError: object of type 'generator' has no len()
Has anyone faced this before?