Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #61608
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'importing': 0.05; 'column': 0.07; 'debugging': 0.07; 'finally:': 0.07; 'subject:adding': 0.07; 'subject:getting': 0.07; 'subject:help': 0.08; 'builtin': 0.09; 'explanation': 0.09; 'filename': 0.09; 'fix.': 0.09; 'iterate': 0.09; 'cc:addr:python-list': 0.11; 'brackets': 0.16; 'buggy': 0.16; 'comma,': 0.16; 'csv': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'part- way': 0.16; 'route,': 0.16; 'skip:[ 30': 0.16; 'subject:beginner': 0.16; 'subject:values': 0.16; 'there!': 0.16; 'there...': 0.16; 'wrote:': 0.18; 'file,': 0.19; 'split': 0.19; 'things.': 0.19; 'thu,': 0.19; 'solution.': 0.20; 'cc:addr:python.org': 0.22; 'module,': 0.24; 'specify': 0.24; 'cc:2**0': 0.24; 'mention': 0.26; 'switch': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'rest': 0.29; 'appreciated.': 0.29; 'am,': 0.29; 'dec': 0.30; 'list:': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'that.': 0.31; 'calculated': 0.31; 'fixing': 0.31; 'once,': 0.31; 'piece': 0.31; 'search.': 0.31; 'though.': 0.31; 'file': 0.32; 'figure': 0.32; 'thanks!': 0.32; 'open': 0.33; 'url:python': 0.33; 'brian': 0.33; 'subject:the': 0.34; "i'd": 0.34; 'subject:from': 0.34; 'problem': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'google': 0.35; 'really': 0.36; 'replies': 0.36; 'url:listinfo': 0.36; 'url:org': 0.36; 'list': 0.37; 'starting': 0.37; 'url:library': 0.38; '12,': 0.39; 'sure': 0.39; 'mailing': 0.39; 'url:mail': 0.40; 'how': 0.40; 'read': 0.60; 'url:3': 0.61; 'matter': 0.61; "you're": 0.61; "you'll": 0.62; "you've": 0.63; 'sum': 0.64; 'number:': 0.66; 'subject:. ': 0.67; 'square': 0.74; 'yourself': 0.78; 'average.': 0.84; 'homework': 0.84; 'careful': 0.91; 'same,': 0.91; 'to:none': 0.92; 'fight': 0.97; '2013': 0.98 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=WISWwbKTNEwGQTehnRh5nLGLqAuOrPu9CgX544JjI9A=; b=ZRCnFj5qA+YNIX4AYFTyUbYdKaJX/EUrqEtflyd44rsLFzZTS68KxZ84MQtII9/766 6Sc0c/vnvAsTNm+7mi5cpfWrtmCnHEIJTzOlruP9nuYpxUzZk8+J3tT5cRqWpGX1TOTL CntyuvLCJae3ZbOjgxyC5/Phb5mk+Q9ECny9NVIM3I0ZPbU5O7/bV9/pR1wNrA1dVdnG iGM/L11fCDLIqvPfpbIKlzV5MzcWnARLxGrHBcPtmqHI76lgwITyXP7hCIOszo0FTBmU Lo1TcHhN8RKFIJDuKhGEwEuyEV65njQUtI8MSU+au8ZBE1rbH3rGcUkASLCiaIB3GfV6 yMHw== |
| MIME-Version | 1.0 |
| X-Received | by 10.68.228.97 with SMTP id sh1mr4146650pbc.50.1386789729775; Wed, 11 Dec 2013 11:22:09 -0800 (PST) |
| In-Reply-To | <e3a75021-32a2-471e-b486-51d1b28ffef6@googlegroups.com> |
| References | <e3a75021-32a2-471e-b486-51d1b28ffef6@googlegroups.com> |
| Date | Thu, 12 Dec 2013 06:22:09 +1100 |
| Subject | Re: adding values from a csv column and getting the mean. beginner help |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3922.1386789733.18130.python-list@python.org> (permalink) |
| Lines | 48 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1386789733 news.xs4all.nl 2868 [2001:888:2000:d::a6]:53416 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:61608 |
Show key headers only | View raw
On Thu, Dec 12, 2013 at 6:10 AM, brian cleere <briancleere@gmail.com> wrote:
> I know the problem is with the for loop but don't know how to fix. Any help with explanation would be appreciated.
Your problem is akin to debugging an empty file :) It's not so much a
matter of fixing what's not working as of starting at the very
beginning: How do you iterate over the content of a CSV file?
Now, you're almost there... partly. You have the split() call, which
will split on the comma, so if you go that route, all you need to do
is open the file, using the aptly-named builtin function "open".
You'll find docs on that if you do a quick search.
But you're actually part-way to the better solution. You're importing
the 'csv' module, which is exactly what you need here. All you need is
to read up on its docs:
http://docs.python.org/3/library/csv.html
I'm sure you can figure out the rest of your homework from there!
Now, with that out of the way, I'd like to just mention a couple of
other things.
> print('Please specify a filename and column number: {} [csvfile] [column]'.format(sys.argv[0]))
Square brackets in a usage description often mean "optional". You may
want to be careful of that. There's no really good solution though.
> csum = sum(values)
> cavg = sum(values)/len(values)
Once you've calculated the sum once, you can reuse that to calculate
the average. Can you see how? :)
And finally: You're using Google Groups to post, which means your
paragraphs are unwrapped, and - unless you fight very hard against a
stupidly buggy piece of software - your replies will be malformed and
ugly. Don't make yourself look bad; switch to a better newsreader, or
to the mailing list:
https://mail.python.org/mailman/listinfo/python-list
The content is the same, you just subscribe to the list and read and
write as email.
Thanks! And welcome to the group.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
adding values from a csv column and getting the mean. beginner help brian cleere <briancleere@gmail.com> - 2013-12-11 11:10 -0800 Re: adding values from a csv column and getting the mean. beginner help Tim Chase <python.list@tim.thechases.com> - 2013-12-11 13:20 -0600 Re: adding values from a csv column and getting the mean. beginner help Chris Angelico <rosuav@gmail.com> - 2013-12-12 06:22 +1100 Re: adding values from a csv column and getting the mean. beginner help Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-11 19:34 +0000 Re: adding values from a csv column and getting the mean. beginner help Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-11 19:41 +0000 Re: adding values from a csv column and getting the mean. beginner help Chris Angelico <rosuav@gmail.com> - 2013-12-12 06:46 +1100 Re: adding values from a csv column and getting the mean. beginner help Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-11 20:00 +0000 Re: adding values from a csv column and getting the mean. beginner help Chris Angelico <rosuav@gmail.com> - 2013-12-12 07:03 +1100 Re: adding values from a csv column and getting the mean. beginner help Tim Chase <python.list@tim.thechases.com> - 2013-12-11 14:20 -0600 Re: adding values from a csv column and getting the mean. beginner help Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-11 20:20 +0000 Re: adding values from a csv column and getting the mean. beginner help Christopher Welborn <cjwelborn@live.com> - 2013-12-11 18:49 -0600 Re: adding values from a csv column and getting the mean. beginner help "M.F." <morefool@gmail.com> - 2013-12-12 09:36 +0800
csiph-web