中文词频统计

复制代码
import jieba

a=open('C:/1.txt','r',encoding='utf-8').read()


for i in '\n,.\()。,123"?':
    a=a.replace(i,' ')

b=jieba.cut(a)
d=list(b)

exc={' ','和','你','使','都','所','又','一个','啊', '也是', '的','了','(','…','阿','廖沙','也','是','对','就','“','”','地','他','她'}
dict={}
key=set(d)
key=key-exc

print(key)

for i in key:
    
    dict[i]=d.count(i)

st=list(dict.items())
st.sort(key=lambda x:x[1],reverse=True)
print(st)
for i in range(20):
    print(st[i])
复制代码

posted on 2017-09-29 19:16  137陈楚洪  阅读(86)  评论(0编辑  收藏  举报

导航