2017-08-29 77 views
0

我想加载数据帧csv到spacy管道。我得到的参数字符串错误这里是我的代码。如何在sparse pipeline nlp中加载数据框或csv文件?

from __future__ import unicode_literals 
nlp = spacy.load('en') 

data = pd.read_csv("sometextdata.csv") 
text = [] 
for line in data.Line: 
    text.append(clean_text(line)) 

    text_spacy = nlp(data['Line']) 
    data['Line'].apply(nlp) 
    document = nlp(text) 
TypeError: Argument 'string' has incorrect type (expected unicode, got str) 

我试图以不同的方式加载我得到同样的错误。

平台:操作系统 - Mac和蟒蛇2.7

回答

1

你应该可变文本转换为Unicode。正如你现在可以看到的str类型。作为例子,你可以尝试转换像

document = nlp(unicode(text)) 

或类似

document = nlp(text.decode())