Need help on finding AVERAGE in python -
this question has answer here:
what average value of numbers in field [quant] in range (198) , (272) inclusive
quant 95 189 176 200 177 340 205 203 284 88 109 83 360 67 250 56 111 439 354 143
this code tried. above [quant] field need find average.
word_file = open('300000a.csv','r') firstline = true 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
you can calculate average of list using sum , dividing length.
float(sum(my_list))/len(my_list)
if need grab few specific items , extract average based on can slice array.
print(float(sum(my_list[198:272]))/len(my_list[198:272]))
if have list contains strings, , not integers need convert them list of integers before can use sum.
my_list_of_integers = [int(i) in my_list[198:272] print(float(sum(my_list_of_integers))/len(my_list_of_integers]))
Comments
Post a Comment