ADD file via upload

main
piw4f8lbj 2 months ago
parent 97d5ccc267
commit 6034af7908

@ -0,0 +1,43 @@
import os
import re
from collections import Counter
import pandas as pd
def read_danmu_files(directory):
danmu_data = []
for filename in os.listdir(directory):
if filename.endswith('paris_olympics_danmak.txt'):
with open(os.path.join(directory, filename), 'r', encoding='utf-8') as file:
danmu_data.extend(file.readlines())
return danmu_data
def count_danmu():
danmu_data = read_danmu_files('./') # 当前目录下
ai_danmaku = [danmaku for danmaku in danmu_data if
re.search(r'(?<![a-zA-Z])((?:AI|人工智能))(?![a-zA-Z])', danmaku)]
unique_ai_danmaku = list(set(ai_danmaku))
danmaku_counts = [(danmaku, ai_danmaku.count(danmaku)) for danmaku in unique_ai_danmaku]
sorted_danmaku_counts = sorted(danmaku_counts, key=lambda x: x[1], reverse=True)
top_8_danmaku = sorted_danmaku_counts[:8]
# for danmaku in top_8_danmaku:
# print(danmaku[0])
data = {'弹幕内容': [danmaku[0] for danmaku in top_8_danmaku]}
df = pd.DataFrame(data)
df.to_excel('2024巴黎奥运AI弹幕统计.xlsx', index=False)
Loading…
Cancel
Save