本文介绍了在python中读取没有标题行的csv文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要读取制表符分隔的csv文件而没有11个标题行,如下所示。我怎么能在python中做到这一点?
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
...
非常感谢
Otto
Thanks a lotOtto
推荐答案
你可以使用:
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 ..
这篇关于在python中读取没有标题行的csv文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!