I've been building on some principles from Richard Fairhurst's Blog/blogs/richard_fairhurst/2014/11/08/turbo-charging-data-manipulation-with-python-cursors-and-diction... My goal is to map the average daily well volume for the past 90 days. I have a table of daily volumes for about 1,300 wells. There are several years worth of records in the table. I also have a Python dictionary. The keys in the dictionary are the unique identifier for each well represented in the table. The values in the dictionary start as empty lists. The following block of code populates the dictionary values with the daily volume values from the past 92 days for each well. The code works, but it takes approximately 40 seconds for each well. How can I modify the code to improve performance? Please see the code and comments below. Any suggestions would be greatly appreciated.
i = 0
table = acDaily
fields = ['PROPNUM','D_DATE','WATER']
for prop in propNumDict:
i += 1
print str(i) + " - " + strftime("%Y-%m-%d %H:%M:%S")
if i > 2:
break
else:
with arcpy.da.SearchCursor(table, fields) as cursor:
for row in cursor:
if row[0] == prop and row[1] > tMinus92:
propNumDict[prop].append(row[2])
print propNumDict
print strftime("%Y-%m-%d %H:%M:%S")
After the propNumDict dictionary is populated, I have another block of code that creates a new dictionary and populates it with the average values for each key in propNumDict. Here's what that looks like:
avgDailyDict = {}
for key, values in propNumDict.iteritems():
if float(len(values)) > 0:
avgDailyDict[key] = sum(values)/float(len(values))
print avgDailyDict
arc gis python
dictionary
arcpy.da.searchcursor