Extract entity from dataframe using spacy

前端 未结 2 914
再見小時候
再見小時候 2021-01-28 19:36

I read contents from excel file using pandas::

import pandas as pd
df = pd.read_excel(\"FAM_template_Update 1911274_JS.xlsx\" )
df

While trying

相关标签:
2条回答
  • 2021-01-28 20:07

    You need to loop through the individual strings within your dataframe. The NLP parser and entity extraction is expecting a string.

    For example:

    for row in range(len(df)):
        doc = nlp(df.loc[row, "text_column"])
        for enitity in doc.ents:
             print((entity.text))
    
    0 讨论(0)
  • 2021-01-28 20:21

    This is expected as Spacy is not prepared to deal with a dataframe as-is. You need to do some work before being able to print the entities. Start by identifying the column that contains the text you want to use nlp on. After that, extract its value as list, and now you're ready to go. Let's suppose the column name that contains the text is named Text.

    for i in df['Question'].tolist():
        doc = nlp(i)
        for entity in doc.ents:
             print((entity.text))
    

    This will iterate over each text (row) for in your dataframe and print the entities.

    0 讨论(0)
提交回复
热议问题