[Solved] Row Average CSV Python


You can use the csv library to read the file. It is then just a case of calculating the averages:

import csv

with open('example.csv') as handle:
    reader = csv.reader(handle)
    next(reader, None)
    for row in reader:
        user, *scores = row
        average = sum([int(score) for score in scores]) / len(scores)
        print (
            "{user} has average of {average}".format(user=user, average=average)
        )

With your input this prints:

elliott has average of 8.666666666666666
bob has average of 4.0
test has average of 0.5

This code requires python 3.

3

solved Row Average CSV Python