Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #62174 > unrolled thread
| Started by | Igor Korot <ikorot01@gmail.com> |
|---|---|
| First post | 2013-12-17 01:53 -0800 |
| Last post | 2013-12-17 01:53 -0800 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Reading csv file Igor Korot <ikorot01@gmail.com> - 2013-12-17 01:53 -0800
| From | Igor Korot <ikorot01@gmail.com> |
|---|---|
| Date | 2013-12-17 01:53 -0800 |
| Subject | Re: Reading csv file |
| Message-ID | <mailman.4274.1387274024.18130.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web