python - Pandas .errors.ParserError : Error could possibly be due to quotes being ignored when a multi-char delimiter is used

标签 python pandas csv parsing

我在尝试使用 Pandas 读取 csv 文件时收到 ParserError。下面给出了错误和引发此错误的数据集。

pandas.errors.ParserError: Expected 10 fields in line 8, saw 11. Error could possibly be due to quotes being ignored when a multi-char delimiter is used.

下面给出的是出现这个错误的第 8 行

10/29/18 10:20,85505306,    Scott,20181029102023-file.csv,  22.49,-12.18,CITY,,12:15.0,51:00.0,ABCD,9898,320,D231

我正在使用以下命令读取 csv:

df.to_csv('file.csv'), index = False)

csv 文件的示例输出:

File_Received_Time  Label1  City    FileName    Label2  Label3  State   Unnamed: 12 cTimestamp  dTimestamp  Label4  Label5  Label6  Label7  Label8
10/29/18 10:20  56776   Paris   file1.csv   29  29  IL      29-10-2018 04:11:11     COL06   620 398 516 451
10/29/18 10:20  46069   Hongkong    file2.csv   61  58  VA      29-10-2018 04:03:17 28-10-2018 05:58:00 COL06   576 645 349 374
10/29/18 10:20  47240   Sydney  file3.csv   43  42  IL      29-10-2018 04:12:46     COL06   534 2047    56831   372
10/29/18 10:20  47432   NewYork file4.csv   55  61  OH          28-10-2018 09:01:00 COL06   514 2354    640 633
10/29/18 10:20  41794   London  file5.csv   39  29          29-10-2018 04:12:46 28-10-2018 09:01:00 COL06   470 2354    56831   550
10/29/18 10:20  49643   LA  file6.csv   55  43  TX      29-10-2018 04:05:18     COL06   523 2301    53942   403
10/29/18 10:20  54700   Shangai file7.csv   37  29  AZ      29-10-2018 04:12:15 28-10-2018 12:51:00 COL06   569 2683    53642   538
10/29/18 10:20  37134   Singapore   file8.csv   53  62  AZ      29-10-2018 04:09:16     COL06   560 391 54541   542
10/29/18 10:20  51144   Taiwan  file9.csv   43  33  TX      29-10-2018 04:12:15     COL06   469 472 458 481

最佳答案

您可以解决 pandas.errors.ParserError: Error could possibly be due to quotes being ignored when a multi-char delimiter is used 通过使用:

df = pd.read_csv("train.tsv",index_col = False,sep="\t")

Example working code in Jupyter

关于python - Pandas .errors.ParserError : Error could possibly be due to quotes being ignored when a multi-char delimiter is used,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53066229/

相关文章:

PHPExcel CSV 到 XLSX

python - 无法解析使用 Flask 上传的 .csv 文件

Python、BeautifulSoup - <div> 文本和 <img> 属性顺序正确

python - 覆盖枚举 __call__ 方法

python - C python 扩展中的段错误

python - 如何计算一个实体与另一个实体一起出现的次数

python - 填充不保留所有列

python - Pandas 与 PEP8 : Selecting True values in a Series with mixed types

java - 使用 JAVA testNG 从 CSV 读取时出现 ArrayIndexOutOfBoundsException,但为什么呢?

python - np.power 做了哪些额外的工作?