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


Groups > comp.lang.python > #30744 > unrolled thread

sum function

Started bymike20007@gmail.com
First post2012-10-04 13:52 -0700
Last post2012-10-05 14:19 -0700
Articles 20 on this page of 28 — 7 participants

Back to article view | Back to comp.lang.python


Contents

  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

Page 1 of 2  [1] 2  Next page →


#30744 — sum function

Frommike20007@gmail.com
Date2012-10-04 13:52 -0700
Subjectsum function
Message-ID<7c7beccb-72e4-4cfb-958d-4a7235076fb3@googlegroups.com>
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

[toc] | [next] | [standalone]


#30745

FromIan Kelly <ian.g.kelly@gmail.com>
Date2012-10-04 15:04 -0600
Message-ID<mailman.1809.1349384724.27098.python-list@python.org>
In reply to#30744
On Thu, Oct 4, 2012 at 2:52 PM,  <mike20007@gmail.com> wrote:
> 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?

scanner = client.scannerOpenWithStop("tab", "10", "1000", ["cf:col1"])
next_r = itertools.partial(client.scannerGet, scanner)
total = sum(float(col.value) for r in iter(next_r, None) for col in
r.itervalues())

[toc] | [prev] | [next] | [standalone]


#30749

FromMike <mike20007@gmail.com>
Date2012-10-04 14:31 -0700
Message-ID<f0978784-9869-4c30-bf4c-fba4cad27e48@googlegroups.com>
In reply to#30745
Thanks Ian for the quick reply.

I get the below error.

NameError: name 'itertools' is not defined

Thanks

[toc] | [prev] | [next] | [standalone]


#30750

FromMike <mike20007@gmail.com>
Date2012-10-04 14:31 -0700
Message-ID<mailman.1812.1349386287.27098.python-list@python.org>
In reply to#30745
Thanks Ian for the quick reply.

I get the below error.

NameError: name 'itertools' is not defined

Thanks

[toc] | [prev] | [next] | [standalone]


#30746

FromIan Kelly <ian.g.kelly@gmail.com>
Date2012-10-04 15:05 -0600
Message-ID<mailman.1810.1349384780.27098.python-list@python.org>
In reply to#30744
On Thu, Oct 4, 2012 at 3:04 PM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> scanner = client.scannerOpenWithStop("tab", "10", "1000", ["cf:col1"])
> next_r = itertools.partial(client.scannerGet, scanner)
> total = sum(float(col.value) for r in iter(next_r, None) for col in
> r.itervalues())

That should be "functools" above, not "itertools". :-P

[toc] | [prev] | [next] | [standalone]


#30747

FromMike <mike20007@gmail.com>
Date2012-10-04 14:29 -0700
Message-ID<307d5843-af17-4079-8a48-f8d7351a1d7b@googlegroups.com>
In reply to#30746
I get below error

NameError: name 'functools' is not defined

Thanks

[toc] | [prev] | [next] | [standalone]


#30751

FromDave Angel <d@davea.name>
Date2012-10-04 17:39 -0400
Message-ID<mailman.1813.1349386825.27098.python-list@python.org>
In reply to#30747
On 10/04/2012 05:29 PM, Mike wrote:
> I get below error
>
> NameError: name 'functools' is not defined
>

functools is a module in the standard library. You need to import it.

import functools



-- 

DaveA

[toc] | [prev] | [next] | [standalone]


#30761

FromMike <mike20007@gmail.com>
Date2012-10-04 17:40 -0700
Message-ID<3e6de8b6-5ad5-4b29-92b4-9e957158ca5a@googlegroups.com>
In reply to#30751
On Thursday, October 4, 2012 5:40:26 PM UTC-4, Dave Angel wrote:
> On 10/04/2012 05:29 PM, Mike wrote:
> 
> > I get below error
> 
> >
> 
> > NameError: name 'functools' is not defined
> 
> >
> 
> 
> 
> functools is a module in the standard library. You need to import it.
> 
> 
> 
> import functools
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> 
> 
> DaveA

I imported functools. Now I get the below error please.


Traceback (most recent call last):
  File "test.py", line 16, in <module>
    total = sum(float(col.value) for r in iter(next_r, None) for col in r.itervalues()) 
  File "test.py", line 16, in <genexpr>
    total = sum(float(col.value) for r in iter(next_r, None) for col in r.itervalues()) 
AttributeError: 'list' object has no attribute 'itervalues'

Thanks

[toc] | [prev] | [next] | [standalone]


#30765

FromIan Kelly <ian.g.kelly@gmail.com>
Date2012-10-04 18:59 -0600
Message-ID<mailman.1824.1349398775.27098.python-list@python.org>
In reply to#30761
On Thu, Oct 4, 2012 at 6:40 PM, Mike <mike20007@gmail.com> wrote:
> Traceback (most recent call last):
>   File "test.py", line 16, in <module>
>     total = sum(float(col.value) for r in iter(next_r, None) for col in r.itervalues())
>   File "test.py", line 16, in <genexpr>
>     total = sum(float(col.value) for r in iter(next_r, None) for col in r.itervalues())
> AttributeError: 'list' object has no attribute 'itervalues'

"r.itervalues()" should have been "r[0].columns.itervalues()", I
think.  It's hard to test code against an API that you don't have. :-)

[toc] | [prev] | [next] | [standalone]


#30773

