【发布时间】:2021-03-16 21:58:24
【问题描述】:
用于从 FlashText 中提取关键字的 KeywordProcessor 在数据帧的末尾返回 NaN。数据框的形状是(14.532.885, 6),其中只有一列(包含句子)用于提取某些关键字。
在第 14.452.474 行之前正确应用了关键字提取。换句话说,提取不会应用于句子列中的最后 80.411 行。
from flashtext import KeywordProcessor
kp = KeywordProcessor()
kp.add_keywords_from_dict(keyword_dict=keywords_dict)
df['keywords'] = df['text'].apply(lambda sentence: kp.extract_keywords(sentence=sentence, span_info=False))
df[['text', 'keywords']][14452474:14452480]
output:
text keywords
14452474 it is monsoon season in stl today rain rain r... [friendly]
14452475 hahahah pidgeons then []
14452476 nothing planned maybe ill go stay with u and h... []
14452477 he wont disappoint NaN
14452478 hi doc dickerson howdy opened a new twitter ac... NaN
14452479 only one more class left for today then im hom... NaN
【问题讨论】:
标签: python pandas dataframe keyword