From 97ed2e6089df1f7bb481989cef347424cff95062 Mon Sep 17 00:00:00 2001 From: pzb7h6yxf <1736289433@qq.com> Date: Tue, 17 Sep 2024 15:23:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E9=87=87=E9=9B=86=E7=9A=84=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E9=9B=86=E8=BF=9B=E8=A1=8C=E5=8F=AF=E8=A7=86=E5=8C=96?= =?UTF-8?q?=E8=A1=A8=E7=A4=BA=EF=BC=8C=E5=88=B6=E4=BD=9C=E8=AF=8D=E4=BA=91?= =?UTF-8?q?=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script_2.2.2.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 script_2.2.2.py diff --git a/script_2.2.2.py b/script_2.2.2.py new file mode 100644 index 0000000..98d80af --- /dev/null +++ b/script_2.2.2.py @@ -0,0 +1,41 @@ +import jieba +import wordcloud +import imageio +import pandas as pd # 用于读取Excel文件 + +# 读取图片作为词云的形状 +img = imageio.imread('四叶草1.png') + +# 使用pandas读取Excel文件中的所有列 +df = pd.read_excel('top_ai_danmakus.xlsx') + +# 将Excel所有列的数据拼接成一个长字符串 +book = '' + +# 遍历每一列并将内容合并成字符串 +for column in df.columns: + # 将当前列转换为字符串并拼接到 book 变量 + book += ' '.join(df[column].astype(str)) + ' ' + +# 使用jieba进行分词 +book_list = jieba.lcut(book) +book_str = ' '.join(book_list) + +# 打印分词后的字符串 +print(book_str) + +# 创建词云 +wc = wordcloud.WordCloud( + width=500, + height=500, + background_color='white', + mask=img, + stopwords={'main','Taipei','afraid','aiden','Britain'}, # 可添加不需要的停用词 + font_path='msyh.ttc' # 设置中文字体路径 +) + +# 生成词云 +wc.generate(book_str) + +# 保存词云图 +wc.to_file('词云图.png')