1

I am make DataFrame with 2 columns:

Column 1 Column 2
Text1 Text1
Text2 Text2
Text3 Text3

And I need to make another column with entity from column 1 and second with entity from column 2. For example:

Column 1 Column 2 Entity 1 Entity2
Apple is big corpotarion United Kingdom, island country located off the northwestern coast of mainland Europe. ORGname GPE
There are 12 full moons in 2022, and two of them qualify as supermoons. Google has begun investigating and testing solutions. Date ORG
London which was released in 2015, if that gives some perspective placeName Date

How can I do this using Python Spacy library?

Michał
  • 21
  • 3
  • 1. Nothing about this is spaCy specific? Adding columns isn't special because of spaCy. 2. You can't guarantee that there will only be one named entity per sentence. – polm23 Jan 18 '22 at 04:20
  • So if sentence have more than one entity it can be added to column with comma. – Michał Jan 18 '22 at 07:14

1 Answers1

1

The answer for my problem is lambda:

df['Entity1'] = df['column1'].apply(lambda x: list(nlp(x).ents))

This code will add next column with entity from column 1 text.

Michał
  • 21
  • 3