While this isn't a Field Calculator method, have you considered creating a Database View of 3hr table? You could summarize the 8 entries per RoadID, then create a simple Join data back to the road featureclass, rather than using the relate.
If you are using a RDBMS, you could make a dynamic View through it's internal methods that you could simply Join to the road featureclass. This would keep the tabular summary data always up-to-date.
If you need to do this in a pGDB or fGDB, you could script the process through ModelBuilder fairly easily, although you would need to update the data manually. And by using the "in_memory" workspace, you would also avoid creating a temporary table on disk.
The process I would use would be something like:
Input Table-> Summarize data-> Make View (in_memory)-> Join field to shapefile.
Tools you would likely use include:
- Summary Statistics
- Make Table View
- Join Field (ArcInfo) or Add Join (ArcView/Editor)
Read up in the ArcGIS online help for specifics of each tool.
Assuming your regular expression is working as expected, I think you have an indentation problem wiht your second try/except. Also, I can't say it is the best way, but I might only create an insert cursor when you get to the part you want to insert.
Table2 = "D:\Source_Data_Convert.gdb\Table2"
RAW_Data = "D:\Source_Data_Convert.gdb\RAW_Data_Table2"
#Create Cursors and Insert Rows
with arcpy.da.SearchCursor(RAW_Data, ["Field1", "Other_Stuff", "That_Stuff", "Some_More"]) as searchcursor:
######## Start the SearchCursor Loop ###################
for row in searchcursor:
try:
Other_Stuff = row[1]
That_Stuff = row[2]
Some_More = row[3]
listFrom = re.split(r'\*\s*\(.*?\)\s*', row[0])
print listFrom
Nums = re.findall(r'\(([^)]+)\)', row[0])
for match in re.finditer(r'\(([^)]+)\)', row[0]):
parts = match.group(1).split('/')
print parts
First_Num = parts[0]
try:
Second_Num = parts[1]
except IndexError:
#Second_Num = None
Second_Num = 0
print "First_Num, Second_Num: ", First_Num, Second_Num
print "Parsing Successful"
with arcpy.da.InsertCursor(Table2, ["Other_Stuff", "That_Stuff", "Some_More", "From", "To", "Num_One", "Num_Two", "Nums"]) as ic:
for n,Value in enumerate(match): #enumerate is essentially doing a count
ic.insertRow((Other_Stuff, That_Stuff, Some_More, listFrom[n], listFrom[n+1], First_Num, Second_Num, Nums[n]))
print "Data Inserted"
except:
pass
else:
break
Best Answer
You can use the Python setdefault() method and an UpdateCursor to do this.
To illustrate what is going on behind the scenes,
setdefault()
adds a new key and unique value for every new species it encounters: