pandas中的read_csv会丢失行

时间:2016-02-24 09:32:45

标签: python pandas

我有一个.text文件,格式如下:

712 ben     Battle of the Books
713 james   i used to be in TOM
714 tomy    i was in BOB once
715 ben Tournaments of Minds
716 tommy    Also the Lion in the upcoming school play
717 tommy   Can you guess
718 tommy    P
...

索引号,姓名和消息由\t分隔。我使用read_csv来读取文件并将其存储为数据框:

 chat = pd.read_csv("f.text", sep = "\t", header = None, usecols = [2])

但是数据框只有9812行,而普通文件有超过12428行(只有21行)。这很奇怪。你有什么主意吗?感谢。

1 个答案:

答案 0 :(得分:6)

我认为您需要添加参数quoting

import csv

chat = pd.read_csv("f.text",sep = "\t", header = None, usecols = [2], quoting=csv.QUOTE_NONE)