Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #62167
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| 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; 'column': 0.07; 'subject:file': 0.07; 'assuming': 0.09; 'none):': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'rows': 0.09; 'csv': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:Reading': 0.16; 'wrote:': 0.18; 'meant': 0.20; 'header:User-Agent:1': 0.23; 'simpler': 0.24; 'skip': 0.24; 'sorry,': 0.24; 'file.': 0.24; 'header:X-Complaints-To:1': 0.27; 'reader': 0.33; '(2)': 0.35; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'first': 0.61; 'complete': 0.62; 'otten': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Peter Otten <__peter__@web.de> |
| Subject | Re: Reading csv file |
| Date | Tue, 17 Dec 2013 09:55:43 +0100 |
| Organization | None |
| References | <CA+FnnTwpiq=Z6tswub9vab2wxzzQycwyL2jNCgK2RTQuhGrrMQ@mail.gmail.com> <l8p1f5$gk0$1@ger.gmane.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Gmane-NNTP-Posting-Host | p5084960a.dip0.t-ipconnect.de |
| User-Agent | KNode/4.7.3 |
| 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.4270.1387270513.18130.python-list@python.org> (permalink) |
| Lines | 26 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1387270513 news.xs4all.nl 2834 [2001:888:2000:d::a6]:50654 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:62167 |
Show key headers only | View raw
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 > > 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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Reading csv file Peter Otten <__peter__@web.de> - 2013-12-17 09:55 +0100
csiph-web