I have created code that averages the yearly data and creates a list of lists, like so:
[[‘1988’, 0.09680851063829785, 1.2444680851063827], [‘1989’, 0.2046808510638298, 1.0231914893617025]]
I want to append this data to the boundary that I have, but when I do so it only adds the first row of data.
How do I get this data appended to more rows?
# Add necessary fields if they don't already exist
if not arcpy.ListFields(outlayer, "YEAR"):
arcpy.AddField_management(outlayer, "YEAR", "SHORT")
if not arcpy.ListFields(outlayer, "NITRATE"):
arcpy.AddField_management(outlayer, "NITRATE", "FLOAT")
if not arcpy.ListFields(outlayer, "AMMONIA"):
arcpy.AddField_management(outlayer, "AMMONIA", "FLOAT")
print(f"Processing boundary data for '{outlayer}'...")
# Update the feature layer with data from ndata
with arcpy.da.UpdateCursor(outlayer, ['YEAR', 'NITRATE', 'AMMONIA']) as cursor:
for row, yearly_avg in zip(cursor, ndata):
year_value = yearly_avg[0]
no3_value = yearly_avg[1]
nh4_value = yearly_avg[2]
# Update cursor row with new values
row[0] = year_value
row[1] = no3_value
row[2] = nh4_value
# Update the row in the feature layer
cursor.updateRow(row)
New contributor
Ashlee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.