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


Groups > comp.lang.python > #54653

Re: What's the best way to extract 2 values from a CSV file from each row systematically?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <joel.goldstick@gmail.com>
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; 'python,': 0.02; 'example:': 0.03; 'insert': 0.05; 'indexing': 0.07; 'subject:file': 0.07; 'subject:skip:s 10': 0.07; 'form?': 0.09; 'rows,': 0.09; 'cc:addr:python-list': 0.11; '23,': 0.16; '5),': 0.16; 'advance!': 0.16; 'columns': 0.16; 'csv': 0.16; 'dictionary,': 0.16; 'guys,': 0.16; 'inputs': 0.16; 'key/value': 0.16; 'subject: \n ': 0.16; 'subject:CSV': 0.16; 'subject:values': 0.16; 'all.': 0.16; 'wrote:': 0.18; 'hey': 0.18; 'module': 0.19; '(the': 0.22; 'email addr:gmail.com&gt;': 0.22; 'cc:addr:python.org': 0.22; 'mon,': 0.24; 'file.': 0.24; 'cc:2**0': 0.24; 'least': 0.26; '(for': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'extract': 0.31; 'sep': 0.31; 'file': 0.32; 'lists': 0.32; 'url:python': 0.33; 'beginning': 0.33; 'subject:the': 0.34; "i'd": 0.34; 'subject:from': 0.34; 'form.': 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'building': 0.35; 'really': 0.36; 'data,': 0.36; 'url:listinfo': 0.36; 'thanks': 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'should': 0.36; 'two': 0.37; 'list': 0.37; 'easily': 0.37; 'url:library': 0.38; 'list,': 0.38; 'pm,': 0.38; 'little': 0.38; 'anything': 0.39; 'help,': 0.39; 'url:mail': 0.40; 'read': 0.60; 'prices': 0.60; 'new': 0.61; 'here:': 0.62; 'different': 0.65; 'to:addr:gmail.com': 0.65; 'joel': 0.91; '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:to :cc:content-type; bh=ZoAWx7oJdh/MUplXfEVuQMUT0YlFlrFgKcuy0PLNu68=; b=wnLqT86YFMx5S3tPb/c8b1AMkufW7EU3LjpROq5p6+UQwVwgDlstexLap0xlf3QGdP kjbcB1c3sh3+AmGBGdbc2D7M9/tiSmcVko1PhzXntdoZ9nuYr3nQtZR8Y/+ly+EVcDjI cD3ia+HnC8V0Bih9XDs0iq27RH3mm6PMZQZv97oUgQEO5kmoP28S3Pmvxk+rmEnF7aKI KxinKWyRK287UZP8FcSeWd7zDRsSHd5F2xopoF1I8ZWp79YCKYo+27XnBMvQsMgSZOEs o7S43jX/0+/8qVjp3QAMXQWuIdKRyfpMDBDwLzwna987x77JB2BIlN/k0M7X87a+6qLT yTew==
MIME-Version 1.0
X-Received by 10.52.27.243 with SMTP id w19mr18600440vdg.3.1379957151849; Mon, 23 Sep 2013 10:25:51 -0700 (PDT)
In-Reply-To <fbfc360b-0553-4203-b89a-80b4c4036aec@googlegroups.com>
References <fbfc360b-0553-4203-b89a-80b4c4036aec@googlegroups.com>
Date Mon, 23 Sep 2013 13:25:51 -0400
Subject Re: What's the best way to extract 2 values from a CSV file from each row systematically?
From Joel Goldstick <joel.goldstick@gmail.com>
To quarantinemiles@gmail.com
Content-Type multipart/alternative; boundary=20cf307cfd68d7745e04e7104f83
Cc "python-list@python.org" <python-list@python.org>
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.273.1379957477.18130.python-list@python.org> (permalink)
Lines 101
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1379957477 news.xs4all.nl 15983 [2001:888:2000:d::a6]:53043
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:54653

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On Mon, Sep 23, 2013 at 1:10 PM, <quarantinemiles@gmail.com> wrote:

> Hey guys,
>
> I'm a little new to Python, and am still learning!
>
> I'm test building a web scraper that extracts prices from a website, based
> on two values I want to extract from a CSV file. The CSV has at least 1000
> rows, an example:
>
> 0,0,KGD,0,DME,0,,0,0
>
> The values I want to extract are KGD and DME (columns 3 and 5).
>
> Each row in the CSV file contains values in columns 3 and 5 that I'd like
> to extract. What's the best way to extract these data, so I can insert them
> as inputs in two different fields in a form? A list, dictionary, or MySQL?
> I try not to do anything with MySQL as I'm not familiar with it at all.
>
> I'm thinking of dictionary because at least I can make it work as a
> key/value pair (for columns 3 and 5), but a dictionary is unordered. I'd
> like to automatically go through each row in the CSV file from beginning to
> end to extract the two values in columns 3 and 5 and insert them into
> fields in a form.
>
> I'd really appreciate any suggestions or help, thanks in advance!
>
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>

You should check out the csv module here:
http://docs.python.org/2/library/csv.html#module-csv
It will read your csv file into a list (the file rows) of lists (the
columns).  You can easily loop over the data to extract the columns you
want using list indexing

-- 
Joel Goldstick
http://joelgoldstick.com

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


Thread

What's the best way to extract 2 values from a CSV file from each row systematically? quarantinemiles@gmail.com - 2013-09-23 10:10 -0700
  Re: What's the best way to extract 2 values from a CSV file from each row systematically? Neil Cerutti <neilc@norwich.edu> - 2013-09-23 17:20 +0000
  Re: What's the best way to extract 2 values from a CSV file from each row systematically? Joel Goldstick <joel.goldstick@gmail.com> - 2013-09-23 13:25 -0400
  Re: What's the best way to extract 2 values from a CSV file from each row systematically? Tim Chase <python.list@tim.thechases.com> - 2013-09-23 12:47 -0500
    Re: What's the best way to extract 2 values from a CSV file from each row systematically? Alex Lee <quarantinemiles@gmail.com> - 2013-09-24 07:04 -0700
      Re: What's the best way to extract 2 values from a CSV file from each row systematically? Roland Mueller <roland.em0001@googlemail.com> - 2013-09-27 12:22 +0300
  Re: What's the best way to extract 2 values from a CSV file from each row systematically? Luca Cerone <luca.cerone@gmail.com> - 2013-09-28 03:21 -0700

csiph-web