Path: csiph.com!usenet.pasdenom.info!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'url:pypi': 0.03; 'from:addr:yahoo.co.uk': 0.04; '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; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'bug': 0.12; 'language.': 0.14; 'brackets': 0.16; 'buggy': 0.16; 'comma,': 0.16; 'csv': 0.16; 'nerds,': 0.16; 'part-way': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'route,': 0.16; 'skip:[ 30': 0.16; 'subject: \n ': 0.16; 'subject:beginner': 0.16; 'subject:values': 0.16; 'there!': 0.16; 'there...': 0.16; 'using,': 0.16; 'language': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'trying': 0.19; 'file,': 0.19; 'split': 0.19; 'things.': 0.19; 'thu,': 0.19; 'solution.': 0.20; 'header:User-Agent:1': 0.23; 'module,': 0.24; 'specify': 0.24; 'mention': 0.26; 'switch': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'rest': 0.29; 'appreciated.': 0.29; 'chris': 0.29; 'am,': 0.29; 'dec': 0.30; 'list:': 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; 'front': 0.32; 'thanks!': 0.32; 'open': 0.33; 'worked': 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; 'google': 0.35; 'there': 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; 'to:addr:python-list': 0.38; '12,': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'mailing': 0.39; 'received:org': 0.40; '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; 'our': 0.64; 'sum': 0.64; 'great': 0.65; 'number:': 0.66; 'subject:. ': 0.67; 'url:0': 0.67; 'square': 0.74; 'yourself': 0.78; 'friends': 0.81; 'average.': 0.84; 'homework': 0.84; 'late,': 0.84; 'mention.': 0.84; 'received:2': 0.84; 'careful': 0.91; 'same,': 0.91; 'fight': 0.97; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: adding values from a csv column and getting the mean. beginner help Date: Wed, 11 Dec 2013 19:41:06 +0000 References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-2-98-195-123.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 73 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1386790860 news.xs4all.nl 2881 [2001:888:2000:d::a6]:34873 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:61612 On 11/12/2013 19:22, Chris Angelico wrote: > On Thu, Dec 12, 2013 at 6:10 AM, brian cleere 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. There is, https://pypi.python.org/pypi/docopt/0.6.1 :) > >> 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. Ooh 'eck, we'll have the Popular Front for the Liberation of Google Groups squad out in force again, vainly trying to defend the bug ridden crap that they insist on using, and which I obviously won't mention. Whoops!!! Oh Lord, won't you buy me Mozilla Thunderbird ? My friends all use GG, I think that's absurd. Worked hard all my lifetime, no help from the nerds, So Lord, won't you buy me Mozilla Thunderbird ? With apologies to the late, great Janis Joplin. > > Thanks! And welcome to the group. > > ChrisA > -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence