Python Forum
Adding 2-column CSV together in base Python without using pandas
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding 2-column CSV together in base Python without using pandas
#1
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:
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?
Reply


Messages In This Thread
Adding 2-column CSV together in base Python without using pandas - by LeegeeRicky - Sep-29-2019, 11:23 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Adding PD DataFrame column bsben 2 367 Mar-08-2024, 10:46 PM
Last Post: deanhystad
  Python Alteryx QS-Passing pandas dataframe column inside SQL query where condition sanky1990 0 776 Dec-04-2023, 09:48 PM
Last Post: sanky1990
  pandas : problem with conditional filling of a column Xigris 2 675 Jul-22-2023, 11:44 AM
Last Post: Xigris
  How to assign a value to pandas dataframe column rows based on a condition klllmmm 0 878 Sep-08-2022, 06:32 AM
Last Post: klllmmm
  Basic Pandas, obtaining a value from column and row JamesOzone 2 1,120 Jun-30-2022, 07:16 PM
Last Post: jefsummers
  Reshaping a single column in to multiple column using Python sahar 7 2,129 Jun-20-2022, 12:35 PM
Last Post: deanhystad
  Float Slider - Affecting Values in Column 'Pandas' planckepoch86 0 1,437 Jan-22-2022, 02:18 PM
Last Post: planckepoch86
  pandas pivot table: How to find count for each group in Index and Column JaneTan 0 3,379 Oct-23-2021, 04:35 AM
Last Post: JaneTan
  Adding another condition for df column comparison Mark17 2 1,715 Sep-30-2021, 03:54 PM
Last Post: Mark17
  Python Pandas: How do I extract all the >1000 data from a certain column? JaneTan 0 1,590 Jul-17-2021, 09:09 AM
Last Post: JaneTan

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020