中文词频统计
中文分词
- 下载一中文长篇小说,并转换成UTF-8编码。
- 使用jieba库,进行中文词频统计,输出TOP20的词及出现次数。
- 排除一些无意义词、合并同一词。
- 对词频统计结果做简单的解读。
import jieba news=open('小说.txt','r',encoding='utf-8').read() words=list(jieba.cut(news)) exp={'人','的','但是','他们','这个','一','已','啊','了'} dic={} keys=set(words)-exp for w in keys: if len(w)>1: dic[w]=words.count(w) a=list(dic.items()) a.sort(key=lambda x:x[1],reverse=True) for i in range(20): print(a[i])


浙公网安备 33010602011771号