如何使用 FreqDist 中的 fd.items() 来总结词频数?
>>> fd = FreqDist(text)
>>> most_freq_w = fd.keys()[:10] #gives me the most 10 frequent words in the text
>>> #here I should sum up numbers of each of these 10 freq words appear in the text
例如如果most_freq_w
中的每个词出现10次,结果应该是100
!!!我不需要文本中所有单词的数量,只需要最常见的 10 个
最佳答案
我不熟悉 nltk
,但由于 FreqDist
派生自 dict
,因此以下内容应该有效:
v = fd.values()
v.sort()
count = sum(v[-10:])
关于python - 使用FreqDist,python总结词频数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4206979/