2017-06-16 88 views
2

我试图导入大熊猫以CSV $$作为分隔符,我希望下面的命令来工作:

pd.read_csv('data.csv', delimiter="$$") 

然而,这将返回以下错误:

Falling back to the 'python' engine because the 'c' engine does not support regex separators (separators > 1 char and different from '\s+' are interpreted as regex), but this causes 'error_bad_lines' to be ignored as it is not supported by the 'python' engine.

是本公司经营甚至有可能在熊猫吗?

回答

3

您可以逃脱$通过\

df = pd.read_csv('data.csv', sep="\$\$", engine='python') 

样品:

import pandas as pd 
from pandas.compat import StringIO 

temp=u"""a$$b 
a$$1 
s$$2 
f$$3""" 
#after testing replace 'StringIO(temp)' to 'filename.csv' 
df = pd.read_csv(StringIO(temp), sep="\$\$", engine='python') 
print (df) 
    a b 
0 a 1 
1 s 2 
2 f 3 
+0

这奏效了,谢谢! – hY8vVpf3tyR57Xib

+0

@Anthon - 谢谢。我很好奇,你如何创建耐克标志?什么是代码? – jezrael

+0

@jezrael我是懒惰的,并从消息文本中复制它。它是Unicode位置0x2417“重复检查标记”。 – Anthon