Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #62167
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Subject | Re: Reading csv file |
| Date | 2013-12-17 09:55 +0100 |
| Organization | None |
| References | <CA+FnnTwpiq=Z6tswub9vab2wxzzQycwyL2jNCgK2RTQuhGrrMQ@mail.gmail.com> <l8p1f5$gk0$1@ger.gmane.org> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4270.1387270513.18130.python-list@python.org> (permalink) |
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