I'm trying to update a feature class with new data from a csv file. My workflow is as follows:
- Make a csv reader from csv file
- Identify my data columns using their index position
- Use an update cursor to update the values in the shapefile with data from the csv
Here is my code so far:
import csv import arcpy csvfile = "C:\\Data\\data.csv" shpfile = "C:\\Data\\TEST.gdb\\azcounties" file = open(csvfile,"r") csvReader = csv.reader(file) header = csvReader.next() nameIndex = header.index("NAME") dateIndex = header.index("DATE") valueIndex = header.index("VALUE") dateField = "DATE" nameField = "NAME_2" valueField = "VALUE" with arcpy.da.UpdateCursor(shpfile,(nameField,dateField,valueField)) as cursor: for row in cursor: for rw in csvReader: row = rw[nameIndex] row = rw[dateIndex] row = rw[valueIndex] cursor.updateRow(row)
It seems to almost work. I don't get any errors, but only the first row in the shapefile gets updated.