Jin_id
Jin_id

Reputation: 23

Applying SpaCy's EntityRecognizer to a column within a Pandas dataframe

I have a text based dataset where I am looking to apply SpaCy's EntityRecognizer to each row for a specific column.

I can apply the general spaCy pipeline by doing something like this:

df['new_col'] = df['col'].apply(lambda x: nlp(x))

How do I just apply just the entity recongnizer and get its values?

Upvotes: 2

Views: 4698

Answers (1)

tuxmam
tuxmam

Reputation: 51

In Spacy a doc have a attribute .ents witch return a generator on its named entities.

So you can use :

df['new_col'] = df['col'].apply(lambda x: list(nlp(x).ents))

Upvotes: 5

Related Questions