1

I have a field (WS_Type in the screenshot) that I want to use to calculate values based on the text within the field. The number of occurrences of each WS_Type in the field is not important, but the presence of each different type in the field is. Basically, I need to create an if/then statement that says, if this field contains "NRW" AND "Diversion", then it will get a score of X. If this field contains "NRW" OR "Spring" it will get a score of Y, etc. I'm not sure how to set up this if/then statement.

enter image description here

4

Create a new field for your output. Make sure it is string type.

Click Show Codeblock.

Write your code block/'Pre-Log Script Code' in python like this:

   def func(input):
        if 'NRW' in input and 'Diversion' in input:
            return 'X'
        elif 'NRW' in input or 'Spring' in input:
            return 'Y'
        else:
            continue

Then use it on the field you created like this:

new field=

func(!WS_Type!)
  • 1
    I would change the case, just to be sure, if 'NRW' in input.upper(). but still +1 from me. – Michael Stimson Apr 26 '18 at 22:02

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.