From 54e40721e4398bdb75a065ea7c4a4608a70ce5f0 Mon Sep 17 00:00:00 2001 From: pucvkrxa8 <773824858@qq.com> Date: Thu, 12 Sep 2024 14:29:03 +0800 Subject: [PATCH] =?UTF-8?q?Delete=20'=E7=AD=9B=E9=80=89AI=E5=85=B3?= =?UTF-8?q?=E9=94=AE=E5=AD=97=E5=92=8C=E8=AF=8D=E4=BA=91=E5=9B=BE.py'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 筛选AI关键字和词云图.py | 35 -------------------------------- 1 file changed, 35 deletions(-) delete mode 100644 筛选AI关键字和词云图.py diff --git a/筛选AI关键字和词云图.py b/筛选AI关键字和词云图.py deleted file mode 100644 index d88eb1d..0000000 --- a/筛选AI关键字和词云图.py +++ /dev/null @@ -1,35 +0,0 @@ -from wordcloud import WordCloud -from collections import Counter -import matplotlib.pyplot as plt - -final_danmu=[]#所有弹幕合集 -final_danmu_ai=[]#所有ai有关弹幕合计 -for num in range(1,301):#遍历爬好的弹幕 - text_name=f"第{num}个视频弹幕.txt" - danmu=[] - key=[ - '人工智能','AI' - ] - try: - with open(f"{text_name}",mode='r',encoding='utf-8') as f: - for i in f: - danmu.append(i.strip()) - danmu_ai=[i for i in danmu if any(j in i for j in key)] - final_danmu_ai+=danmu_ai - final_danmu+=danmu - except: - continue -aicount=Counter(final_danmu_ai) -danmucount=Counter(final_danmu) -#分别计数 -for i in aicount.most_common(8):#AI有关弹幕排名前8 - print(f"弹幕:{i[0]}\n次数:{i[1]}\n") -wordcloud = WordCloud(width=800, height=400, background_color='white', - font_path='msyh.ttc', # 设置字体路径,可以根据系统字体路径调整 - max_words=100, colormap='viridis').generate_from_frequencies(danmucount) - -# 显示词云图 -plt.figure(figsize=(10, 5)) -plt.imshow(wordcloud, interpolation='bilinear') -plt.axis('off') # 不显示坐标轴 -plt.show() \ No newline at end of file