Skip to content
Advertisement

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all(). & [duplicate]

I have a dataframe ‘signal’:

JavaScript

As I need some condition to set up my ‘_exec_dict’ which is a dictionary to tell the trading platform what my order is?

JavaScript

The problem is I cannot use

JavaScript

to do the condition determination.

To do the testing:

JavaScript
JavaScript

to have some alternation,

JavaScript

the result is:

JavaScript

After searching, like Truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all() I do use the ‘&’.

Advertisement

Answer

The & is not the problem.

if((signal['coresym']=='XAUUSD') & (signal['direction'] == 9)): print('ok')

do you nean to say if all the elements of signal['coresym'] are equal to XAUUSD and all the elements of signal['direction'] are =9.

Or do you mean if any of them.

This is the ambiguity that the error describes.

use all() or any() around your predcats. for example:

if((signal['coresym']=='XAUUSD').all() & (signal['direction'] == 9).all()): print('ok')

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