红楼梦前八十回使用最多的100个字应该怎么做呢,只能做成全文的带标点符号的代码了
from pyecharts import options as opts
from pyecharts.charts import WordCloud
from collections import Counter
import jieba
with open('C:/Users/川野森奈/Desktop/text.txt.txt',encoding='utf-8') as f:
txt=f.read()
words=jieba.lcut(txt)#精准模式
a={}
for word in words:
a[word]=a.get(word,0)+1
items=list(a.items())#将字典转换为记录列表
items.sort(key=lambda x:x[1],reverse=True)#记录第二列排序
for i in range(100):
word,count=items[i]
print("{0:<10}{1:>5}".format(word,count))
, 59318
。 30810
了 20174
的 14630
“ 11851
” 11659
: 11204
我 7318
他 6442
道 6377
说 6149
你 5915
5862
也 5848
是 5789
又 5121
着 3913
去 3815
宝玉 3773
来 3675
不 3283
便 3182
? 3118
3055
在 2919
人 2675
都 2640
有 2572
笑 2489
就 2475
这 2459
叫 1962
! 1905
呢 1816
听 1775
那 1679
等 1668
好 1655
什么 1615
还 1552
要 1492
一个 1452
见 1413
只 1307
贾母 1230
我们 1226
和 1225
上 1214