python - 使用 Pandas 导入数据时遇到错误
问题描述
所以当我尝试运行 pd.read_csv 函数时,这就是错误的样子,我完全被卡住了。而且我还检查了我是否在数据所在的同一目录中,就是这样
如果知道这里发生了什么,请提供帮助:
PS:数据文件大小为14MB
---------------------------------------------------------------------------
ParserError Traceback (most recent call last)
<ipython-input-28-2a5563273d31> in <module>
----> 1 data=pd.read_csv('ufo_data.csv',header=None)
2 data.head()
3
D:\Anaconda\lib\site-packages\pandas\io\parsers.py in read_csv(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, cache_dates, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, dialect, error_bad_lines, warn_bad_lines, delim_whitespace, low_memory, memory_map, float_precision)
684 )
685
--> 686 return _read(filepath_or_buffer, kwds)
687
688
D:\Anaconda\lib\site-packages\pandas\io\parsers.py in _read(filepath_or_buffer, kwds)
456
457 try:
--> 458 data = parser.read(nrows)
459 finally:
460 parser.close()
D:\Anaconda\lib\site-packages\pandas\io\parsers.py in read(self, nrows)
1194 def read(self, nrows=None):
1195 nrows = _validate_integer("nrows", nrows)
-> 1196 ret = self._engine.read(nrows)
1197
1198 # May alter columns / col_dict
D:\Anaconda\lib\site-packages\pandas\io\parsers.py in read(self, nrows)
2153 def read(self, nrows=None):
2154 try:
-> 2155 data = self._reader.read(nrows)
2156 except StopIteration:
2157 if self._first_chunk:
pandas\_libs\parsers.pyx in pandas._libs.parsers.TextReader.read()
pandas\_libs\parsers.pyx in pandas._libs.parsers.TextReader._read_low_memory()
pandas\_libs\parsers.pyx in pandas._libs.parsers.TextReader._read_rows()
pandas\_libs\parsers.pyx in pandas._libs.parsers.TextReader._tokenize_rows()
pandas\_libs\parsers.pyx in pandas._libs.parsers.raise_parser_error()
ParserError: Error tokenizing data. C error: Expected 11 fields in line 877, saw 12
解决方案
刚刚添加了一个这样的分隔符,它得到了修复:
data=pd.read_csv("File_path", sep='\t')
推荐阅读
- javascript - 如何访问 div 中的图像属性?jQuery
- selenium - Google 搜索按钮的元素名称是什么?
- javascript - 如何将 JavaScript 中的主机名和布尔值与 if/else 进行比较以在 Mongo Shell 中执行?
- python - 如何使用循环来减少python中的代码
- python - 在 Python 中关闭文件
- javascript - 如何使用switch语句查找json对象中是否存在键值对
- python - 词向量相似精度
- java - Hibernate:在 Hibernate 5.4.x 版本中运行此 SQL 查询“alter session enable parallel dml”时出错
- javascript - JavaScript 待办事项列表 - 删除按钮仅出现在最近添加的项目上
- powershell - 此平台不支持 Windows 加密下一代 (CNG) 来自 AWS-Lambda 的 PowerShell