sum function

Ramchandra Apte maniandram01 at gmail.com
Fri Oct 5 09:41:43 EDT 2012


On Friday, 5 October 2012 19:09:15 UTC+5:30, Mike  wrote:
> On Thursday, October 4, 2012 4:52:50 PM UTC-4, Mike wrote:
> 
> > Hi All,
> 
> > 
> 
> > 
> 
> > 
> 
> > I am new to python and am getting the data from hbase. 
> 
> > 
> 
> > I am trying to do sum on the column as below
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > 
> 
> > scanner = client.scannerOpenWithStop("tab", "10", "1000", ["cf:col1"])
> 
> > 
> 
> > total = 0.0
> 
> > 
> 
> > r = client.scannerGet(scanner)
> 
> > 
> 
> > while r:
> 
> > 
> 
> >   for k in (r[0].columns):
> 
> > 
> 
> >     total += float(r[0].columns[k].value)
> 
> > 
> 
> >   r = client.scannerGet(scanner)
> 
> > 
> 
> > 
> 
> > 
> 
> > print total
> 
> > 
> 
> > 
> 
> > 
> 
> > Do you know of better (faster) way to do sum?
> 
> > 
> 
> > 
> 
> > 
> 
> > Any thoughts please?
> 
> > 
> 
> > 
> 
> > 
> 
> > Thanks
> 
> 
> 
> Sorry about that. Here you go
> 
> 
> 
> Traceback (most recent call last):
> 
>   File "test.py", line 17, in <module>
> 
>     total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues())
> 
>   File "test.py", line 17, in <genexpr>
> 
>     total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues())
> 
> IndexError: list index out of range

the variable "r" is an empty list



More information about the Python-list mailing list