<?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 Using Get Count to get a percentage and Add Message in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/using-get-count-to-get-a-percentage-and-add/m-p/1026332#M59932</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am writing a script from an existing workflow to automate a recurring QC for floodplain data. In the workflow, you need to get the number of passing test points and divide by the total number of points. I am attempting to do this using arcpy.GetCount_management() for the passing points and dividing by the same function for the total number of points.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been successful at getting the function to work and return a print string of the number of results (i.e. "Lyr has 8373 Passing Results"), but I have not been able to perform the division of the two results to get the percentage. Am I missing something? Or is there a better way to go about this? I am relatively new to scripting.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Fri, 12 Feb 2021 16:17:38 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2021-02-12T16:17:38Z</dc:date>
    <item>
      <title>Using Get Count to get a percentage and Add Message</title>
      <link>https://community.esri.com/t5/python-questions/using-get-count-to-get-a-percentage-and-add/m-p/1026332#M59932</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am writing a script from an existing workflow to automate a recurring QC for floodplain data. In the workflow, you need to get the number of passing test points and divide by the total number of points. I am attempting to do this using arcpy.GetCount_management() for the passing points and dividing by the same function for the total number of points.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been successful at getting the function to work and return a print string of the number of results (i.e. "Lyr has 8373 Passing Results"), but I have not been able to perform the division of the two results to get the percentage. Am I missing something? Or is there a better way to go about this? I am relatively new to scripting.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 12 Feb 2021 16:17:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-get-count-to-get-a-percentage-and-add/m-p/1026332#M59932</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-02-12T16:17:38Z</dc:date>
    </item>
    <item>
      <title>Re: Using Get Count to get a percentage and Add Message</title>
      <link>https://community.esri.com/t5/python-questions/using-get-count-to-get-a-percentage-and-add/m-p/1026334#M59933</link>
      <description>&lt;P&gt;It would help seeing the code to see what your expression is but for the sake of throwing darts, are you casting the values to int's before dividing?&lt;/P&gt;</description>
      <pubDate>Fri, 12 Feb 2021 16:21:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-get-count-to-get-a-percentage-and-add/m-p/1026334#M59933</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-02-12T16:21:08Z</dc:date>
    </item>
    <item>
      <title>Re: Using Get Count to get a percentage and Add Message</title>
      <link>https://community.esri.com/t5/python-questions/using-get-count-to-get-a-percentage-and-add/m-p/1026335#M59934</link>
      <description>&lt;P&gt;Can you share the script? Do you have an error message?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Feb 2021 16:24:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-get-count-to-get-a-percentage-and-add/m-p/1026335#M59934</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-02-12T16:24:16Z</dc:date>
    </item>
    <item>
      <title>Re: Using Get Count to get a percentage and Add Message</title>
      <link>https://community.esri.com/t5/python-questions/using-get-count-to-get-a-percentage-and-add/m-p/1026337#M59935</link>
      <description>&lt;P&gt;Here is a sample of the code (using ArcPro) for selecting passing points and getting the count. I have tried to cast the output as an integer but I get this error:&lt;/P&gt;&lt;P&gt;arcpy.management.SelectLayerByAttribute(test_pts, 'NEW_SELECTION',"Status = 'Pass'", 'NON_INVERT')&lt;BR /&gt;passct = int(arcpy.GetCount_management(test_pts).getOutput(0))&lt;BR /&gt;print('{} has {} Passing records'.format(test_pts, passct[0]))&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;BR /&gt;File "&amp;lt;string&amp;gt;", line 2, in &amp;lt;module&amp;gt;&lt;BR /&gt;TypeError: 'int' object is not subscriptable&lt;/P&gt;</description>
      <pubDate>Fri, 12 Feb 2021 16:26:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-get-count-to-get-a-percentage-and-add/m-p/1026337#M59935</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-02-12T16:26:54Z</dc:date>
    </item>
    <item>
      <title>Re: Using Get Count to get a percentage and Add Message</title>
      <link>https://community.esri.com/t5/python-questions/using-get-count-to-get-a-percentage-and-add/m-p/1026339#M59936</link>
      <description>&lt;P&gt;Here is a sample of the code (using ArcPro) for selecting passing points and getting the count. I have tried to cast the output as an integer but I get this error:&lt;/P&gt;&lt;P&gt;arcpy.management.SelectLayerByAttribute(test_pts, 'NEW_SELECTION',"Status = 'Pass'", 'NON_INVERT')&lt;BR /&gt;passct = int(arcpy.GetCount_management(test_pts).getOutput(0))&lt;BR /&gt;print('{} has {} Passing records'.format(test_pts, passct[0]))&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;BR /&gt;File "&amp;lt;string&amp;gt;", line 2, in &amp;lt;module&amp;gt;&lt;BR /&gt;TypeError: 'int' object is not subscriptable&lt;/P&gt;</description>
      <pubDate>Fri, 12 Feb 2021 16:28:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-get-count-to-get-a-percentage-and-add/m-p/1026339#M59936</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-02-12T16:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: Using Get Count to get a percentage and Add Message</title>
      <link>https://community.esri.com/t5/python-questions/using-get-count-to-get-a-percentage-and-add/m-p/1026344#M59937</link>
      <description>&lt;P&gt;in your print statement you are trying to index the int passct[0].&amp;nbsp; Although, you might not be able to cast like that if I remember correctly.&lt;/P&gt;&lt;P&gt;Try it like this:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;result = arcpy.GetCount_management(fc)
