1

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

Expression:

NumValue(!POVCAT!)

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

4

You have passed wrong parameter to the NumValue function.

It should be:

NumValue(!PCT_B100P!)
  • 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. – Mike Bannister Apr 13 '16 at 22:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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