简体   繁体   中英

How to load Data Frame or csv file in spacy pipeline nlp?

I am trying to load data frame csv into spacy pipeline. I am getting argument string error here is my code.

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)

I tried to load in different ways i got same error.

Platforms : OS - Mac and python 2.7

You should convert variable text to unicode. As you can see for now has str type. As example you can try convert like

document = nlp(unicode(text))

or like

document = nlp(text.decode())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM