python詞頻統計例項

2021-10-08 11:52:58 字數 604 閱讀 7141

# 詞頻統計

import jieba # 分詞庫包

import snownlp # 情感分析

words =

'非常時尚鞋子,非常非常非常時尚的一款鞋子,設計好看,設計設計做活動買的,超超超超超超超超超划算。滿意。設計好看!'

words_list =

list

(jieba.cut(words)

)words_frequency =

for wl in words_list:

if wl in words_frequency.keys():

words_frequency[wl]+=1

else

: words_frequency[wl]=1

a=words_frequency.items(

)words_sort =

sorted

(words_frequency.items(

),key=

lambda x:x[1]

,reverse=

true

)print

(words_sort)

Python例項 文字詞頻統計

最近在mooc跟著北京理工大學的嵩天老師學習python 受益匪淺,老師所講的通俗易懂,推薦給大家。在此記點筆記和注釋,備忘。今天所記得是文字詞頻統計 hamlet文字詞頻統計。直接上源 calhamletv1.py def gettext txt open e hamlet.txt r read ...

Python 統計詞頻

calhamletv1.py def gettext txt open hamlet.txt r read txt txt.lower for ch in txt txt.replace ch,將文字中特殊字元替換為空格 return txt hamlettxt gettext words haml...

python 詞頻統計

import re 正規表示式庫 import collections 詞頻統計庫 f open text word frequency statistics.txt article f.read lower 統一轉化成小寫 f.close pattern re.compile t n articl...