val = int(result.getOutput(0))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Feb 2021 16:50:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-get-count-to-get-a-percentage-and-add/m-p/1026344#M59937</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-02-12T16:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: Using Get Count to get a percentage and Add Message</title>
      <link>https://community.esri.com/t5/python-questions/using-get-count-to-get-a-percentage-and-add/m-p/1026345#M59938</link>
      <description>&lt;P&gt;.format isn't working since passct is int type.&lt;/P&gt;&lt;P&gt;for it to run get rid of the int type conversion int():&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;passct = (arcpy.GetCount_management(test_pts).getOutput(0))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;when you want to do any division, ensure both numbers are of the int type - you can test this with print(type(passct))&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#passct is a string
passct_string = (arcpy.GetCount_management(test_pts).getOutput(0))
#passct is an int
passct_int = int(arcpy.GetCount_management(test_pts).getOutput(0))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Feb 2021 16:50:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-get-count-to-get-a-percentage-and-add/m-p/1026345#M59938</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-02-12T16:50:53Z</dc:date>
    </item>
    <item>
      <title>Re: Using Get Count to get a percentage and Add Message</title>
      <link>https://community.esri.com/t5/python-questions/using-get-count-to-get-a-percentage-and-add/m-p/1026355#M59939</link>
      <description>&lt;P&gt;Then of course one could read the help and see examples for "immediate" mode and in code.&amp;nbsp; This way you can ensure that your inputs are correct and check to see the data type that it returns to see whether casting is needed to get a numeric type&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/get-count.htm" target="_blank"&gt;Get Count (Data Management)—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Feb 2021 16:57:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-get-count-to-get-a-percentage-and-add/m-p/1026355#M59939</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-02-12T16:57:06Z</dc:date>
    </item>
    <item>
      <title>Re: Using Get Count to get a percentage and Add Message</title>
      <link>https://community.esri.com/t5/python-questions/using-get-count-to-get-a-percentage-and-add/m-p/1026362#M59940</link>
      <description>&lt;P&gt;Thanks for the clarification. I was using the print and .format to view the result but did not know that the integer would not allow this. I was able to do the division after converting the string to int. Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 12 Feb 2021 17:10:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-get-count-to-get-a-percentage-and-add/m-p/1026362#M59940</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-02-12T17:10:20Z</dc:date>
    </item>
    <item>
      <title>Re: Using Get Count to get a percentage and Add Message</title>
      <link>https://community.esri.com/t5/python-questions/using-get-count-to-get-a-percentage-and-add/m-p/1026372#M59941</link>
      <description>&lt;P&gt;Also just note that integer division won't always work as you expect depending on your Python version.&amp;nbsp; I think you're using ArcGIS Pro so you should be fine. e.g. 1/2 = 0.5 in the Pro Python window, but returns 0 in Python 2.7.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Feb 2021 17:21:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-get-count-to-get-a-percentage-and-add/m-p/1026372#M59941</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-02-12T17:21:44Z</dc:date>
    </item>
  </channel>
</rss>

