Player Profiles: Key Contenders
Player A: The Formidable Favorite
This player has consistently performed well on hard courts, making them a favorite for many analysts. With an impressive win-loss record this season, their strategic gameplay and mental fortitude make them a formidable opponent in any match.
<|vq_13809|>%end_of_first_paragraph%%
userI am working with ArcGIS Desktop using Python script tool. I have some attribute fields which I want to convert into Date type but it is throwing error because some values are not in correct format. How can I handle these values without stopping whole process?
I tried using try except block but it is still throwing error when I try converting all values at once. Is there any way I can do this one by one?
The field name is "date" which contains string values like "10/31/2016", "12-01-2017", etc.. Some values are already correct date format but some are incorrect like "01/02/13" or just plain text like "test". I want all these incorrect dates to be converted into NULL or empty string so that it won't throw error while converting other correct dates into Date type.
I am using following code inside my script tool but it doesn't work :
# Replace bad date entries with NULL
arcpy.AddMessage("Replacing bad date entries with NULL")
with arcpy.da.UpdateCursor(fc,"date") as cursor:
for row in cursor:
try:
datetime.datetime.strptime(row[0], '%m/%d/%Y')
except ValueError:
row[0] = None
cursor.updateRow(row)
I get following error :
Error Traceback (most recent call last):
File "C:Program Files (x86)ArcGISDesktop10.5arcpyarcpyda.py", line
2539,in __next__
row = self.fetchone()
File "C:Program Files (x86)ArcGISDesktop10.5arcpyarcpyda.py", line
2494,in fetchone
raise OperationError("ERROR [000900]: Error running expression."
OperationError: ERROR [000900]: Error running expression.
Failed to execute (UpdateCursor). Parameters are not valid.
ERROR [000900]: Error running expression.
Failed to execute (UpdateCursor).
Failed at ExecutePythonScript (line:34)
I also tried following code which also didn't work :
# Replace bad date entries with NULL
arcpy.AddMessage("Replacing bad date entries with NULL")
with arcpy.da.UpdateCursor(fc,"date") as cursor:
for row in cursor:
try:
datetime.datetime.strptime(row[0], '%m/%d/%Y')
except ValueError:
row[0] = ""
cursor.updateRow(row)
Please help me find out what am i doing wrong? Thanks!