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.
23 lines
755 B
23 lines
755 B
import pandas as pd
|
|
|
|
def GetAI():
|
|
# 读取CSV文件
|
|
df = pd.read_csv('danmu.csv')
|
|
|
|
# 筛选出第一列(弹幕)包含关键词"AI"的行
|
|
ai_danmu = df[df['弹幕'].str.contains('AI', na=False)]
|
|
|
|
# 将筛选后的数据保存为XLSX文件
|
|
ai_danmu.to_excel('ai_danmu.xlsx', index=False)
|
|
|
|
# 统计每个弹幕出现的次数
|
|
ai_danmu_count = ai_danmu.groupby('弹幕')['数量'].sum().reset_index()
|
|
|
|
# 找出出现次数最多的8个弹幕
|
|
ai_danmu_most_common = ai_danmu_count.sort_values(by='数量', ascending=False).head(8)
|
|
|
|
# 将这8个元素保存为XLSX文件
|
|
ai_danmu_most_common.to_excel('ai_danmu_most_common.xlsx', index=False)
|
|
|
|
if __name__ == '__main__':
|
|
GetAI() |