lundi 6 juillet 2020

If statement not working as expected when importing csv data

Sorry if the problem is very basic, I am very new to python.

In the code, I am trying to add up values in column 5 of the csv file if the value in the first column is a certain value.

If the value of column 1 is equal to 1, I want to add the value of column 5 of the same value to a cumulative sum.

When debugging everything above the if the statement is working as expected, but the if the statement isn't updating the value for the variable

      csv_reader = csv.reader(csv_file, delimiter=',')
      print('File has been imported')
      csv_headings = next(csv_reader)
    
      Cumlative_Cases=0
    
      for line in csv_reader:
        get_id=line[0]
        new_case=line[4]
        print(get_id)
        #print(new_case)
        
        if get_id == 1:
            Cumlative_Cases = Cumlative_Cases + new_case
        print(Cumlative_Cases)

Aucun commentaire:

Enregistrer un commentaire