I'm trying to update a feature class with new data from a csv file. My workflow is as follows:
import csvimport arcpycsvfile = "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[0] = rw[nameIndex] row[1] = rw[dateIndex] row[2] = 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.
أكثر...
- 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
import csvimport arcpycsvfile = "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[0] = rw[nameIndex] row[1] = rw[dateIndex] row[2] = 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.
أكثر...