import os import pandas as pd from tqdm import tqdm # 指定文件夹路径 folder_path = 'C:\\Users\\H610M-F\\Desktop\\MCServer\\logs\\RawBehaviorLog\\BehaviorLog-2023-1001-1031' # 获取文件列表 file_list = os.listdir(folder_path) # 创建一个空的字典用于存储每个游戏名字的符合条件的记录总数 total_records_dict = {} # 遍历文件列表并加入进度条 for file_name in tqdm(file_list, desc='Processing files', unit='file'): if not file_name.endswith('.csv'): continue # 拼接文件路径 file_path = os.path.join(folder_path, file_name) # 读取CSV文件 df = pd.read_csv(file_path, on_bad_lines='skip') # 将时间列转换为 pandas 的 datetime 类型 df['时间'] = pd.to_datetime(df['时间'], errors='coerce') # 筛选出事件为 '破坏方块' 且类型为 'minecraft:deepslate_diamond_ore' 的数据 filtered_data = df[(df['事件'] == '破坏方块') & (df['目标'] == 'minecraft:ancient_debris')] # 对每个游戏名字进行计数,得到符合条件的记录总数 for game_name in filtered_data['主体'].unique(): total_records = filtered_data[filtered_data['主体'] == game_name].shape[0] # 更新字典中的记录总数统计 if game_name in total_records_dict: total_records_dict[game_name] += total_records else: total_records_dict[game_name] = total_records # 对记录总数进行排序 sorted_records = sorted(total_records_dict.items(), key=lambda x: x[1], reverse=True) # 打印排序后的结果 for game_name, total_records in sorted_records: print(f"游戏名字为 '{game_name}',事件为 '破坏方块' 且类型为 'minecraft:ancient_debris' 的记录总数为 {total_records}")