You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
# 统计弹幕次数
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def count_danmu():
|
|
|
|
|
# 打开TXT文件以读取数据
|
|
|
|
|
file_path = '弹幕.txt'
|
|
|
|
|
|
|
|
|
|
# 初始化一个空的文本字符串,用于累积所有文本数据
|
|
|
|
|
danmu_list = []
|
|
|
|
|
|
|
|
|
|
with open(file_path, 'r', encoding='utf-8') as file:
|
|
|
|
|
for line in file:
|
|
|
|
|
# 在这里处理每一行的数据
|
|
|
|
|
# 示例:将每一行的弹幕添加到danmu_list列表中
|
|
|
|
|
danmu_list.append(line.strip())
|
|
|
|
|
|
|
|
|
|
# 使用Counter统计弹幕出现次数
|
|
|
|
|
danmu_counter = Counter(danmu_list)
|
|
|
|
|
# 筛选与AI技术应用相关的弹幕
|
|
|
|
|
ai_danmu_counter = {k: v for k, v in danmu_counter.items() if 'AI' in k or '人工智能' in k}
|
|
|
|
|
# 将筛选后的弹幕转换为Counter对象
|
|
|
|
|
ai_danmu_counter = Counter(ai_danmu_counter)
|
|
|
|
|
# 获取AI技术应用方面数量排名前8的弹幕
|
|
|
|
|
top_8_ai_danmus = ai_danmu_counter.most_common(8)
|
|
|
|
|
|
|
|
|
|
# 打印排名前8的AI技术应用方面的弹幕及其出现次数
|
|
|
|
|
for idx, (danmu, count) in enumerate(top_8_ai_danmus, 1):
|
|
|
|
|
print(f'排名 #{idx}: 弹幕 "{danmu}" 出现次数:{count}')
|
|
|
|
|
#top_76016_danmus = danmu_counter.most_common(76016)
|
|
|
|
|
# 将AI技术应用方面的统计数据写入Excel
|
|
|
|
|
df = pd.DataFrame(list(ai_danmu_counter.items()), columns=['弹幕', '次数'])
|
|
|
|
|
df.to_excel('AI技术应用弹幕统计.xlsx', index=False)
|