Skip to main content
 首页 » 编程设计

python之需要平均 Python 的帮助

2025年05月04日16zfyouxi

<分区>

求字段 [quant] 中大于或等于 (337) 的值的平均值 这是量化字段

quant 
100 
7 
109 
204 
28 
292 
105 
254 
441 
401 
410 
14 
15 
51 
96 
403 
75 
31 
109 
17 

这是我试过的代码

import csv 
 
total = count = 0 
 
with open('3111111a.csv', newline='') as f: 
    reader = csv.reader(f) 
    next(reader, None)   
 
    for row in reader: 
        total += float(row[4]) 
        count += 1 
 
    if count: 
        average = total / count 
        print('The average of the values is {}'.format(average))