Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find a date in pd dataframe that matches a date in a given list [duplicate]

breakout_candles= []
for _,breakout in btc_breakouts:
    breakout_candles.append(breakout)
print(breakout_candles)

output:

 [Timestamp('2021-10-28 04:00:00+0000', tz='UTC'), Timestamp('2021-10-28 08:00:00+0000', tz='UTC'), Timestamp('2021-10-29 08:00:00+0000', tz='UTC'), Timestamp('2021-10-31 16:00:00+0000', tz='UTC'), Timestamp('2021-11-01 04:00:00+0000', tz='UTC')]

Now im trying to set a value to 1 if the date was found in breakout_candles otherwise -1:

 df['BTCgtRES'] = np.where((df['date'] in breakout_candles),1,-1)

but i m getting the ambiguous error:

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

i also tried this, it compiles but does nothing it has to do:

df['BTCgtRES'] = np.where((df['date'].eq (breakout in breakout_candles)),1,-1)
like image 256
Cartagho07 Avatar asked Dec 10 '25 07:12

Cartagho07


1 Answers

You can try using isin() instead of in

 df['BTCgtRES'] = np.where((df['date'].isin(breakout_candles)),1,-1)
like image 121
Zalak Bhalani Avatar answered Dec 11 '25 21:12

Zalak Bhalani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!