lundi 4 mai 2020

Function not returning proper values (Python)

I have a function below that should return standardized outputs based on numeric ranges:

`def incident(count):
if count['incident_ct']<= 4: 
    val = 1 
elif count['incident_ct']>4 & count['incident_ct']<= 13: # 25 to 50%
    val = 2
elif count['incident_ct'] >13 & count['incident_ct']<=31: # 50 to 75%
    val = 4
elif count['incident_ct'] >31 & count['incident_ct']<=100: # 75 to 95%
    val = 8
else: 
    val = 16
return val`

Then applied to new row in the data:

`intersections['v_counts'] = intersections.apply(incident, axis = 1)`

However, the output is not giving what I specified in the ranges (only 1 or 2 in the v_count) When looking at my code, the incident_ct = 34 should be 8 and where incident_ct = 172 should be 16 enter image description here

Aucun commentaire:

Enregistrer un commentaire