From 872a9d2fde117898c390195bdcdc80846f945471 Mon Sep 17 00:00:00 2001 From: ptkbf2lr5 <18759452262@163.com> Date: Wed, 18 Sep 2024 16:08:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E4=BA=BA=E4=BB=AC=E5=AF=B9=E7=90=83?= =?UTF-8?q?=E7=B1=BB=E9=A1=B9=E7=9B=AE=E7=9A=84=E5=96=9C=E5=A5=BD=E7=A8=8B?= =?UTF-8?q?=E5=BA=A6=E5=88=86=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ballgame.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 ballgame.py diff --git a/ballgame.py b/ballgame.py new file mode 100644 index 0000000..5aa5b9c --- /dev/null +++ b/ballgame.py @@ -0,0 +1,20 @@ +import pandas as pd +from collections import Counter + +# 读入所有弹幕 +with open('all_content.txt', mode='r', encoding='utf-8') as f: + data_list = f.readlines() +# 六项球类关键词 +keywords = ['乒乓球','羽毛球','排球','篮球','足球','网球'] +# 筛选有关球类的弹幕 +selectdanmu = [danmu for danmu in data_list if any(keyword in danmu for keyword in keywords)] + +# 统计弹幕数量 +num = Counter(selectdanmu) +top_common = num.most_common(20) +# 展示数量前八条弹幕 +print(top_common) +t = pd.DataFrame(top_common, columns=['弹幕内容', '数量']) +# 导出excel文件 +excel_path = 'top_ball_danmu.xlsx' +t.to_excel(excel_path, index=False) \ No newline at end of file