jeudi 24 octobre 2019

Is there a way to nest an "if" statement in a "for" loop, to then return as "True", "False", or "Unsure" in a new list?

I currently have a Series column ("DateDiff") in a DataFrame, and I am trying to create a new list/series next to it that returns "True", "False", or "Unsure" based on the values in the "DateDiff" column.

I've tried to create a nested if function inside a for loop, and then append these returns into a new list named "fraud".

minus = condensed['DEATHDATE'] - condensed['STOP']
minus = minus.tolist()
fraud = []
for value in minus:
    if value in minus > 0:
        fraud.append('True')
    elif value in minus < 0:
        fraud.append('False')
    elif value in minus == 0:
        fraud.append('Unsure')

I'm expecting it to run through each line of [minus], check to see if it is >, <, or == to 0, and then return and append "True", "False", or "Unsure" to the list [list].

Whenever I try to run the code above, I keep getting this error message.

TypeError: '>' not supported between instances of 'list' and 'int'

Aucun commentaire:

Enregistrer un commentaire