首先,通过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编码即可。
![](http://upload-images.jianshu.io/upload_images/3629157-0a02fb53b548ef2a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/719/format/webp)
运行部分结果图:
![](http://upload-images.jianshu.io/upload_images/3629157-92b7bde467cb13f8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/524/format/webp)
词云制作
(1)打开taglue官网,点击import words,把运行的结果copy过来。
(2)选择形状,在这里是网上下载的图片进行的导入。
(3)选择字体。
(4)点击Visualize生成图片。
![](http://upload-images.jianshu.io/upload_images/3629157-6566ebc1942456b3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)