如何删除“to”、“and”、“from”、“this”等常用单词。我只对“人工智能”、“数据”、“学习”、“机器”、“人工”这些词感兴趣。
发布于 2019-03-06 19:12:37
我认为您要删除的是诸如' to ',' the‘等停用词。nltk有一个预定义的停用词列表:
from nltk.corpus import stopwords
stop_words = stopwords.words('english')
stop_words
['i',
'me',
'my',
'myself',
'we',
'our',
'ours',
'ourselves',
'you',...您可以使用np.where用np.nan替换停用词
title_analysis['new_col'] = np.where(title_analysis['words'].str.contains(stopwords), np.nan, title_analysis['words'])然后执行value_counts()
title_analysis['new_col'].value_counts()如果您有自己想忽略的单词集,只需将stop_words替换为您的单词列表即可。
https://stackoverflow.com/questions/55021565
复制相似问题