Looking for some help. I have a continuous variable (PCT_B100P) of the percentage of folks in a census tract that are under the 100% federal poverty line. I'm trying to use this variable to assign a categorical variable (POVCAT)to the census tract. If the value is below, between, or above certain limits it will determine what category the record gets. I'm not getting any errors in my code, buy it's only calculating the first category level 1, and nothing else. Here is my code.

def NumValue( PCT_B100P ):

  if (PCT_B100P <5):
    return 1
  elif (PCT_B100P >= 5 and PCT_B100P <10):
    return 2
  elif (PCT_B100P >= 10 and PCT_B100P <20):
    return 3
  elif (PCT_B100P > 20):
    return 4



any idea as to what I'm doing wrong? I'm quite new to Python. Below is an image of my issue

enter image description here


1 Answer 1


You have passed wrong parameter to the NumValue function.

It should be:

  • Also, while the term PCT_B100P in the line: "def NumValue( PCT_B100P ):" is descriptive, it may be less confusing (and certainly faster to type) to just use x or another variable name that doesn't correspond to an attribute field name. Commented Apr 13, 2016 at 22:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.