Select to view content in your preferred language

My python script calculates only the value of the immediate previous record

3579
10
Jump to solution
04-26-2016 11:26 AM
OLANIYANOLAKUNLE
Frequent Contributor

My python script calculates only the value of the immediate previous record instead of calculating the values of all preceding records before that particular record. The example (the image) below is the undesired output;

Untitled.png

While the image below here is what i want to achieve;

Untitled2.png

This is my python script i used;

import arcpy
from arcpy import da
CensusBldForm = "CensusBldForm"
Calculated_EA1=0
with arcpy.da.UpdateCursor(CensusBldForm, ["OBJECTID", "EstimatedPopulationinEA", "Calculated_EA"]) as cursor:
     for row in cursor:
          Calculated_EA2 = row[1]
          row[2] = (Calculated_EA1 + Calculated_EA2)
          Calculated_EA1 = Calculated_EA2
          cursor.updateRow(row)

Kindly assist me with the above please.

Tags (1)
0 Kudos
10 Replies
OLANIYANOLAKUNLE
Frequent Contributor

Thanks

0 Kudos