Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
sum function
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 1 - 25 of 28 - Collapse all  -  Translate all to Translated (View all originals)   Newer >
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
mike20...@gmail.com  
View profile  
 More options Oct 4 2012, 4:52 pm
Newsgroups: comp.lang.python
From: mike20...@gmail.com
Date: Thu, 4 Oct 2012 13:52:50 -0700 (PDT)
Local: Thurs, Oct 4 2012 4:52 pm
Subject: sum function
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ian Kelly  
View profile  
 More options Oct 4 2012, 5:05 pm
Newsgroups: comp.lang.python
From: Ian Kelly <ian.g.ke...@gmail.com>
Date: Thu, 4 Oct 2012 15:04:53 -0600
Local: Thurs, Oct 4 2012 5:04 pm
Subject: Re: sum function

On Thu, Oct 4, 2012 at 2:52 PM,  <mike20...@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())

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ian Kelly  
View profile  
 More options Oct 4 2012, 5:06 pm
Newsgroups: comp.lang.python
From: Ian Kelly <ian.g.ke...@gmail.com>
Date: Thu, 4 Oct 2012 15:05:48 -0600
Local: Thurs, Oct 4 2012 5:05 pm
Subject: Re: sum function

On Thu, Oct 4, 2012 at 3:04 PM, Ian Kelly <ian.g.ke...@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

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike  
View profile  
 More options Oct 4 2012, 5:29 pm
Newsgroups: comp.lang.python
From: Mike <mike20...@gmail.com>
Date: Thu, 4 Oct 2012 14:29:54 -0700 (PDT)
Local: Thurs, Oct 4 2012 5:29 pm
Subject: Re: sum function
I get below error

NameError: name 'functools' is not defined

Thanks


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike  
View profile  
 More options Oct 4 2012, 5:29 pm
Newsgroups: comp.lang.python
From: Mike <mike20...@gmail.com>
Date: Thu, 4 Oct 2012 14:29:54 -0700 (PDT)
Local: Thurs, Oct 4 2012 5:29 pm
Subject: Re: sum function
I get below error

NameError: name 'functools' is not defined

Thanks


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike  
View profile  
 More options Oct 4 2012, 5:31 pm
Newsgroups: comp.lang.python
From: Mike <mike20...@gmail.com>
Date: Thu, 4 Oct 2012 14:31:19 -0700 (PDT)
Local: Thurs, Oct 4 2012 5:31 pm
Subject: Re: sum function
Thanks Ian for the quick reply.

I get the below error.

NameError: name 'itertools' is not defined

Thanks


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike  
View profile  
 More options Oct 4 2012, 5:31 pm
Newsgroups: comp.lang.python
From: Mike <mike20...@gmail.com>
Date: Thu, 4 Oct 2012 14:31:19 -0700 (PDT)
Local: Thurs, Oct 4 2012 5:31 pm
Subject: Re: sum function
Thanks Ian for the quick reply.

I get the below error.

NameError: name 'itertools' is not defined

Thanks


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dave Angel  
View profile  
 More options Oct 4 2012, 5:40 pm
Newsgroups: comp.lang.python
From: Dave Angel <d...@davea.name>
Date: Thu, 04 Oct 2012 17:39:50 -0400
Local: Thurs, Oct 4 2012 5:39 pm
Subject: Re: sum function
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Angelico  
View profile  
 More options Oct 4 2012, 5:41 pm
Newsgroups: comp.lang.python
From: Chris Angelico <ros...@gmail.com>
Date: Fri, 5 Oct 2012 07:34:41 +1000
Local: Thurs, Oct 4 2012 5:34 pm
Subject: Re: sum function

On Fri, Oct 5, 2012 at 7:29 AM, Mike <mike20...@gmail.com> wrote:
> I get below error

> NameError: name 'functools' is not defined

> Thanks

functools is a module:

import functools

ChrisA


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike  
View profile  
 More options Oct 4 2012, 8:40 pm
Newsgroups: comp.lang.python
From: Mike <mike20...@gmail.com>
Date: Thu, 4 Oct 2012 17:40:49 -0700 (PDT)
Local: Thurs, Oct 4 2012 8:40 pm
Subject: Re: sum function

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike  
View profile  
 More options Oct 4 2012, 8:41 pm
Newsgroups: comp.lang.python
From: Mike <mike20...@gmail.com>
Date: Thu, 4 Oct 2012 17:40:49 -0700 (PDT)
Local: Thurs, Oct 4 2012 8:40 pm
Subject: Re: sum function

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ian Kelly  
View profile  
 More options Oct 4 2012, 8:59 pm
Newsgroups: comp.lang.python
From: Ian Kelly <ian.g.ke...@gmail.com>
Date: Thu, 4 Oct 2012 18:59:03 -0600
Local: Thurs, Oct 4 2012 8:59 pm
Subject: Re: sum function

On Thu, Oct 4, 2012 at 6:40 PM, Mike <mike20...@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. :-)

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike  
View profile  
 More options Oct 4 2012, 10:01 pm
Newsgroups: comp.lang.python
From: Mike <mike20...@gmail.com>
Date: Thu, 4 Oct 2012 19:01:24 -0700 (PDT)
Local: Thurs, Oct 4 2012 10:01 pm
Subject: Re: sum function

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 must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike  
View profile  
 More options Oct 4 2012, 10:01 pm
