如何在数据集中使用read_csv断开管道“|”作为seprator ???

时间:2018-03-09 02:08:49

标签: python pandas broken-pipe

我有10个文件数据集10mb到8gb,我正在尝试读取一个大小为8gb的数据集txt,由于“|”(断管),我无法读取...几乎所有大小都超过200mb的数据集同样的问题和最小的文件有“普通”管道(|)。

代码是:

p = 0.001  # % of lines

df = pd.read_csv("protectedSearch_GPRS.txt", sep='¦', 
                    skiprows= lambda i: i>0 and random.random() > p)


     ParserWarning: Falling back to the 'python' engine because the separator 
     encoded in utf-8 is > 1 char long, and the 'c' engine does not support such 
     separators; you can avoid this warning by specifying engine='python'.
       after removing the cwd from sys.path.

那究竟是什么?这是一个错误吗?如何处理这个问题?我试图解决这个有2天,我真的不知道该怎么做。

非常感谢,对不起任何语言错误。

1 个答案:

答案 0 :(得分:2)

不是错误。 Pandas C引擎仅支持单字符分割。断管在技术上是两个UTF-8字符,因此错误为character is > 1

例如:

len('¦'.encode('utf-8'))
Out[24]: 2
len(','.encode('utf-8'))
Out[25]: 1

如果要取消警告,请明确说明您要使用的引擎:

df = pd.read_csv(
      "protectedSearch_GPRS.txt", 
      sep='¦', 
      skiprows=lambda i: i > 0 and random.random() > p,
      engine='python'
)

使用engine=python可以匹配多字符串/正则表达式拆分。