Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #30815

Re: sum function

Newsgroups comp.lang.python
Date 2012-10-05 06:41 -0700
References <7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com> <12a372ba-8809-4fff-bca5-55a03e61ca82@googlegroups.com>
Message-ID <04412893-e6ba-43cc-8d9c-7867f82af4d1@googlegroups.com> (permalink)
Subject Re: sum function
From Ramchandra Apte <maniandram01@gmail.com>

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

sum function mike20007@gmail.com - 2012-10-04 13:52 -0700
  Re: sum function Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-04 15:04 -0600
    Re: sum function Mike <mike20007@gmail.com> - 2012-10-04 14:31 -0700
    Re: sum function Mike <mike20007@gmail.com> - 2012-10-04 14:31 -0700
  Re: sum function Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-04 15:05 -0600
    Re: sum function Mike <mike20007@gmail.com> - 2012-10-04 14:29 -0700
      Re: sum function Dave Angel <d@davea.name> - 2012-10-04 17:39 -0400
        Re: sum function Mike <mike20007@gmail.com> - 2012-10-04 17:40 -0700
          Re: sum function Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-04 18:59 -0600
            Re: sum function Mike <mike20007@gmail.com> - 2012-10-04 19:01 -0700
              Re: sum function Ramchandra Apte <maniandram01@gmail.com> - 2012-10-05 01:31 -0700
              Re: sum function Ramchandra Apte <maniandram01@gmail.com> - 2012-10-05 01:31 -0700
            Re: sum function Mike <mike20007@gmail.com> - 2012-10-04 19:01 -0700
        Re: sum function Mike <mike20007@gmail.com> - 2012-10-04 17:40 -0700
      Re: sum function Chris Angelico <rosuav@gmail.com> - 2012-10-05 07:34 +1000
    Re: sum function Mike <mike20007@gmail.com> - 2012-10-04 14:29 -0700
  Re: sum function Mike <mike20007@gmail.com> - 2012-10-05 06:39 -0700
    Re: sum function Ramchandra Apte <maniandram01@gmail.com> - 2012-10-05 06:41 -0700
      Re: sum function Mike <mike20007@gmail.com> - 2012-10-05 06:47 -0700
        Re: sum function Terry Reedy <tjreedy@udel.edu> - 2012-10-05 14:52 -0400
          Re: sum function Mike <mike20007@gmail.com> - 2012-10-05 13:09 -0700
            Re: sum function Dave Angel <d@davea.name> - 2012-10-05 16:26 -0400
              Re: sum function Ramchandra Apte <maniandram01@gmail.com> - 2012-10-06 05:38 -0700
          Re: sum function Mike <mike20007@gmail.com> - 2012-10-05 13:09 -0700
    Re: sum function Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-05 13:29 -0600
  Re: sum function Mike <mike20007@gmail.com> - 2012-10-05 13:03 -0700
    Re: sum function Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-05 14:10 -0600
      Re: sum function Mike <mike20007@gmail.com> - 2012-10-05 14:19 -0700

csiph-web