Python – 移除停用词
停用词即在英语句子中并不具有实际意义,可以忽略不计而不影响句意的诸如the, he, have等单词。这些单词已被一个语料库(corpus)命名为stopwords。我们首先下载该文件到Python环境中。
它会下载一个包含英语停用词的文件。
验证停用词
当我们运行上述程序时,我们得到以下输出 −
[u'your', u'yours', u'yourself', u'yourselves', u'he', u'him', u'his', u'himself', u'she',
u"she's", u'her', u'hers', u'herself', u'it', u"it's", u'its', u'itself', u'they', u'them',
u'their', u'theirs', u'themselves', u'what', u'which', u'who', u'whom', u'this',
u'that', u"that'll", u'these', u'those', u'am', u'is', u'are', u'was', u'were', u'be',
u'been', u'being', u'have', u'has', u'had', u'having', u'do', u'does', u'did', u'doing',
u'a', u'an', u'the', u'and', u'but', u'if', u'or', u'because', u'as', u'until',
u'while', u'of', u'at']
以下语言中也有这些停用词。
当我们运行上述程序时,我们得到以下输出 −
示例
我们使用以下示例来展示如何从单词列表中删除停用词。
当我们运行上述程序时,我们得到以下输出 −