<?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 Cumulative Sum by year? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/cumulative-sum-by-year/m-p/471302#M36772</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a table that is something like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Object&amp;nbsp;&amp;nbsp;&amp;nbsp; Year&amp;nbsp;&amp;nbsp;&amp;nbsp; Acres&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1980&amp;nbsp;&amp;nbsp; 5&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1979&amp;nbsp;&amp;nbsp; 3&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1978&amp;nbsp;&amp;nbsp; 2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1980&amp;nbsp;&amp;nbsp; 8&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1979&amp;nbsp;&amp;nbsp; 2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1976&amp;nbsp;&amp;nbsp; 6&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would like to use python to create a cumulative sum so that I end up with a table that looks like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1976&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1978&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1979&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1980&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 13&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm going to be graphing this using matplotlib, showing trends in acres over time.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm a beginner with python. So far I've tried to use FeatureClasstoNumPyArray and numpy's cumsum, but I can't get the array structured correctly to sum by year. I think part of my problem is that I don't really understand how an attribute table gets converted to an array.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If numpy is the wrong approach, pleases let me know. My requirements are that I can graph cumulative acres over time from a dataset that has polygons of various sizes occuring in specific years. If it matters for processing time, this dataset has about 140,000 records. Also, if you have any suggestions for python graphing modules or sample code that will do with kind of thing well, I'd like to know about them.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 09 Jan 2013 14:27:01 GMT</pubDate>
    <dc:creator>SpencerMeyer</dc:creator>
    <dc:date>2013-01-09T14:27:01Z</dc:date>
    <item>
      <title>Cumulative Sum by year?</title>
      <link>https://community.esri.com/t5/python-questions/cumulative-sum-by-year/m-p/471302#M36772</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a table that is something like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Object&amp;nbsp;&amp;nbsp;&amp;nbsp; Year&amp;nbsp;&amp;nbsp;&amp;nbsp; Acres&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1980&amp;nbsp;&amp;nbsp; 5&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1979&amp;nbsp;&amp;nbsp; 3&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1978&amp;nbsp;&amp;nbsp; 2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1980&amp;nbsp;&amp;nbsp; 8&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1979&amp;nbsp;&amp;nbsp; 2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1976&amp;nbsp;&amp;nbsp; 6&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would like to use python to create a cumulative sum so that I end up with a table that looks like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1976&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1978&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1979&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1980&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 13&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm going to be graphing this using matplotlib, showing trends in acres over time.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm a beginner with python. So far I've tried to use FeatureClasstoNumPyArray and numpy's cumsum, but I can't get the array structured correctly to sum by year. I think part of my problem is that I don't really understand how an attribute table gets converted to an array.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If numpy is the wrong approach, pleases let me know. My requirements are that I can graph cumulative acres over time from a dataset that has polygons of various sizes occuring in specific years. If it matters for processing time, this dataset has about 140,000 records. Also, if you have any suggestions for python graphing modules or sample code that will do with kind of thing well, I'd like to know about them.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Jan 2013 14:27:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cumulative-sum-by-year/m-p/471302#M36772</guid>
      <dc:creator>SpencerMeyer</dc:creator>
      <dc:date>2013-01-09T14:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum by year?</title>
      <link>https://community.esri.com/t5/python-questions/cumulative-sum-by-year/m-p/471303#M36773</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You're making this harder than it needs to be... use the Summary Statistics tool (or the Frequency tool if you prefer and licensed for it).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can simply execute the tool from Toolbox or script it, up to you, but it's the only tool you will need to perform this function...could also use a cursor, but it likely isn't necessary...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EDIT-&amp;nbsp; ...so Year would be your 'case' and Acres would be your 'statistic' to sum for.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Jan 2013 15:16:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cumulative-sum-by-year/m-p/471303#M36773</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2013-01-09T15:16:51Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum by year?</title>
      <link>https://community.esri.com/t5/python-questions/cumulative-sum-by-year/m-p/471304#M36774</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I would like to use python to create a cumulative sum so that I end up with a table that looks like:&lt;BR /&gt;1976&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6&lt;BR /&gt;1978&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;BR /&gt;1979&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&lt;BR /&gt;1980&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 13&lt;BR /&gt;&lt;BR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Actually, I meant THIS is what I want:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1976&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1978&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1979&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 13&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1980&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 26&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Summary stats gets me the first part, but then I need to do a cumulative sum by year so I can graph such that the x-axis is the year, and y-axis is total, cumulative acres.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm sorry I didn't explain it correctly the first time. Thanks for your quick response.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Jan 2013 15:23:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cumulative-sum-by-year/m-p/471304#M36774</guid>
      <dc:creator>SpencerMeyer</dc:creator>
      <dc:date>2013-01-09T15:23:28Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum by year?</title>
      <link>https://community.esri.com/t5/python-questions/cumulative-sum-by-year/m-p/471305#M36775</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Oh I see, looks like you are sorting by year (which would make sense on an axis)....this is a bit of a workaround, but it will work if you take the table result of the Summary Statistics output and input that into a sorted update cursor (by year), then in a new field calculate the previous record acreage + the current record acreage... make sense?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In other words, use a variable to 'hold' the last record's acreage value + the cummulative acreage to this point in the processing --- so in your example initiating the update cursor to the 1st record, you can fetch the 1st acreage value:&amp;nbsp; 6&amp;nbsp; (initiating the variable to 0, setvalue for the new 'cummulative value' field to 0)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Iterate over the records, the next record value is for 1978 is 2 (using getvalue) --- add that to your current var value of 6, that's 6 + 2 = 8.&amp;nbsp; setvalue, update the var to 8, go to the next row...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Next row is for 1979 is 5, so 8 + 5 = 13... &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Get it?&amp;nbsp; The code is easy to write, see the webhelp examples for cursor processing...post back if you get stuck.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-Wayne&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Jan 2013 15:34:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cumulative-sum-by-year/m-p/471305#M36775</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2013-01-09T15:34:39Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum by year?</title>
      <link>https://community.esri.com/t5/python-questions/cumulative-sum-by-year/m-p/471306#M36776</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;...in short, see the code below (also the webhelp link below that will help explain).&amp;nbsp; Note that comments to aid you in following the code are preceded by the '#' symbol.&amp;nbsp; Sorry, I forgot you said you were just beginning to use Python.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
