[GIS] Script for Sum of Rows in field calculator – VB or Python

arcgis-desktoparcpyfield-calculatorpython-parser

I wrote the TOTAL_FREQUENCY values manually. But I want to automatically write this values with a script. Namely, I want to write sum of column 3 to all of the the column 5 rows. How can I do it with a script?

enter image description here

Best Answer

The following standalone-script should do the work for ArcGIS 10.x:

import arcpy

arcpy.env.workspace = 'myGeodatabase'

cursor = arcpy.SearchCursor('myLayer', ['frequency'])
sum = 0
for row in cursor:
    sum += row[0]

cursor = arcpy.UpdateCursor('myLayer', ['total_frequency'])
for row in cursor:
    row[0] = sum
    cursor.updateRow(row)

del cursor