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.
21 lines
610 B
21 lines
610 B
import pandas as pd
|
|
|
|
|
|
def top_8_ai_barrage(file_path):
|
|
# 读取CSV文件
|
|
all_barrage = pd.read_csv(file_path, encoding='utf-8')
|
|
|
|
# 过滤包含"AI"或"人工智能"的弹幕
|
|
ai_barrage = all_barrage[all_barrage['barrage'].str.contains('AI |人工智能|科技|智能', case=False, na=False)]
|
|
|
|
# 统计每个弹幕出现的次数
|
|
counter = ai_barrage['barrage'].value_counts()
|
|
|
|
# 获取数量排名前8项
|
|
top_8 = counter.head(8).reset_index()
|
|
top_8.columns = ['弹幕', '出现次数']
|
|
return top_8
|
|
|
|
|
|
if __name__ == '__main__':
|
|
print(top_8_ai_barrage('barrage.csv')) |