【发布时间】:2021-06-22 06:01:04
【问题描述】:
我有一个 df,其中有一列包含我想从中提取组织的 cmets。这个article 提供了一个很好的方法,但是对于我的问题来说它太慢了。我使用的 df 有超过 1,000,000 行,并且我使用的是 Google Colab 笔记本。
目前我的方法是(来自链接的文章):
def get_orgs(text):
# process the text with our SpaCy model to get named entities
doc = nlp(text)
# initialize list to store identified organizations
org_list = []
# loop through the identified entities and append ORG entities to org_list
for entity in doc.ents:
if entity.label_ == 'ORG':
org_list.append(entity.text)
# if organization is identified more than once it will appear multiple times in list
# we use set() to remove duplicates then convert back to list
org_list = list(set(org_list))
return org_list
df['organizations'] = df['body'].apply(get_orgs)
有没有更快的方法来处理这个?而且,您会建议将其应用于 Pandas df 还是有更好/更快的替代方案?
【问题讨论】:
-
这个问题的答案也可能有用:stackoverflow.com/questions/66780391/…
标签: python pandas spacy named-entity-recognition