2017-06-16 93 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