Python - Calculate average for every column in a csv file

后端 未结 6 979
执笔经年
执笔经年 2020-12-10 20:02

I\'m new in Python and I\'m trying to get the average of every (column or row) of a csv file for then select the values that are higher than the double of the average of its

6条回答
  •  情深已故
    2020-12-10 20:24

    If you want to do it without stdlib modules for some reason:

    with open('path/to/csv') as infile:
        columns = list(map(float,next(infile).split(',')))
        for how_many_entries, line in enumerate(infile,start=2):
            for (idx,running_avg), new_data in zip(enumerate(columns), line.split(',')):
                columns[idx] += (float(new_data) - running_avg)/how_many_entries
    

提交回复
热议问题