中文词频统计
中文分词
- 下载一中文长篇小说,并转换成UTF-8编码。
- 使用jieba库,进行中文词频统计,输出TOP20的词及出现次数。
- 排除一些无意义词、合并同一词。
- 对词频统计结果做简单的解读。
import jieba #使用jieba库 novel=open('C:\\novel.txt','r',encoding='utf-8').read() #中文长篇小说转换成UTF-8编码 words=list(jieba.cut(novel)) #中文分词 exp={',','。',':','“','”'} #排除无意义词、合并同一词 keys=set(words)-exp dic={} for w in keys: if len(w)>1: dic[w]=words.count(w) txt=list(dic.items()) txt.sort(key=lambda x:x[1],reverse=True) for i in range(20): #中文词频统计,输出TOP20的词及出现次数 print(txt[i])
![]()
- 唐僧师徒途径女儿国,几经波折取得关文才得以脱身。

浙公网安备 33010602011771号