I am working on a project for an online class that uses Python with ArcGIS Pro. This is a beginner class but I am terrible with scripting so everything is a struggle for me. This is the prompt: "Write a Python script that finds the difference between populations for U.S. counties from 1990 to 2010 and writes that information to a new field." This data was given to us to download and import into Pro.
I have used python to create the new field in the table in Pro, but I have no idea how to take the two other fields that contain the 1990 population and the 2010 population and use them to populate my new field I created in the table.
This is the tutorial they gave us to go off of:
# Define the object with which we are working.
cities = "Cities.shp" # Notice I don't use the whole path if the file is in the workspace.
# Finds city names and coordinates
with arcpy.da.UpdateCursor(cities, ["NAME", "X_CO", "Y_CO" "SHAPE@X", "SHAPE@Y"]) as cursor:
for row in cursor:
NAME = row[0]
x = row[3]
y = row[4]
# Here we have opened an update cursor to find data inside cities.
# This lets us read and write data to this file.
# "NAME", "X_CO", and "Y_CO" are names of a fields containing city names.
# and blank fields.
# SHAPE@X and SHAPE@Y are tokens to retrieve the X and Y data for each city.
# We have then saved the data to a variable
# Let's populate the X_CO and Y_CO fields with X Y data.
row[1] = x
row[2] = y
cursor.updateRow(row)
For me I don't understand how this is the same thing as what the prompt is telling me to do, but again I struggle a lot with writing/understanding scripts.
I feel like I am missing something very simple that would make all of this click for me. Not looking for someone to just write it out for me, but any direction would be greatly appreciated.