Problems with SQL expression formatting and Calculate field management

المشرف العام

Administrator
طاقم الإدارة
first of all I apologize if the language is wrong, I'm fairly new with python. So what I am trying to do is with the population census tract I'm trying to calculate the percentage of population by each census tract the field (Populati_2). To do this I'm creating a new field with the total sum of the population (pop). To get the percentage I'm doing the following expression on arcgis [Populati_2] / [Pop] *100 it works fine in arcgis but when I'm doing the calculate field management or python it just doesn't work. I'm not sure how to format the expression, I have tried every single combination and it's just not working.

Here's part of the script:

arcpy.AddField_management(r"Results\popjoin.dbf", "Pop", "LONG", "", "", "5")arcpy.AddField_management(r"Results\popjoin.dbf", "Pop2", "DOUBLE", "", "", "5")arcpy.CalculateField_management(r"Results\popjoin.dbf", "Pop", summed_total)arcpy.CalculateField_management(r"Results\popjoin.dbf", "Pop2", '''Populati_2] / [Pop] *100''')

This one gives me errors, but the following does not give me any errors but I get a 0 in every row instead of the calculation.

expression = "!Populati_2! / !Pop! * 100"

arcpy.CalculateField_management(r"Results\popjoin.dbf", "Pop2", expression, "PYTHON_9.3")

Any help is appreciated!!



أكثر...
 
أعلى