I'm trying to calculate multiple fields that all begin with "B01". This calculation consists of multiplying the fields by a field that contains a percentage ("TractPercent") and then dividing the results of that multiplication by a population field ("BufferPOP").
The problem I'm having is incorporating the variable associated with my "for loop" with my Python3 expression.
Here is my code:
import arcpy
### set workspaces
arcpy.env.workspace = r"C:\arcGIS_Shared\Python\Demographics.gdb"
relpath = r'C:\arcGIS_Shared\Python'
p = arcpy.mp.ArcGISProject(relpath + r'\Demographics.aprx')
m = p.listMaps('Map')[0]
layers = m.listLayers("DalyCity_HalfMile_Demographics")
for layer in layers:
print(layer)
DemoFields = arcpy.ListFields(layer, "B01*", "ALL")
for DemoField in DemoFields:
arcpy.CalculateField_management(layer, DemoField, "(+DemoField+ *
!TractPercent!) / !BufferPOP!", "PYTHON3")
print(layer.name + ' ' + DemoField + ' Calculated')
When I run the code this way I get the following error, but can't figure out what I need to change.
ERROR 000622: Failed to execute (Calculate Field). Parameters are not valid.
ERROR 000623: Invalid value type for parameter field