hi, all I've been trying to run a script to update a feature class but the message i get (part of the script) state "No matching values in CSV of join field: plus the value ". any advice? this is the script i have. thanks
import arcpy
import csv
gdb_path = r'S:\PW\GIS\Map Requests\Water_MeterProject\MapProject_11x17\RIDVSQL.sde'
fc = r'S:\PW\GIS\Map Requests\Water_MeterProject\MapProject_11x17\RIDVSQL.sde\RIGIS.DBO.Water_Features\RIGIS.DBO.ResidentialWaterMeter'
csv_file = r'S:\PW\GIS\Map Requests\Water_MeterProject\Account Data 100124.csv'
#fields in fc to update
fc_fields = ['Address', 'SerialNumber']
#field in csv to update
csv_fields = ['service_address', 'serial_no']
csv_data = {}
with open(csv_file, 'r') as f:
reader = csv.DictReader(f)
for row in reader:
csv_data[row[csv_fields[0]]] = row
arcpy.env.workspace = gdb_path
edit = arcpy.da.Editor(gdb_path) #start edit session
edit.startEditing(False, True)
edit.startOperation()
with arcpy.da.UpdateCursor(fc, fc_fields) as cursor:
for row in cursor:
join_value = row[0]
if str(join_value) in csv_data:
csv_row = csv_data[str(join_value)]
for i in range(1, len(fc_fields)):
fc_field_name = fc_fields[i]
csv_field_name = csv_fields[i]
row[i] = csv_row[csv_field_name]
cursor.updateRow(row)
else:
print("No matching values in CSV of join field: {join_value}")
edit.stopOperation()
edit.stopEditing()
print("updatedSucessfully")
Would it be possible to print both the join_value and the csv_data? It could be that the join_value is not in the csv_data, the address could be null or none as well.
I would start placing some prints around that would allow for some debugging!
Cody
to format the code with line numbers for reference, see...
Code formatting ... the Community Version - Esri Community
It should just match. Have the exact values in both the CSV and feature class .
The error is just printed from your Else statement so I wouldn't take it as wrote. If you can format your code with indentation that would help troubleshoot. Dan has linked the formatting guide above.