问题
I have a .text
file with following format, where fields (index number, name and message) are separated by \t
(tab-separated):
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
...
which I read with read_csv
into a data frame:
chat = pd.read_csv("f.text", sep = "\t", header = None, usecols = [2])
But the data frame just has 9812
rows while the ordinary file has more than 12428
rows (just 21 empty lines). It is quite weird. Do you have any idea? Thanks.
回答1:
I think you need add parameter quoting
:
import csv
chat = pd.read_csv("f.text",sep = "\t", header = None, usecols = [2], quoting=csv.QUOTE_NONE)
来源:https://stackoverflow.com/questions/35598249/rows-are-lost-when-reading-this-tab-separated-file-with-pandas-read-csv