2

Below is the code with what I have come up with. I have two columns, one named First_kopp that have the classes CT, WT, ST ranging from 1-9, and the second column is named First-fros. There are conditions that have to be met based on both columns as expressed in the code below, however, this code does not seem to work:

def reclass(FIRST_KOPP , FIRST_FROS):
 if 'CT' in FIRST_KOPP: 
 return "High frost risk"
 elif 'ST1' or 'ST2' or 'ST3' in FIRST_KOPP:
 return "Frost free"
 elif 'ST1' or 'ST2' or 'ST3' in FIRST_KOPP and 'Moderate frost risk' or 'High frost risk' in FIRST_FROS:
 return "Low frost risk"
 elif 'ST4' or 'ST5' or 'ST6' or 'ST7' or 'ST8' or 'ST9' in FIRST_KOPP:
 return "Frost free"
 elif 'WT' in FIRST_KOPP and 'Frost free' in FIRST_FROS:
 return "Low frost risk"
 else:
 return FIRST_FROS
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Feb 15, 2022 at 15:07
1
  • You can also use any: elif any(x in FIRST_KOPP for x in ['ST1','ST2','ST3']) Commented Feb 15, 2022 at 17:57

1 Answer 1

2

I have managed to get the script to work. After every or it is important to state in which column. Such as ST1 in Frost_Kopp or ST2 in Frost_kopp, etc

Kadir Şahbaz
78.6k57 gold badges260 silver badges407 bronze badges
answered Feb 15, 2022 at 17:05
1
  • your first two "elif" condition test both for "'ST1' or 'ST2' or 'ST3' in FIRST_KOPP" regardless of syntax issue if the firsts is true the second wont be evaluated.... Commented Feb 15, 2022 at 17:19

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.