0

Hi everyone,

I need to use python to read some data in my csv file, but the file I have contains 15 rows of introduction in front. all the data I need is from the row 16. I am able to read the data as the way I want it if I remove the first 15 rows, but it's very troublesome to do it every time and I have a lot of csv files like that.

so I want to know if there is a way to let python skip the first 15 rows just read from row 16?

below is my code

import csv
import time
import datetime

tempReadings = csv.reader(open('newdata3.csv','rb'),delimiter=',')

for reading in tempReadings:

print "got: %s" % reading
(timestamp, format, temp) = reading

print "timestamp: %s" % timestamp

print "temp: %s" % temp

Thanks

2
Contributors
1
Reply
4
Views
5 Years
Discussion Span
Last Post by pyTony
0
import csv
import time
import datetime

tempReadings = csv.reader(open('newdata3.csv','rb'),delimiter=',')

for reading in tempReadings:

    print "got: %s" % reading
    (timestamp, format, temp) = reading

    print "timestamp: %s" % timestamp

    print "temp: %s" % temp

Learn to push [CODE] before paste.
I think you can use itertools.islice to read from 16th value in the csv.reader. I mostly use manual split, strip routine instead of csv. If I had quoted values in files, then csv module would be good choice, otherwise I DIY. If you have choice, for me the best separator choice is semi comma.

Edited by pyTony: fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.