2

I need to read a tab delimited csv file without the 11 header lines as shown below. How can I do this in python?

START:  21.09.2011  11:24:12

TIME STEP:
100 = 10s

VOLTAGE RANGE:
CH1:  255 = 3V  CH3:  255 = 30V
CH2:  255 = 30V CH4:  255 = 30V

N   CH1 Time/s  CH1/V   CH2/V   CH3/V   CH4/V

0   137 0,00    1,612   0,000   0,000   0,000
1   137 0,10    1,612   0,000   0,000   0,000
2   137 0,20    1,612   0,000   0,000   0,000
3   131 0,30    1,541   0,000   0,000   0,000
...

Thanks a lot Otto

1
  • Note that the best way to read the file depends on what you're doing with it, because that affects which library you should use. A simple row-based action? Then csv will be fine. More complicated actions move you through numpy toward pandas. Commented Oct 14, 2013 at 15:58

2 Answers 2

3

You can use itertools.islice:

import csv
import itertools

with open('1.csv') as f:
    lines = itertools.islice(f, 11, None) # skip 11 lines, similar to [11:]
    reader = csv.reader(lines)
    for row in reader:
        ... Do whatever you want with row ..
Sign up to request clarification or add additional context in comments.

Comments

1

You can make use of next -> to skip

Code :

import csv

with open('1.csv') as f:
    csv_rd = csv.reader(f)
    next(csv_rd)

    for row in csv_rd:
        print(row)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.