parent
4034c37d19
commit
aea6a2bda6
@ -0,0 +1,30 @@
|
|||||||
|
import jieba # 引入分词模块
|
||||||
|
import wordcloud # 引入词云图配置模块
|
||||||
|
|
||||||
|
|
||||||
|
# 1、对bili.txt进行读取
|
||||||
|
f = open("全弹幕.txt",encoding="utf-8")
|
||||||
|
text = f.read()
|
||||||
|
|
||||||
|
|
||||||
|
# 2、对弹幕数据进行分词操作
|
||||||
|
word_list = jieba.lcut(text)
|
||||||
|
for word in word_list:
|
||||||
|
with open('全弹幕分词.xls',mode='a',encoding='utf-8') as f:
|
||||||
|
f.write(word)
|
||||||
|
f.write('\n')
|
||||||
|
|
||||||
|
|
||||||
|
# 3、将分割出的词连接成字符串
|
||||||
|
word_str = ' '.join(word_list)
|
||||||
|
|
||||||
|
|
||||||
|
# 4、进行词云图相关配置
|
||||||
|
wcdd = wordcloud.WordCloud(
|
||||||
|
width=600, # 宽度
|
||||||
|
height=600, #高度
|
||||||
|
background_color='white', # 背景颜色
|
||||||
|
font_path='msyh.ttc' # 字体文件
|
||||||
|
)
|
||||||
|
wcdd.generate(word_str)
|
||||||
|
wcdd.to_file('全弹幕词云.png')
|
Loading…
Reference in new issue