中文词频统计
.中文分词
1.下载一中文长篇小说,并转换成UTF-8编码。
2.使用jieba库,进行中文词频统计,输出TOP20的词及出现次数。
3.排除一些无意义词、合并同一词。
4.对词频统计结果做简单的解读
import jieba txt=open('test.txt','r',encoding='UTF-8').read() for i in '''.,-\n\t\u3000'()":“”,。‘’?''': txt=txt.replace(i,'') words=list(jieba.cut(txt)) exc={'了','么','吗','他','我','你','她','是','在','也','都','的','但','很','着'} dic={} keys=set(words) keys=keys-exc for w in keys: dic[w]=words.count(w) wc = list(dic.items()) wc.sort(key=lambda x:x[1],reverse=True) for w in range(20): print(wc[w])

浙公网安备 33010602011771号