Newsgroups: comp.lang.python
From: Mike <mike20...@gmail.com>
Date: Thu, 4 Oct 2012 19:01:24 -0700 (PDT)
Local: Thurs, Oct 4 2012 10:01 pm
Subject: Re: sum function

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 must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ramchandra Apte  
View profile  
 More options Oct 5 2012, 4:31 am
Newsgroups: comp.lang.python
From: Ramchandra Apte <maniandra...@gmail.com>
Date: Fri, 5 Oct 2012 01:31:29 -0700 (PDT)
Local: Fri, Oct 5 2012 4:31 am
Subject: Re: sum function

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

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ramchandra Apte  
View profile  
 More options Oct 5 2012, 4:31 am
Newsgroups: comp.lang.python
From: Ramchandra Apte <maniandra...@gmail.com>
Date: Fri, 5 Oct 2012 01:31:29 -0700 (PDT)
Local: Fri, Oct 5 2012 4:31 am
Subject: Re: sum function

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

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike  
View profile  
 More options Oct 5 2012, 9:39 am
Newsgroups: comp.lang.python
From: Mike <mike20...@gmail.com>
Date: Fri, 5 Oct 2012 06:39:15 -0700 (PDT)
Local: Fri, Oct 5 2012 9:39 am
Subject: Re: sum function

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ramchandra Apte  
View profile  
 More options Oct 5 2012, 9:41 am
Newsgroups: comp.lang.python
From: Ramchandra Apte <maniandra...@gmail.com>
Date: Fri, 5 Oct 2012 06:41:43 -0700 (PDT)
Local: Fri, Oct 5 2012 9:41 am
Subject: Re: sum function

the variable "r" is an empty list

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike  
View profile  
 More options Oct 5 2012, 9:47 am
Newsgroups: comp.lang.python
From: Mike <mike20...@gmail.com>
Date: Fri, 5 Oct 2012 06:47:12 -0700 (PDT)
Local: Fri, Oct 5 2012 9:47 am
Subject: Re: sum function

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Terry Reedy  
View profile  
 More options Oct 5 2012, 2:52 pm
Newsgroups: comp.lang.python
From: Terry Reedy <tjre...@udel.edu>
Date: Fri, 05 Oct 2012 14:52:13 -0400
Local: Fri, Oct 5 2012 2:52 pm
Subject: Re: sum function
On 10/5/2012 9:47 AM, Mike wrote:

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ian Kelly  
View profile  
 More options Oct 5 2012, 3:29 pm
Newsgroups: comp.lang.python
From: Ian Kelly <ian.g.ke...@gmail.com>
Date: Fri, 5 Oct 2012 13:29:04 -0600
Local: Fri, Oct 5 2012 3:29 pm
Subject: Re: sum function

On Fri, Oct 5, 2012 at 7:39 AM, Mike <mike20...@gmail.com> wrote:
> 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

Maybe the sentinel value is not None as I assumed, and it's
overrunning the end of the data?  What does
client.scannerGet return when there is no more data?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike  
View profile  
 More options Oct 5 2012, 4:03 pm
Newsgroups: comp.lang.python
From: Mike <mike20...@gmail.com>
Date: Fri, 5 Oct 2012 13:03:49 -0700 (PDT)
Local: Fri, Oct 5 2012 4:03 pm
Subject: Re: sum function
I added the print command.

It prints [] when there is no data.

Thanks


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike  
View profile  
 More options Oct 5 2012, 4:09 pm
Newsgroups: comp.lang.python
From: Mike <mike20...@gmail.com>
Date: Fri, 5 Oct 2012 13:09:11 -0700 (PDT)
Local: Fri, Oct 5 2012 4:09 pm
Subject: Re: sum function
Terry,

I am not using the mail client. I am just posting on the site.

Something wrong with this site. When you do individual reply, it does the double posting which it shouldn't. See "Ramachandra Apte's" reply. It is posted twice too.

Thanks


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike  
View profile  
 More options Oct 5 2012, 4:09 pm
Newsgroups: comp.lang.python
From: Mike <mike20...@gmail.com>
Date: Fri, 5 Oct 2012 13:09:11 -0700 (PDT)
Local: Fri, Oct 5 2012 4:09 pm
Subject: Re: sum function
Terry,

I am not using the mail client. I am just posting on the site.

Something wrong with this site. When you do individual reply, it does the double posting which it shouldn't. See "Ramachandra Apte's" reply. It is posted twice too.

Thanks


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ian Kelly  
View profile  
 More options Oct 5 2012, 4:11 pm
Newsgroups: comp.lang.python
From: Ian Kelly <ian.g.ke...@gmail.com>
Date: Fri, 5 Oct 2012 14:10:36 -0600
Local: Fri, Oct 5 2012 4:10 pm
Subject: Re: sum function

On Fri, Oct 5, 2012 at 2:03 PM, Mike <mike20...@gmail.com> wrote:
> I added the print command.

> It prints [] when there is no data.

Change "iter(next_r, None)" to "iter(next_r, [])"

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Messages 1 - 25 of 28   Newer >
« Back to Discussions « Newer topic     Older topic »