parent
bd5d04effb
commit
dfb7b63663
@ -0,0 +1,28 @@
|
|||||||
|
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')
|
Loading…
Reference in new issue