You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
753 B

from wordcloud import WordCloud
import jieba
from openpyxl import load_workbook
# 加载Excel工作簿和工作表
wb = load_workbook('AI_应用统计.xlsx')
ws = wb.active
# 读取所有行数据
rows = list(ws.iter_rows(values_only=True))
# 跳过标题行,提取所有弹幕内容
danmu_contents = [row[2] for row in rows[1:] if row[2] is not None]
# 使用jieba进行分词
string = ' '.join(jieba.lcut(' '.join(danmu_contents)))
# 创建词云对象
wc = WordCloud(
width=200,
height=200,
background_color='white',
font_path='STLITI.TTF', # 请替换为你电脑上实际存在的中文字体文件路径
scale=15
).generate(string)
# 将词云保存为图片
wc.to_file('弹幕词云.png')