samedi 19 juin 2021

Struggling with if statements for pandas df: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()

Here is a bit of context to my code, and the main line of issue below it. Even replacing and with & did not work

df['in_uptrend'] = 'N/A'
    for current in range(1, len(df.index)):
        previous = current - 1
... 

#MAIN ISSUE
if df['short_ema'][current] < df['long_ema'][current] and df['close'][current] < df['short_ema'][current] and df['above_below_50'] == 'below_50' and in_short == False:
            df['in_uptrend'][current] = 'OPEN SHORT'
            in_short = True

This gives the error:

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

and below that:

TypeError: catching classes that do not inherit from BaseException is not allowed

Aucun commentaire:

Enregistrer un commentaire