Traceback (most recent call last): File "E:\liuyuan\signal processing\zuixin\信号处理\3.py", line 7, in <module> data = pd.read_csv(file_name, skiprows=1, usecols=[0, 1, 2], names=['Time', 'Flow']) File "C:\Users\Yang\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\io\parsers.py", line 610, in read_csv return _read(filepath_or_buffer, kwds) File "C:\Users\Yang\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\io\parsers.py", line 462, in _read parser = TextFileReader(filepath_or_buffer, **kwds) File "C:\Users\Yang\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\io\parsers.py", line 819, in __init__ self._engine = self._make_engine(self.engine) File "C:\Users\Yang\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\io\parsers.py", line 1050, in _make_engine return mapping[engine](self.f, **self.options) # type: ignore[call-arg] File "C:\Users\Yang\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\io\parsers.py", line 1898, in __init__ self._reader = parsers.TextReader(self.handles.handle, **kwds) File "pandas\_libs\parsers.pyx", line 518, in pandas._libs.parsers.TextReader.__cinit__ File "pandas\_libs\parsers.pyx", line 742, in pandas._libs.parsers.TextReader._get_header ValueError: Passed header names mismatches usecols
时间: 2023-07-17 17:02:33 浏览: 158
linux 下 pip3 报错“ File “/usr/bin/pip3”, line 9, in from pip import mainImportError: canno”处理
5星 · 资源好评率100%
这个错误是由于传递给`read_csv`函数的`usecols`参数与`names`参数的长度不匹配引起的。`usecols`参数用于指定要读取的列,而`names`参数用于指定列的名称。请确保这两个参数的长度一致。
在你的代码中,你指定了`usecols=[0, 1, 2]`,表示你只想读取文件中的前三列。然后你指定了`names=['Time', 'Flow']`,但是这个列表中只有两个元素,与`usecols`中指定的列数不匹配。
你可以将`names`参数修改为`names=['Time', 'Flow', 'Column3']`,其中`Column3`可以是任意名称,以匹配`usecols`中指定的三列。这样就能解决这个错误了。
阅读全文