【发布时间】:2013-05-08 17:22:44
【问题描述】:
字段 [quant] 在 (198) 和 (272) 范围内的数字的平均值是多少
quant
95
189
176
200
177
340
205
203
284
88
109
83
360
67
250
56
111
439
354
143
这是我尝试过的代码。以上是我需要从中找到平均值的 [quant] 字段。
word_file = open('300000a.csv','r')
firstLine = True
for line in word_file:
if firstLine:
firstLine = False
continue
line = line.strip()
line = line.split (",")
field = int(line[0])
TotalMetalCount +=1
if field >198 or field <272:
metalCounts += 1
else:
metalCounts = 1
countT +=1
if field >198 or field <272:
count += 1
【问题讨论】:
-
@GrijeshChauhan 请不要建议
reduce,因为你可以使用sum -
@jamylak :) :)..同意,谢谢! :)
-
@LevLevitsky 是的......不太清楚为什么再次被问到。无论如何,它必须是课程/作业的一部分,但stackoverflow.com/questions/16522767/… 要求更好 - 所以建议 OP 阅读那个...
-
你的代码我看了好几遍,不知道你的代码和变量是什么意思。