Building Time Based Bins

Michael Spencer mahs at telcopartners.com
Mon Mar 21 19:44:53 EST 2005


MCD wrote:
> Thanks Alessandro... I'll have to try that as well.
> 
> I have a modified working version of John's code (thanks John!). I'm
> able to output the bins by 5min intervals, sum one of the fields, and
> get the high and low of each field. So far I'm really happy with how it
> works. Thank you to everybody.
> 
> The only thing that I'd like to do, which I've been racking my brain on
> how to do in python... is how to keep track of the bins, so that I can
> refer back to them. For instance, if I wanted to get "binlo" from two
> bins back... in the scripting language I was working with (pascal
> based) you could create a counting series:
> 
> for binlo = binlo - 1 do
> begin
> 
>  2binlosBack = (binlo - 2)
> 
>     # if it was 12:00, I'd be looking back to 11:50
> 
> I would really appreciat if anyone could explain to me how this could
> be accomplished using python grammar... or perhaps some other method
> "look back" which I'm unable to conceive of.
> 
> Many thanks,
> Marcus
> 
Just append the results to a list as you go:
bins = []

for bin in ... # whichever method you use to get each new bin
     bins.append(bin)

Then refer to previous bins using negative index (starting at -1 for the most 
recent):
e.g., 2binlosBack  = bins[-3]

Michael





More information about the Python-list mailing list