Home > OS >  Getting error TypeError: 'float' object is not iterable
Getting error TypeError: 'float' object is not iterable

Time:11-16

I am trying the following code wherein I am fetching the value of the holding from a CSV file and storing it in a list. Then on that holding, I am calculating ownership percentage for each row of a dataframe. That is my logic.

holdings_list=list(data["holdings"])
    ownership_percentage_list=[]
    for i in range(len(holdings_list)):
        ownership_percentage_list=list(get_ownership_percentage(i,60000))
    print(ownership_percentage_list)

But with this I am getting error TypeError: 'float' object is not iterable. When I remove the range and len and keep only holdings_list then too I am getting the same error. Am I missing something here?

CodePudding user response:

# In 4th line:

if  get_ownership_percentage(i,60000) returns float;
 then list(float) will cause error.

#Eg. 
list(2.5) # Displays --> TypeError: 'float' object is not iterable

CodePudding user response:

maybe data["holdings"] is already a float. Try printing type(X) on every variable to better understand what types you are using exactly.

  • Related