使用FreqDist总结词频数,python
如何使用 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 个最常见的
How to sum up the number of words frequency using fd.items() from FreqDist?
>>> 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
e.g. if each word in most_freq_w
appear 10 times, the result should be 100
!!! I don't need that number of all words in the text, just the 10 most frequent
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不熟悉
nltk
,但由于FreqDist
派生自dict
,因此以下内容应该有效:I'm not familiar with
nltk
, but sinceFreqDist
derives fromdict
, then the following should work:要查找某个单词在语料库(您的一段文本)中出现的次数:
To find the number of times a word appears in the corpus(your piece of text):
它有一个漂亮的打印功能
就可以做到这一点。
It has a pretty print feature
will do it.
如果 FreqDist 是单词到频率的映射:
If
FreqDist
is a mapping of words to their frequencies: