逐行阅读时,根据您的摘要。
我认为这
kb_2是错误指示,
groups={}with open("data/petaJoined.csv", "r") as large_file: for line in large_file: arr=line.split('t') #assuming this structure: ka,kb_1,kb_2,timeofEvent,timeInterval k=arr[0]+','+arr[1] if not (k in groups.keys()) groups[k]={'record_count':0, 'error_sum': 0} groups[k]['record_count']=groups[k]['record_count']+1 groups[k]['error_sum']=groups[k]['error_sum']+float(arr[2])for k,v in groups.items: print ('{group}: {error_rate}'.format(group=k,error_rate=v['error_sum']/v['record_count']))此代码段将所有组存储在字典中,并在读取整个文件后计算错误率。
如果组的组合太多,它将遇到内存不足的异常。



