2

I have two columns in my shape file with text values called GP and Z which contain abbreviations and a third column called UpOrDown which is meant to hold the binary 0-1 generated from the if-then statement.

I am struggling in a few areas that likely are impeding my own research and resolution of this issue.

What is the highlighted area called? I may be using the wrong syntax here but I'm not sure how to find this out because you don't know what you don't know!

enter image description here

Next, I want to use the GP and Z columns only when they are both specific values. For example, if GP is DT and Z is CG I want to output a 1 into the UpOrDown column but if GP is CIC and Z is A I want to output a zero. The categories are extensive and I'm not sure if there is a way to make a library of all the GP and Z pairs that would be 1 or 0 due to my limited python understanding.

Is there any clarity on this that anyone might provide (for a novice)?

3

Code Block is where you will define your reclass function. It should look something like this:

def reclass(GP, Z):
    if (GP == "DT" and Z == "CG"):
        UpOrDown = 1
    elif (GP == "CIC" and Z == "A"):
        UpOrDown = 0
    return UpOrDown

A good resource on how to use If-Then statements in Python can be found at the Python If ... Else page of w3schools.com.

A good resource on how to use the Code Block in ArcGIS Pro can be found at the Calculate Field Python examples page of its Online Help.

Some terms for the highlighted part of your screenshot include column name or field name. If you want a mathematical term for UpOrDown, it would be a Dependent Variable, because the value assigned to that cell on each row calculated depends on what happens on the right side of the equation.

| improve this answer | |
  • 1
    Keep in mind that as written in my answer, the code will only calculate a 0 or 1 value for those two scenarios. If CP and Z combinations equal anything else (such as GP == "DT" and Z == "DT", or CP == "NOPE" and Z == "ALSO NOPE"), the code will skip that row and not change the value in UpOrDown. So, if UpOrDown was null, it will stay null. If UpOrDown was 256, it will stay 256. – Zachary Ordo - GISP May 20 at 16:25
  • Which means I have 136 nested elif statements to make I think. Do you happen to know what the highlighted area in the screenshot is called? – Therow May 20 at 16:59
  • That is simply the column name, field name, or if we want to use mathematical terms, it's the dependent variable. – Zachary Ordo - GISP May 20 at 17:19
  • UpOrDown = reclass(!UpOrDown!) ... def reclass(Z,GP): ... if (GP == "DT" and Z == "CG"): UpOrDown = 1 ... this isn't working to change the UpOrDown Column at all -- all values are still NULL. Thoughts? – Therow May 20 at 18:57
  • @Therow, did you manage to get this to work? If not, we can move to chat where it'll be easier to share screenshots of the steps you're taking. – Zachary Ordo - GISP May 21 at 16:29

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.