A peculiar issue, what is wrong in this code, when the if condition hits the code crashes. This is the original code not in python but converting this to python code
efratio=noise!=0 ? signal/noise : 1
Background of the stockdata
is nothing but dataframe value in pandas array. the array list has noise value when I compare this with !=0
in Python I don't know why the program crashes.
Should I use numpy here as this dataframe has the list of data series?
if (stockdata['noise']!= 0):
stockdata['efratio']= (stockdata['signal']/stockdata['noise'])
else :
stockdata['efratio']= 1
or
stockdata['efratio']= (stockdata['signal']/stockdata['noise']) if (stockdata['noise']!= 0) else 1
Edit1: The exception coming is
The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()