sum function

Mike mike20007 at gmail.com
Fri Oct 5 09:39:15 EDT 2012


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



More information about the Python-list mailing list