首页 > 解决方案 > 读取 csv 文件时出现问题

问题描述

我有以下形式的大 csv 文件:

Model,DPO4034
Firmware Version,2.48

Point Format,Y,,,
Horizontal Units,S,,,
Horizontal Scale,4e-05,,,
Sample Interval,4e-10,,,
Record Length,1e+06,,,
Gating,0.0% to 100.0%,0.0% to 100.0%,0.0% to 100.0%,0.0% to 100.0%
Probe Attenuation,50,10,1000,50
Vertical Units,V,A,V,V
Vertical Offset,0,0,0,0
Vertical Scale,50,10,200,50
Label,,,,
TIME,CH1,CH2,CH3,CH4
-1.982936e-04,-5.13281,3.12188,-15,3.83594
-1.982932e-04,-5.14844,3.16719,-14.6875,4.32031
-1.982928e-04,-5.33594,3.15313,-14.9375,4.08594
-1.982924e-04,-5.46875,3.15313,-15.25,4.125
-1.982920e-04,-5.3125,3.14375,-16.5312,4.50781
-1.982916e-04,-5.82812,3.24219,-15.8125,4.80469
-1.982912e-04,-5.53906,3.3,-15,4.72656
-1.982908e-04,-5.50781,3.28906,-15.6875,4.9375
-1.982904e-04,-5.64062,3.27031,-15.8438,4.08594
-1.982900e-04,-5.35156,3.20781,-15.125,3.83594
-1.982896e-04,-5.53906,3.16094,-18.0312,3.89844
-1.982892e-04,-5.51562,3.09531,-17.9688,4.64844

我对 TIME、CH1、CH2、CH3 和 CH4 的值感兴趣。当我尝试使用python如下方式阅读它时:

import pandas
csv_file = pandas.read_csv(my_csv_file,error_bad_lines=False)

我收到以下错误:

expected 2 fields, saw 5\nSkipping liTraceback (most recent call last):
File "C:\Users\lsee\Desktop\Mustapha\Definition\mesures.py", line 23, in <module>
csv_file = pandas.read_csv('Mesures.csv',error_bad_lines=False)
File "C:\Program Files\Python37\lib\site-packages\pandas\io\parsers.py", line 610, in read_csv
return _read(filepath_or_buffer, kwds)
File "C:\Program Files\Python37\lib\site-packages\pandas\io\parsers.py", line 468, in _read
return parser.read(nrows)
File "C:\Program Files\Python37\lib\site-packages\pandas\io\parsers.py", line 1057, in read
index, columns, col_dict = self._engine.read(nrows)
File "C:\Program Files\Python37\lib\site-packages\pandas\io\parsers.py", line 2061, in read
data = self._reader.read(nrows)
File "pandas\_libs\parsers.pyx", line 756, in pandas._libs.parsers.TextReader.read
File "pandas\_libs\parsers.pyx", line 771, in pandas._libs.parsers.TextReader._read_low_memory
File "pandas\_libs\parsers.pyx", line 827, in pandas._libs.parsers.TextReader._read_rows
File "pandas\_libs\parsers.pyx", line 809, in pandas._libs.parsers.TextReader._tokenize_rows

知道我做错了什么吗?

标签: python-3.xpandascsv

解决方案


推荐阅读