# How to use Field Calculator to calculate area as percentage?

I am searching for python code to use in Field Calculator to calculate area as a percentage in relation to another field? The area percentage needs be calculated based on the total area for each "Basin_ID" separately.

## 1 Answer

Here's one way you could do it:

Summary Statistics with the statistics field of sum on Area_Ac and a case field of Basin_ID.

Then join the two tables together, and run Field Calculator like this:

Parser:

``````Python
``````

Expression:

``````!Area_Ac!/!<sum field>!
``````

Here is an ArcMap 10.1 script version:

``````import arcpy

vals = [[r for r in row] for row in arcpy.da.SearchCursor(fc, ["Basin_ID", "Area_Ac"])]
sums = dict([[i, float(sum(zip(*filter(lambda f: f == i, vals))))]
for i in sorted(list(set(zip(*vals))))])

with arcpy.da.UpdateCursor(fc, ["Basin_ID", "Area_Ac", "Area_perce"]) as rows:
for row in rows:

try:    row = row/sums.get(row)
except:     pass

rows.updateRow(row)
``````
• This is probably the easiest way I can think of without scripting. – Fezter Jul 31 '13 at 0:13