0

Since I'm new to python I have an issue with writing the correct code to achieve the following. The picture is an example of an attribute table of which i want to make frequency distribution graphs according to certain ranges of an indicator variable. For instance a graph should be created in which the range of ORG_STOF (indicator variable) should be: < 2, 2 - 3.5, etc. for which the Count_ORG_STOF needs to be indicated.

According to another question post i found (Using Range in Python expression of ArcGIS Field Calculator?) I thought that a solution would be something in the line of: Additional fields should be created for each range (in most cases consisting of 3 or 5)

    def "Range_one"(value):
    if value > 2 and value < 3.5:
     return "Value of Count_ORG"
     else:
     return "0"

Then in the calculation area:

    Range_one(!ORG_STOF!)

However, it is a bit different in my case, since in the solution script I had in mind I need to refer to two fields.

After trial

0

Use the expression below

def "Range_one"(value1,value2):
    if value > 2 and value < 3.5:
        return value2
    else:
        return 0

With this call

Range_one (!ORG_STOF!,!Count_ORG_STOF!)
  • Hi, thanks for your adequate response. However, I have tried to copy the script that you wrote but I did not succeed.. (See image). – Soil33 Aug 12 '16 at 16:03
  • I have tried separating it with the top part in the pre-logic script code as well – Soil33 Aug 12 '16 at 16:23
  • you should tick a codeblock, insert first part def "Range_one"(value1,value2): if value > 2 and value < 3.5: return value2 else: return 0 in a first window and insert Range_one (!ORG_STOF!,!Count_ORG_STOF!) in second window – GRM Aug 12 '16 at 17:14
  • Got it! I had to change the "Range_one", to calc, and then it worked. Thank you kind for your help everyone and have a good day – Soil33 Aug 15 '16 at 8:06

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.