jieba库和好玩的词云

首先,通过pip3 install jieba安装jieba库,随后在网上下载《斗破》。

代码如下:

import jieba.analyse

path = '小说路径'

fp = open(path,'r',encoding='utf-8')
content = fp.read()
try:
    jieba.analyse.set_stop_words('停用词表路径')
    tags = jieba.analyse.extract_tags(content, topK=100, withWeight=True)
    for item in tags:
        print(item[0]+'\t'+str(int(item[1]*1000)))

finally:
    fp.close()

大家运行程序可能会报错,是编码问题,我们这时需打开下载的txt文档,另存为,选择utf-8编码即可。


 
 

运行部分结果图:


 
 

词云制作

(1)打开taglue官网,点击import words,把运行的结果copy过来。
(2)选择形状,在这里是网上下载的图片进行的导入。
(3)选择字体。
(4)点击Visualize生成图片。


 




posted @ 2019-04-03 22:17  hy120040  阅读(128)  评论(0编辑  收藏  举报