I have this code that performs a Summarize Within on all company stores for every month of the year. However, not all the stores were open in some of the early months so I need to write some code that will identify that the "USER_PatientVisits" is equal to zero and then skip that store and move on to the next. I'm thinking this can be accomplished using an "If" statement and probably a loop; however, I'm not sure what exactly to write and how to bring it all together.
Here is the top portion of my code for January and February; the full code continues on through December:
import arcpy
import sys
import os
import datetime
arcpy.env.overwriteOutput = True
from arcpy import env
env.workspace = r"C:\arcGIS_Shared\Python\CenterHeatMaps.gdb"
fc = 'Open_Store_Centers'
fields = ['USER_market_id','USER_Store_ID','USER_Store_Center_Name']
fieldname = 'USER_market_id'
whereclause = """{} = 2000""".format(arcpy.AddFieldDelimiters(fc, fieldname))
cursor = arcpy.da.SearchCursor(in_table = fc, field_names = fields, where_clause=whereclause, sql_clause=(None, 'ORDER BY USER_market_id, USER_Store_ID'))
for row in (cursor):
polys = "Market{0}".format(row[0])+"Blocks"
points = "Jan_NWPatientVisits{0}".format(row[0])+"{0}".format(row[2])
outFeatureClass = "Jan_NWSumWithin{0}".format(row[0])+"{0}".format(row[2])
keepAll = 'ONLY_INTERSECTING'
sumFields = [['USER_VisitCount', 'Sum']]
addShapeSum = 'ADD_SHAPE_SUM'
arcpy.SummarizeWithin_analysis(polys, points, outFeatureClass, keepAll, sumFields, addShapeSum, '')
print(row[2])
print (arcpy.GetMessages())
fc = 'Open_Store_Centers'
fields = ['USER_market_id','USER_Store_ID','USER_Store_Center_Name']
fieldname = 'USER_market_id'
whereclause = """{} = 2000""".format(arcpy.AddFieldDelimiters(fc, fieldname))
cursor = arcpy.da.SearchCursor(in_table = fc, field_names = fields, where_clause=whereclause, sql_clause=(None, 'ORDER BY USER_market_id, USER_Store_ID'))
for row in (cursor):
polys = "Market{0}".format(row[0])+"Blocks"
points = "Feb_NWPatientVisits{0}".format(row[0])+"{0}".format(row[2])
outFeatureClass = "Feb_NWSumWithin{0}".format(row[0])+"{0}".format(row[2])
keepAll = 'ONLY_INTERSECTING'
sumFields = [['USER_VisitCount', 'Sum']]
addShapeSum = 'ADD_SHAPE_SUM'
arcpy.SummarizeWithin_analysis(polys, points, outFeatureClass, keepAll, sumFields, addShapeSum, '')
print(row[2])
print (arcpy.GetMessages())