1

I'm working on zoning data and I've been evaluating if the percentage for various zoning is more than 90% of the area, so I can define it as that zone in a new field, like so:

def ifBlock(RS, RM):
if RS >= 90:
    return "RS"
elif RM >= 90:
    return "RM" 
else:
    return "Mixed"

There are approximately ~40-50 lines of the above code for the different zones. However, for some of the parcels, the values for all of the zones come out to 0. I want to make a new field to identify these areas as "no data". I thought that I could define all of the zoning columns in a list, and I wanted to write in Python something like "if all of the values in the list = 0, return no data".

1

Create a new field. Then use the below code:

def nodataf(args,**kwargs):
    for a in args:
       for k in kwargs:
           if a == kwargs[k]:
               return "No Data"

List your fields.

nodataf([!a!, !b!,!c!], k = 0)

| improve this answer | |
  • I have many more zones than the two I listed, so it would be a lot more efficient if I could classify the zone fields as one list and write "if list = 0, return 'no data'". – clowdyday Dec 8 '17 at 23:32
  • 1
    Sum of the list ==O ? – FelixIP Dec 9 '17 at 1:02
  • @FelixIP !a!== 0 and !b! == 0 and ... – BBG_GIS Dec 9 '17 at 1:09
  • 1
    In fact this can be done with a one-liner ‘all’. – fatih_dur Dec 9 '17 at 2:14
  • 1
    @fatih_dur This is exactly what I meant in 1st comment, e.g. sum([!a!,!b!,!c!]), providing they are all non-negative. – FelixIP Dec 9 '17 at 4:21

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.