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
2 Answers 2
if
and else
need to be lower case in Python
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
Explore related questions
See similar questions with these tags.