I need some help in binning my data values. Need a histogram-like function, but I don't want to list the occurrences, just the sum of the values for each bin.
In my example below I have a list with the number of Twitter followers for 30 days. Lets say I want 10 bins, then each bin would take the values of 30 / 10 = 3 days. For the first three days the value for bin 1 would be 1391 + 142 + 0 = 1533 for bin 2 12618, etc., up to bin 10.
The number of bins as well as the duration could eventually be varied. It also needs to work for a duration of 31 days and 5 bins, for instance.
Anyone knows how to do this efficiently? Is there a Python function available that could do this? Otherwise an implementation of a for loop that is able to sum n number of values in a list together until end of duration.
All help would be highly appreciated :) Thanks!
followersList = [1391, 142, 0, 0, 12618, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 456, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
duration = 30
bins = 10
binWidth = round(duration / bins)
#
# for loop or python function that sums values for each bin
#