Click here to Skip to main content
14,773,061 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am new in programming can any one help me please?
I have 10 csv file each file having some of float numbers
I am asking how can I read and get the avg of values in each file,

this code read one file and then compute the avg(mean) of data in file

What I have tried:

total = 0

   with open('er11.csv', 'r') as inp:
       for line in inp:
           try:
               num = float(line)
               total += num
           except ValueError:
               print('{} is not a number!'.format(line))
       mean total/len(open('er11.csv').readlines())
       print('Total of all numbers: {}'.format(total))
       print(mean)
Posted
Updated 6-Apr-20 23:05pm

1 solution

You need to create a loop that will get each file, one by one, and pass that to a function that processes the content. You can either hard code the names into the application or use a directory search to find them: glob — Unix style pathname pattern expansion — Python 3.8.2 documentation[^].
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900