中文词频统计

中文分词

  1. 下载一中文长篇小说,并转换成UTF-8编码。
  2. 使用jieba库,进行中文词频统计,输出TOP20的词及出现次数。
  3. 排除一些无意义词、合并同一词。
  4. 对词频统计结果做简单的解读。
import jieba
fo = open('傲慢与偏见前十章.txt','r',encoding='utf-8').read()
words = list(jieba.cut(fo,cut_all=True))

for i in ''',。:‘’“”?!\n \u3000\u3000''':
    fo = fo.replace(i,' ')
words = fo.split(' ')
exp={'','','','她说',''}
dic={}
keys=set(words)-exp
for w in keys:
    dic[w]=words.count(w)

wc = list(dic.items()) 
wc.sort(key= lambda x:x[1],reverse=True)

for i in range(20):
    print(wc[i])

 

posted @ 2017-09-29 11:58  105杨捷丽  阅读(106)  评论(0编辑  收藏  举报