<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Skript to sum up attribute values and copy them into a table in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/skript-to-sum-up-attribute-values-and-copy-them/m-p/445299#M34872</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Here is an example on how to do this.&amp;nbsp; The code uses the Summary Statistics tool to summarize the Area field in each polygon feature class within feature datasets, then writes the feature class name and Area sum to a previously created table.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
from arcpy import env
env.overwriteOutput = True
env.workspace = r"C:\MapsandGeodatabase\LocalGovernment.gdb"

arcpy.CreateTable_management(env.workspace, "AREA_SUM")
arcpy.AddField_management("AREA_SUM", "Name", "Text", "75")
arcpy.AddField_management("AREA_SUM", "SUM_Shape_Area", "Double")

for dataset in arcpy.ListDatasets("*"):
&amp;nbsp;&amp;nbsp;&amp;nbsp; lstFCs = arcpy.ListFeatureClasses("*", "", dataset)
&amp;nbsp;&amp;nbsp;&amp;nbsp; for fc in lstFCs:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; desc = arcpy.Describe(fc)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if desc.shapeType == "Polygon":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows = arcpy.InsertCursor("AREA_SUM")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row = rows.newRow()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.Name = fc
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sumArea = arcpy.Statistics_analysis(fc, "Stats", [["Shape_Area", "SUM"]])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows2 = arcpy.SearchCursor(sumArea)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row2 in rows2:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; totArea = row2.getValue("SUM_Shape_Area")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.SUM_Shape_Area = totArea
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.insertRow(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; totArea = 0


del row, rows, row2, rows2

arcpy.Delete_management("Stats")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 19:54:11 GMT</pubDate>
    <dc:creator>JakeSkinner</dc:creator>
    <dc:date>2021-12-11T19:54:11Z</dc:date>
    <item>
      <title>Skript to sum up attribute values and copy them into a table</title>
      <link>https://community.esri.com/t5/python-questions/skript-to-sum-up-attribute-values-and-copy-them/m-p/445297#M34870</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hallo,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I ve a lot of gdb-features in different feature datasets. I would like to sum up all "shape_area" values of each feature and copy the result of the sum in an output table. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;To identify the source of the number in the output table, I need an additional column with the name of the source file.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;How can I do this?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanx&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Matthias&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Aug 2011 09:56:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/skript-to-sum-up-attribute-values-and-copy-them/m-p/445297#M34870</guid>
      <dc:creator>MatthiasAbele</dc:creator>
      <dc:date>2011-08-24T09:56:32Z</dc:date>
    </item>
    <item>
      <title>Re: Skript to sum up attribute values and copy them into a table</title>
      <link>https://community.esri.com/t5/python-questions/skript-to-sum-up-attribute-values-and-copy-them/m-p/445298#M34871</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;create an output table with name and area fields&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;get a list of the data sets&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;get a list of the feature classes in each data set&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;cycle through the feature classes, one data set at at time&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;create a search cursor on the first feature class&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;run through the records, adding the area of that record to a running total&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You have the feature class name already&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;write the name and total area to a python list&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;add that list as a member of a list of lists&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;do the next feature class in that data set&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;after that, do the next data set&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;... and so on&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;then&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;create an insert cursor for the output table&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;cycle through the list of lists, adding each name and total area sub list as a new record&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;all done.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Aug 2011 18:05:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/skript-to-sum-up-attribute-values-and-copy-them/m-p/445298#M34871</guid>
      <dc:creator>markdenil</dc:creator>
      <dc:date>2011-08-25T18:05:51Z</dc:date>
    </item>
    <item>
      <title>Re: Skript to sum up attribute values and copy them into a table</title>
      <link>https://community.esri.com/t5/python-questions/skript-to-sum-up-attribute-values-and-copy-them/m-p/445299#M34872</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Here is an example on how to do this.&amp;nbsp; The code uses the Summary Statistics tool to summarize the Area field in each polygon feature class within feature datasets, then writes the feature class name and Area sum to a previously created table.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
from arcpy import env
env.overwriteOutput = True
env.workspace = r"C:\MapsandGeodatabase\LocalGovernment.gdb"

arcpy.CreateTable_management(env.workspace, "AREA_SUM")
arcpy.AddField_management("AREA_SUM", "Name", "Text", "75")
arcpy.AddField_management("AREA_SUM", "SUM_Shape_Area", "Double")

for dataset in arcpy.ListDatasets("*"):
&amp;nbsp;&amp;nbsp;&amp;nbsp; lstFCs = arcpy.ListFeatureClasses("*", "", dataset)
&amp;nbsp;&amp;nbsp;&amp;nbsp; for fc in lstFCs:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; desc = arcpy.Describe(fc)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if desc.shapeType == "Polygon":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows = arcpy.InsertCursor("AREA_SUM")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row = rows.newRow()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.Name = fc
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sumArea = arcpy.Statistics_analysis(fc, "Stats", [["Shape_Area", "SUM"]])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows2 = arcpy.SearchCursor(sumArea)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row2 in rows2:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; totArea = row2.getValue("SUM_Shape_Area")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.SUM_Shape_Area = totArea
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.insertRow(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; totArea = 0


del row, rows, row2, rows2

arcpy.Delete_management("Stats")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:54:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/skript-to-sum-up-attribute-values-and-copy-them/m-p/445299#M34872</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-11T19:54:11Z</dc:date>
    </item>
    <item>
      <title>Re: Skript to sum up attribute values and copy them into a table</title>
      <link>https://community.esri.com/t5/python-questions/skript-to-sum-up-attribute-values-and-copy-them/m-p/445300#M34873</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanx for the code...do you any good sites which can help me to get used to python???&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Yours,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Matthias&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Aug 2011 14:43:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/skript-to-sum-up-attribute-values-and-copy-them/m-p/445300#M34873</guid>
      <dc:creator>MatthiasAbele</dc:creator>
      <dc:date>2011-08-29T14:43:07Z</dc:date>
    </item>
    <item>
      <title>Re: Skript to sum up attribute values and copy them into a table</title>
      <link>https://community.esri.com/t5/python-questions/skript-to-sum-up-attribute-values-and-copy-them/m-p/445301#M34874</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Here is a link to some ESRI training courses:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://training.esri.com/gateway/index.cfm?fa=search.results&amp;amp;searchterm=python+arcpy"&gt;http://training.esri.com/gateway/index.cfm?fa=search.results&amp;amp;searchterm=python+arcpy&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I highly recommend &lt;/SPAN&gt;&lt;A href="http://training.esri.com/gateway/index.cfm?fa=catalog.courseDetail&amp;amp;CourseID=50121644_10.x"&gt;'Introduction to Geoprocessing Scripts Using Python'&lt;/A&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Aug 2011 15:47:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/skript-to-sum-up-attribute-values-and-copy-them/m-p/445301#M34874</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2011-08-29T15:47:53Z</dc:date>
    </item>
  </channel>
</rss>

