I need to find a way to find a specific value in the attribute table and then export all rows with said value to a new feature class.
Below is the code that I have managed to come up with (using other answers on this site). It gives the FID of the rows with the value searched but I can't find a way to select and export those records to a new file.
import arcpy
arcpy.env.overwriteOutput = True
# Set the environment
workspace = r"\\C:\\GIS\\"
arcpy.env.workspace = workspace
fc = "species.shp"
# Get fields in the attribute table
field_names = [f.name for f in arcpy.ListFields(fc, field_type='String')]
print(field_names)
# Loop through fields
for field in field_names:
# Create a search cursor through rows in the feature class that looks for "In Danger" values and prints the record's FID number
search = arcpy.da.SearchCursor(fc, "*")
for row in search:
if "In Danger" in row:
print("In Danger value for FID {0}".format(row[0]))
arcpy.Select_analysis(fc, 'new_fc', '{} like \'%{}%\''.format(field, 'In Danger'))