# import the module, arcpy...
import arcpy

# Set the current workspace environment variable.
arcpy.env.workspace = r'C:\Documents and Settings\whitley-wayne\My Documents\ArcGIS\Default.gdb'

# I set up a 'mock' table representing the summary output table,
# called 'SummaryStatsOutput'.&amp;nbsp; Set the table variable 'tbl' to that...
tbl = 'SummaryStatsOutput'

# Define another variable 'accumVal' to represent accumulated ACREAGE.
# Initiate it to zero (0).
accumVal = 0

# Establish the 'rows' cursor variable on tbl, which takes 5 parameters -
# The 3 middle ones are 'blank'...
# The last one is the sort parameter - sorting by YEAR...
# (since my mock table was not in order).
rows = arcpy.UpdateCursor(tbl, '', '', '', 'YEAR A')

# looping on 'row' objects contained in the 'rows' cursor object...
for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Adding the current 'getValue' fetch from the ACREAGE field to accumVal.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # (This is '0' for 1st record).
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; accumVal = accumVal + row.getValue('ACREAGE')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Setting the ACREAGE field to the 'new' accumVal.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # (a new field wasn't necessary)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue('ACREAGE', accumVal)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Updating the row object within the cursor object
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # (committing the changes)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)

# Outside the loop, delete the objects to remove lock reference on table
del row, rows
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is the 10 webhelp for the update cursor:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v0000003m000000" rel="nofollow noopener noreferrer" target="_blank"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v0000003m000000&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:51:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cumulative-sum-by-year/m-p/471306#M36776</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2021-12-11T20:51:30Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum by year?</title>
      <link>https://community.esri.com/t5/python-questions/cumulative-sum-by-year/m-p/471307#M36777</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Check out the pandas library -- it is very slick for time-series work.&amp;nbsp; Plus, you can integrate with your matplotlib work too.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://pandas.pydata.org/pandas-docs/dev/timeseries.html"&gt;http://pandas.pydata.org/pandas-docs/dev/timeseries.html&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Jan 2013 16:32:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cumulative-sum-by-year/m-p/471307#M36777</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2013-01-09T16:32:44Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum by year?</title>
      <link>https://community.esri.com/t5/python-questions/cumulative-sum-by-year/m-p/471308#M36778</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Tip: if you plan to use matplotlib to generate many figures from inside of a loop, make sure to close the figure each time you are finished saving it out!&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;plt.figure()

