I'm trying to populate a field (Season, "TEXT") in my attribute table with a season code based on a sampling date (FIXDATE, "DATE"). For example sample collected between 01/01/2016 and 01/03/2016 would get season code "SPRING". I'm new to arcpy and search cursors. Here is my code so far.
import arcpy
from datetime import datetime
caribou = "C:/Python/Test_data.gdb/test_data"
fields = ['FIXDATE', 'Season']
with arcpy.da.UpdateCursor(caribou, fields) as cursor:
for row in cursor:
if (row[0] >= datetime.strptime("01/01/2016", "%d/%m/%y") and row[0] <= datetime.strptime("01/03/2016", "%d/%m/%y")):
row[1] = "SPRING"
elif (row[0] >= datetime.strptime("02/03/2016", "%d/%m/%y")and row[0] <= datetime.strptime("01/06/2016", "%d/%m/%y")):
row[1] = "SUMMER"
elif (row[0] >= datetime.strptime("02/06/2016", "%d/%m/%y") and row[0] <= datetime.strptime("01/10/2016", "%d/%m/%y")):
row[1] = "FALL"
elif (row[0] >= datetime.strptime("02/10/2016", "%d/%m/%y")):
row[1] = "WINTER"
# Update the cursor with the updated list
cursor.updateRow(row)
for row in cursor...
inside thewith
statement.