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?
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 cursor = arcpy.UpdateCursor('myLayer', ['total_frequency']) for row in cursor: row = sum cursor.updateRow(row) del cursor
The following Python script (created by Terry Giles and mentioned in this ESRI forum) allows you to sum the values of a field and paste the sum in another field. The script is designed to work in the Toolbox so that when you run it, you can enter the Layer name, Field name and output:
#args to pass in: ##1 = input FC or table ##2 = field to sum up ##3 = field to write sum into import arcpy, sys intable = sys.argv field = sys.argv # Create search cursor rows = arcpy.SearchCursor(intable) row = rows.Next() x = 0.0 # Enter while loop for each feature/row while row: x += row.getvalue(field) print x row = rows.next() #note value can be rounded depending on field type gp.calculatefield(intable,sys.argv,float(x),"PYTHON")
Disclaimer: I am not an ArcGIS user therefore cannot confirm if this still works as this script was first posted way back in 2007.
It seems OP seeking field calculator expression. Here is one:
def getTotal(name,field): mxd = arcpy.mapping.MapDocument("CURRENT") lr=arcpy.mapping.ListTableViews(mxd,name) tbl=[row for row in arcpy.da.TableToNumPyArray(lr,field)] return sum(tbl)