#...plotting code here

plt.savefig(out)
plt.close()&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you don't you will get severe memory leak and the ArcGIS software you are running the python script from will bomb out.&amp;nbsp; In my case I am running this as an ArcToolbox script and ArcCatalog would shutdown after a few hundred figures were generated.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:51:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cumulative-sum-by-year/m-p/471308#M36778</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2021-12-11T20:51:33Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum by year?</title>
      <link>https://community.esri.com/t5/python-questions/cumulative-sum-by-year/m-p/471309#M36779</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;In Python (and using the data access cursor model in ArcGIS v10.1) the code would look like this... Basically a re-write of the 'SUM' functionality of summary statistics tool using da cursors and a Python Dictionary. You would then use an insertCursor to write the values from 'summaryDict' back to a table on disk (not shown) or maybe you could hand the values in the dictionary straight to matplotlib?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;myTable = r"C:\test.gdb\my_table"
summaryDict = {}
searchRows = arcpy.da.SearchCursor(myTable, ["YEAR","ACRES"])
for searchRow in searchRows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; yearValue, acresValue = searchRow
&amp;nbsp;&amp;nbsp;&amp;nbsp; if yearValue in summaryDict:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; summaryDict[yearValue] = summaryDict[yearValue] + acresValue
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; summaryDict[yearValue] = acresValue
yearKeys = summaryDict.keys()
yearKeys.sort() #sort the years in ascending order
#Print some output
for yearValue in yearKeys:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print str(yearValue) + " = " + str(summaryDict[yearValue]) + " acres"&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:51:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cumulative-sum-by-year/m-p/471309#M36779</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-11T20:51:35Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum by year?</title>
      <link>https://community.esri.com/t5/python-questions/cumulative-sum-by-year/m-p/471310#M36780</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Beautiful!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Jan 2013 18:20:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cumulative-sum-by-year/m-p/471310#M36780</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2013-01-10T18:20:47Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum by year?</title>
      <link>https://community.esri.com/t5/python-questions/cumulative-sum-by-year/m-p/471311#M36781</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Great stuff thanks! I'm hoping to use this to create creaming curves for oil and gas exploration. What I have noticed is that it creates totals of a value per yer but I think the main aim was to create cumulative totals. As an example I used this code on my data:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2011 = 35.0 mmboe&lt;/P&gt;&lt;P&gt;2012 = 616.666667 mmboe&lt;/P&gt;&lt;P&gt;2013 = 389.166667 mmboe&lt;/P&gt;&lt;P&gt;2014 = 348.333333 mmboe&lt;/P&gt;&lt;P&gt;2015 = 107.5 mmboe&lt;/P&gt;&lt;P&gt;2016 = 433.333333 mmboe&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Of which is correct as it creates totals for each year. Is it possible to create a cumulative total of this so each previous year is added to the total of the following year? I then want to plot cumulative curves using matplotlib.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Jul 2016 07:45:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cumulative-sum-by-year/m-p/471311#M36781</guid>
      <dc:creator>MatthewHowe</dc:creator>
      <dc:date>2016-07-05T07:45:09Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum by year?</title>
      <link>https://community.esri.com/t5/python-questions/cumulative-sum-by-year/m-p/471312#M36782</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The code by &lt;A href="https://community.esri.com/migrated-users/11835" target="_blank"&gt;Chris Snyder&lt;/A&gt;​ has all of the information already available in the &lt;SPAN style="font-family: courier new,courier;"&gt;summaryDict&lt;/SPAN&gt;, you just need to add some logic to the final loop to grab the previous year in addition to the current year.&amp;nbsp; Moving to a &lt;SPAN style="font-family: courier new,courier;"&gt;defaultdict&lt;/SPAN&gt; instead of a regular dictionary allows the original code to be simplified some.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;from collections import defaultdict
