簡體   English   中英

Python NLTK FreqDist - 列出頻率大於 1000 的單詞

[英]Python NLTK FreqDist - Listing words with a frequency greater than 1000

我試圖輸出出現在我的標記中的每個單詞超過 1000 次(> 1000)並將其保存到 freq1000。

freq1000 = []

newtokens = []

for words in tokens:
    newtokens += words
FreqDist(newtokens)

fd_1 = FreqDist(newtokens)

for i in set(fd_1):
    if fd_1.count(i) == >1000:
        print(i)

這是我當前的代碼,在此之后我完全卡住了,我不確定是否有一個 freqdist 函數可以用來提供幫助。 我已成功將 FreqDist 保存到 fd_1。 我只是不確定如何獲得出現超過 1000 次的單詞的輸出並將其保存到 freq1000。

如果您能提供任何幫助,我將不勝感激。

您可以使用freqDist.items()根據頻率計數過濾單詞,如下所示:

 list(filter(lambda x: x[1]>=1000, fd_1.items()))

希望能幫助到你 :)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM