I have two dataframes:
last_signal:
Unnamed: 0 coresym Lots open_orders direction
0 0 AUDUSD 110.39 0.0 9.0
1 1 EURUSD 88.19 0.0 9.0
2 2 GBPUSD -87.65 0.0 9.0
signal:
coresym Lots open_orders direction
0 AUDUSD 250.00 0.0 1.0
1 EURUSD 112.50 0.0 0.0
2 GBPUSD -97.11 0.0 0.0
I want to change the signal's value based on last_signal:
if ((last_signal[last_signal['coresym']=='AUDUSD']['direction'] == 9) & (signal[signal['coresym']=='AUDUSD']['Lots'] >100)):
signal[signal['coresym']=='AUDUSD']['direction'] = 9
I got the error
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-36-0b88b27047e9> in <module>
----> 1 if ((last_signal[last_signal['coresym']=='AUDUSD']['direction'] == 9) & (signal[signal['coresym']=='AUDUSD']['Lots'] >100)):
2 signal[signal['coresym']=='AUDUSD']['direction'] = 9
~anaconda3libsite-packagespandascoregeneric.py in __nonzero__(self)
1327
1328 def __nonzero__(self):
-> 1329 raise ValueError(
1330 f"The truth value of a {type(self).__name__} is ambiguous. "
1331 "Use a.empty, a.bool(), a.item(), a.any() or a.all()."
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
I tried to debug myself:
last_signal[last_signal['coresym']=='AUDUSD']['direction'] == 9
0 True
Name: direction, dtype: bool
signal[signal['coresym']=='AUDUSD']['Lots'] >100
0 True
Name: Lots, dtype: bool
((last_signal[last_signal['coresym']=='AUDUSD']['direction'] == 9) & (signal[signal['coresym']=='AUDUSD']['Lots'] >100))
0 True
dtype: bool
I really dont understand why, I assume others may have the same problem, so I post it here
question from:
https://stackoverflow.com/questions/65599711/valueerror-the-truth-value-of-a-series-is-ambiguous-use-a-empty-a-bool-a-i 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…