ADD file via upload

main
puz372fkg 2 months ago
parent e6843c379a
commit f794bc925c

@ -0,0 +1,49 @@
import jieba # 引入分词模块
import wordcloud # 引入词云图配置模块
import imageio # 引入图片模块,改变词云图形状
# 1、对弹幕进行读取
f = open("全弹幕.txt",encoding="utf-8") # 读取全弹幕
text = f.read()
f1 = open("AI弹幕.txt",encoding="utf-8") # 读取AI弹幕
text1 = f1.read()
# 2、对弹幕数据进行分词操作
word_list = jieba.lcut(text) #对全弹幕进行分词
for word in word_list:
with open('全弹幕分词.xls',mode='a',encoding='utf-8') as f: # 将全弹幕分词保存在xls表中
if word != '\n': # 防止输入换行字符
f.write(word)
f.write('\n')
word_list1 = jieba.lcut(text1) #对AI弹幕进行分词
for word in word_list1:
with open('AI弹幕分词.xls',mode='a',encoding='utf-8') as f: # 将AI弹幕分词保存在xls表中
if word != '\n': # 防止输入换行字符
f.write(word)
f.write('\n')
# 3、将分割出的词连接成字符串
word_str = ' '.join(word_list) # 全弹幕
word_str1 = ' '.join(word_list1) # AI弹幕
# 4、进行词云图相关配置
img = imageio.imread('1.jpg') # 载入图片
wcdall = wordcloud.WordCloud( # 全弹幕词云图
mask=img, # 形状
background_color='white', # 背景颜色
font_path='msyh.ttc' # 字体文件
)
wcdall.generate(word_str)
wcdall.to_file('全弹幕词云.png')
wcdai = wordcloud.WordCloud( # AI弹幕词云图
mask=img, # 形状
background_color='white', # 背景颜色
font_path='msyh.ttc' # 字体文件
)
wcdai.generate(word_str1)
wcdai.to_file('AI弹幕词云.png')
Loading…
Cancel
Save