jeudi 14 février 2019

Logic not working - matching values with ages in a list

I am trying to match particular values (val_A) to ages I have in a list (val_B) in csv format. I am using the below Python code but it's never meeting the first two criteria.The last 2 elif and the else statement are working, and in almost always the else criteria is applied.

def age_convert(val_A):
    val_B = 1
    ages = pd.read_csv('age.csv')
    #print(ages)

    if val_A in ages:
        val_B = val_A
    elif val_A>91:
        val_B=91
    elif val_A<0:
        val_B=val_A*-1
    elif val_A==86:
        val_B=val_A+2
    else:
        val_B=val_A+1
        print('I went through the else')

    return val_B

test = age_convert(1)

print(test)

Aucun commentaire:

Enregistrer un commentaire