python - 使用FreqDist,python总结词频数

标签 python nltk frequency-distribution

如何使用 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/

相关文章:

python - Python中反向排序列表的二进制搜索

Python 权限问题 Ubuntu

python - 如何使用 Keras 确定类别?

python - 如何通过保存训练好的模型来减少使用 pickle 的编译时间?

python - 如何在保持数据分布的同时从 python 列表中随机抽样

r - 如何在具有丰度数据的表上进行 PCA,但将其与 R 中站点的环境参数向量叠加?

python - 动态模板标签

python - NLTK tokenizer 和 Stanford corenlp tokenizer 无法区分句号 (.) 处没有空格的 2 个句子

python - 使用 NLTK 和德语语料库从名词中获取性别

r - 频率分布表