FromMike <mike20007@gmail.com>
Date2012-10-04 19:01 -0700
Message-ID<d2939506-ae0e-40fc-a4fb-626ea99a941e@googlegroups.com>
In reply to#30765
I agree with you, Ian. Thanks for all the help.  Now I get the below error.

  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())

Thanks

[toc] | [prev] | [next] | [standalone]


#30792

FromRamchandra Apte <maniandram01@gmail.com>
Date2012-10-05 01:31 -0700
Message-ID<e9746a06-809f-461a-910c-19b6c048cb0f@googlegroups.com>
In reply to#30773
On Friday, 5 October 2012 07:31:24 UTC+5:30, Mike  wrote:
> I agree with you, Ian. Thanks for all the help.  Now I get the below error.
> 
> 
> 
>   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())
> 
> 
> 
> Thanks

You have missed the last line of the traceback (error)

[toc] | [prev] | [next] | [standalone]


#30793

FromRamchandra Apte <maniandram01@gmail.com>
Date2012-10-05 01:31 -0700
Message-ID<mailman.1845.1349425893.27098.python-list@python.org>
In reply to#30773
On Friday, 5 October 2012 07:31:24 UTC+5:30, Mike  wrote:
> I agree with you, Ian. Thanks for all the help.  Now I get the below error.
> 
> 
> 
>   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())
> 
> 
> 
> Thanks

You have missed the last line of the traceback (error)

[toc] | [prev] | [next] | [standalone]


#30774

FromMike <mike20007@gmail.com>
Date2012-10-04 19:01 -0700
Message-ID<mailman.1832.1349402494.27098.python-list@python.org>
In reply to#30765
I agree with you, Ian. Thanks for all the help.  Now I get the below error.

  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())

Thanks

[toc] | [prev] | [next] | [standalone]


#30762

FromMike <mike20007@gmail.com>
Date2012-10-04 17:40 -0700
Message-ID<mailman.1821.1349397657.27098.python-list@python.org>
In reply to#30751
On Thursday, October 4, 2012 5:40:26 PM UTC-4, Dave Angel wrote:
> On 10/04/2012 05:29 PM, Mike wrote:
> 
> > I get below error
> 
> >
> 
> > NameError: name 'functools' is not defined
> 
> >
> 
> 
> 
> functools is a module in the standard library. You need to import it.
> 
> 
> 
> import functools
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> 
> 
> DaveA

I imported functools. Now I get the below error please.


Traceback (most recent call last):
  File "test.py", line 16, in <module>
    total = sum(float(col.value) for r in iter(next_r, None) for col in r.itervalues()) 
  File "test.py", line 16, in <genexpr>
    total = sum(float(col.value) for r in iter(next_r, None) for col in r.itervalues()) 
AttributeError: 'list' object has no attribute 'itervalues'

Thanks

[toc] | [prev] | [next] | [standalone]


#30752

FromChris Angelico <rosuav@gmail.com>
Date2012-10-05 07:34 +1000
Message-ID<mailman.1814.1349386894.27098.python-list@python.org>
In reply to#30747
On Fri, Oct 5, 2012 at 7:29 AM, Mike <mike20007@gmail.com> wrote:
> I get below error
>
> NameError: name 'functools' is not defined
>
> Thanks

functools is a module:

import functools

ChrisA

[toc] | [prev] | [next] | [standalone]


#30748

FromMike <mike20007@gmail.com>
Date2012-10-04 14:29 -0700
Message-ID<mailman.1811.1349386197.27098.python-list@python.org>
In reply to#30746
I get below error

NameError: name 'functools' is not defined

Thanks

[toc] | [prev] | [next] | [standalone]


#30814

FromMike <mike20007@gmail.com>
Date2012-10-05 06:39 -0700
Message-ID<12a372ba-8809-4fff-bca5-55a03e61ca82@googlegroups.com>
In reply to#30744
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

[toc] | [prev] | [next] | [standalone]


#30815

FromRamchandra Apte <maniandram01@gmail.com>
Date2012-10-05 06:41 -0700
Message-ID<04412893-e6ba-43cc-8d9c-7867f82af4d1@googlegroups.com>
In reply to#30814
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

[toc] | [prev] | [next] | [standalone]


#30816

FromMike <mike20007@gmail.com>
Date2012-10-05 06:47 -0700
Message-ID<d52e3cdb-9568-4963-8ff2-09e619f984c4@googlegroups.com>
In reply to#30815
On Friday, October 5, 2012 9:41:44 AM UTC-4, Ramchandra Apte wrote:
> 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

Here is the actual code.

scanner = client.scannerOpenWithStop("tab", "10", "1000", ["cf:col1"]) 
next_r = functools.partial(client.scannerGet, scanner)
total = sum(float(col.value) for r in iter(next_r, None) for col in r[0].columns.itervalues())


Scanner does have rows.

Are we missing something please?

Thanks

[toc] | [prev] | [next] | [standalone]


#30829

FromTerry Reedy <tjreedy@udel.edu>
Date2012-10-05 14:52 -0400
Message-ID<mailman.1863.1349463163.27098.python-list@python.org>
In reply to#30816
On 10/5/2012 9:47 AM, Mike wrote:
> On Friday, October 5, 2012 9:41:44 AM UTC-4, Ramchandra Apte wrote:
>> 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.

If you want as many people as possible to read your posts, stop using a 
mail-agent and site that spits in the face of readers by doubling blank 
lines each iteration. Alternatives have been discussed previously.

-- 
Terry Jan Reedy

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.python


csiph-web