我从 here 得到了问题随着我的改变。我有以下代码:
from nltk.corpus import stopwords
def content_text(text):
stopwords = nltk.corpus.stopwords.words('english')
content = [w for w in text if w.lower() in stopwords]
return content
如何打印文本中 1)包括 和 2)排除 停用词的 10 个最常出现的词?
最佳答案
nltk中有一个FreqDist函数
import nltk
allWords = nltk.tokenize.word_tokenize(text)
allWordDist = nltk.FreqDist(w.lower() for w in allWords)
stopwords = nltk.corpus.stopwords.words('english')
allWordExceptStopDist = nltk.FreqDist(w.lower() for w in allWords if w not in stopwords)
提取 10 个最常见的:
mostCommon= allWordDist.most_common(10).keys()
关于python - 打印包含和排除停用词的文本中 10 个最常出现的词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28392860/