mercredi 26 avril 2017

Compound inequality in if statement

This is a generalized function I want to use to check if each row of a dataframe follows a specific trend in column values.

def follows_trend(row):
    trend = None
    if row[("col_5" < "col_6" < "col_4" < "col_1" < "col_2" < "col_3")]:
        trend = True        
    else:
        trend = False
    return trend

I'll apply it like this

df_trend = df.apply(follows_trend, axis=1)

When I do, it returns all True when there are clearly some rows that should return False. I'm not sure if there is something wrong with the inequality I used or the function itself.

Aucun commentaire:

Enregistrer un commentaire