簡體   English   中英

使用熊貓read_csv讀取此制表符分隔的文件時,行丟失

[英]Rows are lost when reading this tab-separated file with pandas read_csv

我有一個具有以下格式的.text文件,其中的字段(索引號,名稱和消息)由\\t分隔(制表符分隔):

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
...

我用read_csv將其讀入數據幀:

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

但是數據幀只有9812行,而普通文件有12428行(僅21空行)。 這很奇怪。 你有什么主意嗎? 謝謝。

我認為您需要添加參數quoting

import csv

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM