2

I'm trying to reclass values in field calculator using Python (recreating something I did successfully last month and am failing now). I've reviewed many questions and answers on this site with no success.


I've followed multiple examples from ArcGIS help and on this site, and regardless of how I change my statements, the calculator returns only one answer for all records. I added a picture as an example.

I wrote the following pre-logic script code, but the calculator returns "1" for all data. I have a field (Percent) of percentages and I'd like to bin them into 5 groups in the cate field: greater than or equal to 80; greater than or equal to 60 and less than 80; greater than or equal to 40 and less than 60; greater than or equal to 20 and less than 40; greater than or equal to 0 and less than 20.

I have no python experience and am just trying to replicate examples from GIS help and answers to similar questions on this site.

def Reclass(Percent):
  if Percent >= 80:
    return 5
  elif Percent >= 60 and Percent < 80: 
    return 4
  elif Percent >= 40 and Percent < 60:
    return 3
  elif Percent >= 20 and Percent < 40:
    return 2
  elif Percent >= 0 and Percent < 20:
    return 1

enter image description here

enter image description here

closed as unclear what you're asking by PolyGeo Dec 21 '16 at 22:26

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • See the example here, scroll to Calculate fields using logic with Python. This may not be the issue but you should put your conditionals in parenthesis, e.g (Percent >= 60 and Percent < 80). Additionally what are some of the values in the field Cate? It could be that in fact everything is greater than 0 and less than 20, so returning 1 for everything is valid. – GeoSharp Dec 7 '16 at 20:24
  • Thanks. The values range from 0 to 100. I tried the parenthesis, with no effect. I based my original statement on the example you provided and am not able to get the calculation to work. – Kristin Dec 7 '16 at 23:16
  • Have a look at gis.stackexchange.com/questions/177652/… – FelixIP Dec 7 '16 at 23:26
  • Thanks. The expression is still not working - it only returns the answer for the first logic statement (if I say "return 1" if Percent <= 20 in the first statement, it returns "1" for all 1200 records regardless of the actual number in the Percent field - so 80 returns as "1" as well ). Maybe an issue with my data? It is strange because I was able to make it work before with this same data. – Kristin Dec 8 '16 at 18:02
  • Does the third picture have any direct relevance to what you have tried and where you are stuck? If not, then I think you should delete it and provide details of the data types for any fields that you are trying to use in your field calculation. – PolyGeo Dec 21 '16 at 22:26