<?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>idea Calculate statistics for selected features and pass to a variable in Python Ideas</title>
    <link>https://community.esri.com/t5/python-ideas/calculate-statistics-for-selected-features-and/idi-p/1060419</link>
    <description>&lt;P&gt;The analysis.Statistics tool calculates statistics for selected rows but puts the value in a CSV table. I want to be able to calculate the sum of values in a field for selected rows and then use the sum elsewhere in my Python Script.&lt;/P&gt;</description>
    <pubDate>Fri, 21 May 2021 14:15:20 GMT</pubDate>
    <dc:creator>d484648</dc:creator>
    <dc:date>2021-05-21T14:15:20Z</dc:date>
    <item>
      <title>Calculate statistics for selected features and pass to a variable</title>
      <link>https://community.esri.com/t5/python-ideas/calculate-statistics-for-selected-features-and/idi-p/1060419</link>
      <description>&lt;P&gt;The analysis.Statistics tool calculates statistics for selected rows but puts the value in a CSV table. I want to be able to calculate the sum of values in a field for selected rows and then use the sum elsewhere in my Python Script.&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2021 14:15:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-ideas/calculate-statistics-for-selected-features-and/idi-p/1060419</guid>
      <dc:creator>d484648</dc:creator>
      <dc:date>2021-05-21T14:15:20Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate statistics for selected features and pass to a variable</title>
      <link>https://community.esri.com/t5/python-ideas/calculate-statistics-for-selected-features-and/idc-p/1065136#M46</link>
      <description>&lt;P&gt;Just use a searchcursor if you want to read values from a selection, or you could call the summary statistics tool.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 14:55:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-ideas/calculate-statistics-for-selected-features-and/idc-p/1065136#M46</guid>
      <dc:creator>DuncanHornby</dc:creator>
      <dc:date>2021-06-04T14:55:28Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate statistics for selected features and pass to a variable</title>
      <link>https://community.esri.com/t5/python-ideas/calculate-statistics-for-selected-features-and/idc-p/1065182#M47</link>
      <description>&lt;P&gt;Thanks for the reply.&lt;/P&gt;&lt;P&gt;The summary statistics tool generates a CSV file for each sum. I don't need that.&lt;/P&gt;&lt;P&gt;I'll have to look up how to read and create a running sum of values from a selection using a searchcursor.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Jun 2021 16:30:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-ideas/calculate-statistics-for-selected-features-and/idc-p/1065182#M47</guid>
      <dc:creator>d484648</dc:creator>
      <dc:date>2021-06-04T16:30:05Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate statistics for selected features and pass to a variable</title>
      <link>https://community.esri.com/t5/python-ideas/calculate-statistics-for-selected-features-and/idc-p/1170539#M109</link>
      <description>&lt;P&gt;Wrap the summary statistics in a function.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def calculate_field_statistics(in_table, field, statistics_type='SUM'):
    """ Run the Summary Statistics on a field in a table and return the result."""
    try:
        # Create the temporary stats result table
        stats_table = arcpy.CreateUniqueName('stats', 'in_memory')
        # The output field is statistics_type underscore field name
        stats_field = "{}_{}".format(statistics_type, field)
        # Run Summary Statistic
        arcpy.analysis.Statistics(in_table, stats_table, [[field, statistics_type]])
        # Return the first value from the stats_table
        return arcpy.da.SearchCursor(stats_table, stats_field).next()[0]
    finally:
        # Delete the stats table
        if arcpy.Exists(stats_table):
            arcpy.management.Delete(stats_table)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2022 10:41:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-ideas/calculate-statistics-for-selected-features-and/idc-p/1170539#M109</guid>
      <dc:creator>MarkBryant</dc:creator>
      <dc:date>2022-05-04T10:41:12Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate statistics for selected features and pass to a variable</title>
      <link>https://community.esri.com/t5/python-ideas/calculate-statistics-for-selected-features-and/idc-p/1170559#M110</link>
      <description>&lt;P&gt;This is great, thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2022 12:33:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-ideas/calculate-statistics-for-selected-features-and/idc-p/1170559#M110</guid>
      <dc:creator>d484648</dc:creator>
      <dc:date>2022-05-04T12:33:53Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate statistics for selected features and pass to a variable - Status changed to: Closed</title>
      <link>https://community.esri.com/t5/python-ideas/calculate-statistics-for-selected-features-and/idc-p/1201051#M135</link>
      <description>&lt;P&gt;Thanks for your idea! Based on the comments in this thread, it looks like this issue is addressable with a moderate amount of Python code directly using ArcPy, and is also possible using mechanisms like SeDF or plain pandas for performing the summarization. Based on that, will close this issue because the specific need can be addressed without a new specialized tool to solve it. Let us know if see any other areas that Python in ArcGIS can use enhancement.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Aug 2022 20:22:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-ideas/calculate-statistics-for-selected-features-and/idc-p/1201051#M135</guid>
      <dc:creator>ShaunWalbridge</dc:creator>
      <dc:date>2022-08-09T20:22:56Z</dc:date>
    </item>
  </channel>
</rss>

