Skip to content
Advertisement

Pandas: AttributeError: ‘float’ object has no attribute ‘MACD’

I would like to compare 2 rows in a pandas dataframe but I always get an Error saying: AttributeError: ‘float’ object has no attribute ‘MACD’.

This is the df:

JavaScript

Now I want to count on how many times it would buy and sell based on some information in the rows so I’m trying to iterate through it like this:

JavaScript

I am getting the following Error:

JavaScript

I know this Error has already been here but I the solutions there didn’t help me.

Thank you already!

Advertisement

Answer

your problem his here row[i – 1].MACD

when you are accesessing the row[i-1] place you get the value of the location in the service if i = 1 then you will get the row[0] for the row and not the preivice row in the dataframe you should probably switch it by df.iloc[i-1].MACD

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement