[Tutor] TypeError: 'float' object is not iterable

hongerlapjes hongerlapjes at gmail.com
Wed Jul 22 19:33:42 EDT 2020


I'm learning python and need help. How can I sum up "bedrag"?
I've replaced the "." with a "," and changed the string into a float, 
but I can't iter. I'm lost. What do I need to do?

I've tried numpy
For content csv see:


My python code:

     import csv

     import numpy as np

     with open('oefen.csv') as csv_file:
     csv_reader = csv.DictReader(csv_file, delimiter=',')

     print(csv_reader.fieldnames)
     for row in csv_reader:

         #change string into float and replace the comma with a dot
         bedrag = float(row['Bedrag (EUR)'].replace(",", "."))

             #try 1 gives: TypeError: 'float' object is not iterable
             som = sum(bedrag)
             print(som)

             #try 2 gives: TypeError: iteration over a 0-d array
             arr = np.array(float(row['Bedrag (EUR)'].replace(",", ".")))
             som = sum(arr)
             print(som)


             #try 3 gives: TypeError: 'float' object is not iterable
             arr = np.array(list(float(row['Bedrag (EUR)'].replace(",", 
"."))))
             som = sum(arr)
             print(som)



More information about the Tutor mailing list