At first I made a statistic analyst to get the sum of the field area for equal Ids.Now I need the sum of all area fields from the output-table therefore I did another statistic analyst to get the sum. With a searchcursor I tried to get the sumvalue to put it in the calculate field tool. But in the end it is not calculating the percent, so the field I add before and I don’t know what I did wrong. I need to do it with arcpy because it is a small part of a big tool I’m trying to build and the sumvalue will change from input to input.
It would be wonderful if you can tell me my mistake.
The following code is working, but there is just a 0 in the percent field.
from arcpy import env
env.overwriteOutput = True
env.workspace = r"D:\Users\jul\ers\cities_UA\resultfolder"
inputshp = r"D:\Users\jul\ers\cities_UA\resultfolder\at005l_innsbruck_result.shp"
arcpy.Statistics_analysis(inputshp, outtable, [["area", "SUM"]], "Id")
arcpy.Statistics_analysis(outtable, outtableSUM, [["SUM_area", "SUM"]])
with arcpy.da.SearchCursor(outtableSUM, "SUM_SUM_ar") as cursor:
for row in cursor:
fieldsum = (int(row))
arcpy.AddField_management(outtable, "prozent", "DOUBLE")#working
arcpy.CalculateField_management(outtable, "prozent", "([SUM_area]*100)/fieldsum", "VB")