Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #62174
| Return-Path | <ikorot01@gmail.com> |
|---|---|
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.005 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'column': 0.07; 'subject:file': 0.07; 'assuming': 0.09; 'complicate': 0.09; 'mysql.': 0.09; 'none):': 0.09; 'report,': 0.09; 'rows': 0.09; 'missed': 0.12; 'creates': 0.14; 'at,': 0.16; 'csv': 0.16; 'guys,': 0.16; 'subject:Reading': 0.16; 'switches': 0.16; 'task.': 0.16; 'wrote:': 0.18; 'meant': 0.20; 'not,': 0.20; 'parse': 0.24; 'simpler': 0.24; 'skip': 0.24; 'sorry,': 0.24; 'text,': 0.24; 'header': 0.24; 'file.': 0.24; 'push': 0.26; 'switch': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'dec': 0.30; 'message- id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'posting': 0.31; 'info.': 0.31; 'names.': 0.31; 'file': 0.32; 'run': 0.32; 'url:python': 0.33; 'guess': 0.33; 'reader': 0.33; '(2)': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'located': 0.36; 'i.e.': 0.36; 'url:listinfo': 0.36; 'hi,': 0.36; 'url:org': 0.36; 'thank': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'url:mail': 0.40; 'read': 0.60; 'first': 0.61; 'complete': 0.62; 'such': 0.63; 'reply': 0.66; 'realized': 0.68; 'deeply': 0.69; 'otten': 0.84; 'sorry.': 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 :content-type; bh=qZwND3Kwgsp1nAbxOGx9pqDO4Lvh7PlZBbMK+Ta7lpY=; b=VSaHpBRI7v21K8C9mnlNvwtS3hvH631cQb8GY+uaw5zmX4nBTDxgCZwBB/i2ZylcxJ yMvtSECc/2QUQP1pWxSSpWWVTpJVEUxP5A7UUUXvG9jJXhqCs7L+n9bCq9dem4G5zZdw V55JgQBK2NL7BhrXSLoI8jQ9bMvy5xcavIW0nUPwqaT+Zd4o6w4+b94c806jvkEZbQN+ 9usIQ49NfDHUJq1e6bISs2MUKlYPojCiMCRX07EqT5LQo8a7cpDeZqzKjJdIh7/wQi3T VOATFXStGHHKwxuSBiCpw7PFkznZIEonaWtwXOd4vrbHxN2WlmtPjnxOrMrFPfU+ys1N o9Mg== |
| MIME-Version | 1.0 |
| X-Received | by 10.58.100.197 with SMTP id fa5mr1887199veb.24.1387274015366; Tue, 17 Dec 2013 01:53:35 -0800 (PST) |
| In-Reply-To | <l8p3gj$3gb$1@ger.gmane.org> |
| References | <CA+FnnTwpiq=Z6tswub9vab2wxzzQycwyL2jNCgK2RTQuhGrrMQ@mail.gmail.com> <l8p1f5$gk0$1@ger.gmane.org> <l8p3gj$3gb$1@ger.gmane.org> |
| Date | Tue, 17 Dec 2013 01:53:35 -0800 |
| Subject | Re: Reading csv file |
| From | Igor Korot <ikorot01@gmail.com> |
| To | python-list@python.org |
| Content-Type | text/plain; charset=ISO-8859-1 |
| 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.4274.1387274024.18130.python-list@python.org> (permalink) |
| Lines | 52 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1387274024 news.xs4all.nl 2920 [2001:888:2000:d::a6]:43874 |
| X-Complaints-To | abuse@xs4all.nl |
| Path | csiph.com!usenet.pasdenom.info!news.stben.net!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
| Xref | csiph.com comp.lang.python:62174 |
Show key headers only | View raw
Hi, guys, On Tue, Dec 17, 2013 at 12:55 AM, Peter Otten <__peter__@web.de> wrote: > Peter Otten wrote: > >> You are still reading the complete csv file. Assuming >> >> (1) the first row of the csv contains the column names >> (2) you want to skip the first five rows of data Looking at the Peter's reply I realized I missed very important piece: The first row may or may not contain column names. If it does not, the first row will just contain some text, i.e. "abc" and the column names will be located on the row 6. I know if does complicate things but I am deeply sorry. The csv file is generated by some program run and I guess depending on the switches passed to that program it either creates the header in the csv (report name, time slice it ran at, user it ran under and some other info. Or it can be run without such switch and then it generates a normal csv. The report it generates is huge: it has about 30+ fields and I need to read this report, parse it and push accordingly to the database of mySQL. Thank you for any suggestions and sorry for not posting complete task. >> >> you'd have to write >> >> reader = csv.Reader(file) > > Sorry, I meant DictReader, not Reader. > >> line = 0 >> while line < 5: >> next(reader) >> line += 1 >> for row in reader: >> .... # process csv row >> >> A simpler alternative is to use itertools.islice(): >> >> for row in itertools.islice(reader, 5, None): >> ... # process csv row > > > -- > https://mail.python.org/mailman/listinfo/python-list
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Reading csv file Igor Korot <ikorot01@gmail.com> - 2013-12-17 01:53 -0800
csiph-web