qa_info.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import pandas as pd
  2. import warnings
  3. warnings.filterwarnings('ignore')
  4. # 创建筛选条件
  5. def analyze_data(excel_path):
  6. df = pd.read_excel(excel_path)
  7. result = {}
  8. # 1. 呼出且与AI对话的数量
  9. total_calls = len(df[(df['对话方向'] == '呼出')])
  10. ai_calls = len(df[(df['对话方向'] == '呼出') & (df['是否在和AI对话'] == '是')])
  11. # 2. 呼出且非AI对话的数量
  12. non_ai_calls = len(df[(df['对话方向'] == '呼出') & (df['是否在和AI对话'] == '否')])
  13. # 3. 呼出且AI对话的满意度分类
  14. ai_calls_df = df[(df['对话方向'] == '呼出') & (df['是否在和AI对话'] == '是')]
  15. satisfied = len(ai_calls_df[ai_calls_df['分类是否正确'] == '满意'])
  16. unsatisfied = len(ai_calls_df[ai_calls_df['分类是否正确'] == '不满意'])
  17. not_rated = len(ai_calls_df[ai_calls_df['分类是否正确'] == '未评价'])
  18. # 4. 比率计算
  19. satisfaction_rate = f"{((satisfied + not_rated) / ai_calls * 100):.2f}%"
  20. not_rated_rate = f"{(not_rated / ai_calls * 100):.2f}%"
  21. auto_call_rate = f"{(ai_calls / total_calls * 100):.2f}%"
  22. # 5. 人工计算
  23. result["总呼出"] = total_calls
  24. result["人呼出"] = non_ai_calls
  25. result["AI呼出"] = ai_calls
  26. result["满意数"] = satisfied
  27. result["不满意"] = unsatisfied
  28. result["未评价"] = not_rated
  29. result["未评价率"] = not_rated_rate
  30. result["满意率"] = satisfaction_rate
  31. result["AI回复率"] = auto_call_rate
  32. # print(result)
  33. # 筛选条件:呼出 + AI对话 + 未评价
  34. filtered_df = df[
  35. (df['对话方向'] == '呼出') &
  36. (df['是否在和AI对话'] == '是') &
  37. (df['分类是否正确'] == '未评价')
  38. ]
  39. # 按客服用户名分组统计
  40. user_counts = filtered_df['客服用户名'].value_counts()
  41. unrate_info = {}
  42. for user, count in user_counts.items():
  43. unrate_info[user.split(':')[-1]] = count
  44. result["未评价统计"] = unrate_info
  45. return result
  46. # 使用示例
  47. if __name__ == "__main__":
  48. excel_path = "./data/聊天历史统计表_04_02.xlsx"
  49. result = analyze_data(excel_path)
  50. print(result)