Sep-29-2019, 11:23 AM
(This post was last modified: Sep-29-2019, 11:24 AM by LeegeeRicky.)
I have a CSV file with ID column (Username) and two numeric columns. In base Python I want to get the ID and the sum of Auto and Manual Score, then generate another CSV with the result.
Example input CSV:
Username Auto Score Manual Score
1234, 1,
1234, 1,
1234, 1,
1234, , 1.5
345, 1,
345, 1,
345, , 2
133, 1,
133, 1,
133, , 2.5
Here is my code:
How can I fix it to sum the result with one Username with one sum score each row?
Example input CSV:
Username Auto Score Manual Score
1234, 1,
1234, 1,
1234, 1,
1234, , 1.5
345, 1,
345, 1,
345, , 2
133, 1,
133, 1,
133, , 2.5
Here is my code:
import csv with open("exam_for_2019.csv") as csvfile: reader = csv.DictReader(csvfile) for row in reader: sum_row = int(row['Auto Score']) + int(row['Manual Score']) print(sum_row)But I got the error as: ValueError: invalid literal for int() with base 10: '' .
How can I fix it to sum the result with one Username with one sum score each row?