I am trying to run the select attribute tool for a layer that I created. I can manually run the tool in ArcMap, but when I write the script the code fails after the copy feature tool was used. Not sure what I am doing wrong, I am using the ArcMap help section to get a general idea of the code that I needed.
I am new to python, so I appreciate any guidance anyone has:
#Import a CSV file that will show you what ASOS weather stations are in the state.
#Lets you write over the shape file if needed
arcpy.env.overwriteOutput = True
arcpy.env.workspace = "C:\\GEOG485\\FinalProject"
#Latitude and Longitude Coordinates
xFieldName = 'LON'
yFieldName = 'LAT'
outFolder = "C:\\GEOG485\\FinalProject\\Output"
#ASOS stations layer
eventLayer = "ASOS"
outPutlayer = "C:\\GEOG485\\FinalProject\\FinalProject.gdb\\CurrentStations"
stateLayer = "C:\\GEOG485\\FinalProject\\FinalProject.gdb\\State_ASOS"
spatialRef = arcpy.SpatialReference(4326)
#CSV file that will be imported into ArcMap
csvFilePath = "C:\\GEOG485\\FinalProject\\isd-history.csv"
#Select state of interest
targetState = 'NJ'
#Date of file last updated
targetEnd = '20190329'
#import csv file using the xy event layer tool
arcpy.MakeXYEventLayer_management(csvFilePath, xFieldName, yFieldName, eventLayer, spatialRef)
#Copy features from the XY Event Layer in order to asign Object ID's to the rows in the file
stateQuery = '"STATE" = ' + "'" + targetState + "'"
#Select Attribute management to narrow down the state of interest
arcpy.SelectLayerByAttribute_management(outPutlayer, "NEW_SELECTION", stateQuery)
arcpy.SelectLayerByAttribute_management(outPutlayer, 'SUBSET_SELECTION', '"END" = ' + "'" + targetEnd + "'")
mxd = arcpy.mapping.MapDocument("C:\\GEOG485\\FinalProject\\basemap.mxd")
df = arcpy.mapping.ListDataFrame(mxd, "*")
newLayer = arcpy.mapping.Layer(outPutlayer)
arcpy.mapping.Layer(df, newLayer, "Bottom")