如何附加从 DataFrame 中提取的命名实体?

How to append Named Entites extracted from DataFrame?

以下从 df['Article'] 中提取并打印实体的代码工作正常。

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

但每当我尝试使用 entities_list.append((entity.text)) append 这些实体时,我都会收到 TypeError: object of type 'float' has no len() 错误 我尝试使用以下方式创建 entities_list=[]

entities_list = []
for i in df['Article'].to_list():
    doc = nlp(i)
    for entity in doc.ents:
        print((entity.text))

以及

for i in df['Article'].to_list():
    entities_list = []
    doc = nlp(i)
    for entity in doc.ents:
        print((entity.text))

此外,即使我尝试创建另一个 DataFrame 或向 df 添加新列,我也会遇到同样的错误。有人可以帮助解决我在这里做错了什么吗?谢谢

编辑:
df['Articles'] 中的数据是新闻文本,如

Pence’s move comes as inoculation efforts are unfurling around the world in the race to halt a pandemic that has claimed at least 1.66 million lives and infected more than 74 million people.

第一个代码打印从文本中提取的实体,但我需要将这些实体附加到列表中,如下所示

[entity1, entity2, entity3, entity4]

文章栏似乎有一些缺失值,请执行以下操作:

entities_list = []
for i in df['Article'].fillna('').to_list():
    doc = nlp(i)
    for entity in doc.ents:
        entities_list.append((entity.text))