Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am trying to use field calculator to populate a column based on the the number of characters in another column. I am using the Python Parser. I am not sure if the .count() function is appropriate in this case or if I am even using it right.

Thanks in advance for your help!

My pre-logic script is:

def reclass(f1):
     if f1.count() >= 4:
         return "Yes"
      else:
         return "No"



Label = reclass( !HUB! )
share|improve this question

2 Answers 2

up vote 3 down vote accepted

I would make two changes:

  1. Make sure your indentation is correct
  2. Use len() to count the characters. Make sure you are writing to a text field.

def reclass(f1):
     if len(f1) >= 4:
         return "Yes"
     else:
         return "No"

Label = reclass( !HUB! )
share|improve this answer
    
Thanks Aaron. Works like a charm! –  ChrisA Apr 4 at 20:22

Select by Attributes: char_length(FIELD) >= number

Field Calculate on the selected records

share|improve this answer
1  
This Answer was flagged up as low quality due to its brevity. I think you should edit it to explain that you are suggesting an alternative to using the Python Parser of the Field Calculator. –  PolyGeo Apr 4 at 21:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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