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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.