myTable = r"C:\test.gdb\my_table"
summaryDict = defaultdict(float)
searchRows = arcpy.da.SearchCursor(myTable, ["YEAR","ACRES"])
for yearValue, acresValue in searchRows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; summaryDict[yearValue] += acresValue 
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
#Print some output&amp;nbsp; 
for yearValue in sorted(summaryDict):&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; print str(yearValue) + " = " + str(summaryDict[yearValue] + summaryDict[yearValue - 1]) + " acres"&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:51:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cumulative-sum-by-year/m-p/471312#M36782</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-11T20:51:38Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum by year?</title>
      <link>https://community.esri.com/t5/python-questions/cumulative-sum-by-year/m-p/471313#M36783</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think the way you have written the last part does not accumulated the values from the first key of the dictionary to the last. It only seems to add the current and prior year, not the current and all prior years. I think the last part needs a variable outside the loop to accumulate the summary values for each successive sorted year as shown below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&lt;SPAN class="comment" style="font-weight: inherit; font-style: inherit; color: #008200; font-size: 9pt !important; background-color: inherit;"&gt;#Print some output&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;
&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&lt;SPAN class="comment" style="font-weight: inherit; font-style: inherit; color: #008200; font-size: 9pt !important; background-color: inherit;"&gt;cum = 0&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&lt;SPAN class="keyword" style="font-weight: inherit; font-style: inherit; color: #006699; font-size: 9pt !important; background-color: inherit;"&gt;for&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt; yearValue &lt;/SPAN&gt;&lt;SPAN class="keyword" style="font-weight: inherit; font-style: inherit; color: #006699; font-size: 9pt !important; background-color: inherit;"&gt;in&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt; sorted(summaryDict):&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;SPAN style="background-color: inherit; color: black; font-weight: inherit; font-size: 9pt !important; font-style: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #000000; font-style: inherit; font-weight: inherit; font-size: 9pt !important;"&gt;cum += &lt;/SPAN&gt;&lt;SPAN style="color: #000000; font-style: inherit; font-weight: inherit; font-size: 9pt !important;"&gt;summaryDict[yearValue]&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;
&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword" style="font-weight: inherit; font-style: inherit; color: #006699; font-size: 9pt !important; background-color: inherit;"&gt;print&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt; '{0} = {1} acres'.format(str(yearValue), str(cum&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;))&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: inherit; color: black; font-weight: inherit; font-size: 9pt !important; font-style: inherit;"&gt;This has the benefit of not needing to assume that each year key has a prior year value, which allows years to be skipped if the data did not have every year&amp;nbsp; (and the first year should throw an error with &lt;SPAN style="color: #000000; font-size: 12px;"&gt;Joshua's &lt;/SPAN&gt;code as shown since there is no prior year key in the dictionary for the first year, but it still needs to print).&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:51:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cumulative-sum-by-year/m-p/471313#M36783</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2021-12-11T20:51:41Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum by year?</title>
      <link>https://community.esri.com/t5/python-questions/cumulative-sum-by-year/m-p/471314#M36784</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/4811"&gt;Richard Fairhurst&lt;/A&gt;​, you are correct, my code is only summing a given year and its previous year because I believe that is what was asked:&amp;nbsp; "Is it possible to create a cumulative total of this so each previous year is added to the total of the following year?"&amp;nbsp; Although the word "cumulative" was used, I wasn't sure whether the intent was a running total over all years or a moving two-year total.&amp;nbsp; If the former, something like your code would be needed; if the latter, mine will work.&amp;nbsp; Maybe &lt;A href="https://community.esri.com/migrated-users/11835"&gt;Chris Snyder&lt;/A&gt;​ could clarify.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regarding my code, since I am using a &lt;SPAN style="font-family: courier new,courier;"&gt;defaultdict&lt;/SPAN&gt; instead of a regular dictionary, it will not err on summing the first year to a non-existent prior year.&amp;nbsp; Since the &lt;SPAN style="font-family: courier new,courier;"&gt;defaultdict&lt;/SPAN&gt; is initialized with &lt;SPAN style="font-family: courier new,courier;"&gt;float&lt;/SPAN&gt;, any non-existent year will get created with a value of zero.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Jul 2016 01:14:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cumulative-sum-by-year/m-p/471314#M36784</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2016-07-06T01:14:09Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum by year?</title>
      <link>https://community.esri.com/t5/python-questions/cumulative-sum-by-year/m-p/1358418#M69362</link>
      <description>&lt;P&gt;Thanks&amp;nbsp; a lot for the tip. It worked for me. Easy and neat.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2023 04:37:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/cumulative-sum-by-year/m-p/1358418#M69362</guid>
      <dc:creator>MinhazulIslam919</dc:creator>
      <dc:date>2023-12-08T04:37:21Z</dc:date>
    </item>
  </channel>
</rss>

