【发布时间】:2017-09-07 16:44:09
【问题描述】:
我有一个包含两列的 csv 文件。我正在尝试将该 csv 文件中的第二列读取到 python 中的列表中。我提到了stackoverflow中的一些方法。我试过了,但我得到了一个错误。
noise_amp=[] #an empty list to store the second column
with open('null_ch1_waveform_10mV.csv', 'rb') as rf:
reader = csv.reader(rf, delimiter=';')
for row in reader:
noise_amp.extend([row[1]])
我收到此错误:
Traceback (most recent call last):
File "J:/Ramu_Scripts/noise_script/source_code.py", line 58, in <module>
noise_amp.extend([row[1]])
IndexError: list index out of range
我的 csv 文件是这样的
1,2
2,3
3,4
4,5
【问题讨论】:
-
你能提供一些你的 csv 数据的例子吗?
-
查看When processing CSV data, how do I ignore the first line of data? 的已接受答案,其中显示了如何处理 csv 列中的数据。