Amanda Morrow
Amanda Morrow

Reputation: 33

Python spaCy - Argument 'string' has incorrect type (expected str, got DataFrame)

I am trying to use spaCy and I am having trouble with this error that I am receiving.

Set up spaCy

from spacy.lang.en import English
parser = English()

import en_core_web_sm
nlp = en_core_web_sm.load()

comment = data['comment']

This is the line of code causing the error:

comment = nlp(comment)

Upvotes: 2

Views: 4178

Answers (1)

Adnan S
Adnan S

Reputation: 1882

data['comment']

returns a pandas series. Spacy is expecting a list. You should convert the pandas series to list using tolist() command and then pass to Spacy - refer to SO question here

comment = data['comment'].tolist()

Upvotes: 3

Related Questions