2

I'm trying to calculate a field using Python with field calculator but am running into a syntax error. I'm hoping someone can point out what the error is, and I can't seem to figure it out. Below is the code.

Unfortunately, BUS_YR is stored as a string. It has the last 2 digits of a year and I'm trying to convert it into an integer of the full year. So 96 becomes 1996 and 00 becomes 2000.

def Reclass(NEWYEAR):
  BUS_YR=int(BUS_YR)
  If BUS_YR > 90:
    return BUS_YR+1900
  Else: 
    return BUS_YR+2000
3

if and else need to be lower case in Python

  • Well son of a bitch. It's always something simple. – JackOfTales Sep 15 '17 at 15:52
1

Here is how the code should read with the suggested correction (as mentioned previously) with if and else, lower cased.

def Reclass(NEWYEAR):  
    BUS_YR=int(BUS_YR)  
    if BUS_YR > 90:  
        return BUS_YR+1900  
    else:   
        return BUS_YR+2000  

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.