I would like to apply a specific function to specific columns using polars similar to the following question: Apply name-entity recognition on specific dataframe columns
Above question works with pandas and it is taking ages for me to run it on my computer. So, I would like to use polars. Taking from the above question:
df = pd.DataFrame({'source': ['Paul', 'Paul'],
'target': ['GOOGLE', 'Ferrari'],
'edge': ['works at', 'drive']
})
df()
source target edge
0 Paul GOOGLE works at
1 Paul Ferrari drive
Expected outcome with polars:
source target edge Entitiy
0 Paul GOOGLE works at Person
1 Paul Ferrari drive Person
!python -m spacy download en_core_web_sm
import spacy
nlp = spacy.load('en_core_web_sm')
df['Entities'] = df['Text'].apply(lambda sent: [(ent.label_) for ent in nlp(sent).ents])
df['Entities'][1]
How can I add a column with label(Person) to the current dataframe with polars? Thank you.