<?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: Count of fields in a row that satisfy a query in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/count-of-fields-in-a-row-that-satisfy-a-query/m-p/562547#M43993</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the link, adding to my bookmarks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 27 Jan 2017 23:16:20 GMT</pubDate>
    <dc:creator>IanMurray</dc:creator>
    <dc:date>2017-01-27T23:16:20Z</dc:date>
    <item>
      <title>Count of fields in a row that satisfy a query</title>
      <link>https://community.esri.com/t5/python-questions/count-of-fields-in-a-row-that-satisfy-a-query/m-p/562544#M43990</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am wanting to calculate the count of fields in a row where designated fields in a feature class attribute table satisfy a query (in this case, where the value is greater than 0) and then write the count (sum) of the number of fields that satisfy this query into a new field.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This seems simple, but I am having a hard time wrapping my head around how to do this using SQL or Python. Any suggestions or advice would be much appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Jan 2017 22:50:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/count-of-fields-in-a-row-that-satisfy-a-query/m-p/562544#M43990</guid>
      <dc:creator>TessOldemeyer</dc:creator>
      <dc:date>2017-01-27T22:50:02Z</dc:date>
    </item>
    <item>
      <title>Re: Count of fields in a row that satisfy a query</title>
      <link>https://community.esri.com/t5/python-questions/count-of-fields-in-a-row-that-satisfy-a-query/m-p/562545#M43991</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have you looked at using cursors to pull the values of each value of each field you need in a row to check see if it is greater than 0?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/arcpy/data-access/updatecursor-class.htm"&gt;https://pro.arcgis.com/en/pro-app/arcpy/data-access/updatecursor-class.htm&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Jan 2017 23:07:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/count-of-fields-in-a-row-that-satisfy-a-query/m-p/562545#M43991</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2017-01-27T23:07:52Z</dc:date>
    </item>
    <item>
      <title>Re: Count of fields in a row that satisfy a query</title>
      <link>https://community.esri.com/t5/python-questions/count-of-fields-in-a-row-that-satisfy-a-query/m-p/562546#M43992</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In Python, &lt;A href="https://community.esri.com/migrated-users/3420"&gt;Joshua Bixby&lt;/A&gt;‌ covers the options in &lt;A _jive_internal="true" href="https://community.esri.com/blogs/tilting/2016/02/02/the-iterable-cursor-python-built-ins-itertools"&gt;this blog post&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;In SQL, you can do something like&lt;/P&gt;&lt;PRE class="line-numbers language-sql"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;select&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;count&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;*&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; TableName &lt;SPAN class="keyword token"&gt;where&lt;/SPAN&gt; FieldName &lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EDIT:&lt;/P&gt;&lt;P&gt;Just to clarify your question, I will edit it for what I think you meant to say...&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;SPAN style="background-color: #ffffff;"&gt;I am wanting to calculate the count of &lt;STRONG&gt;rows&lt;/STRONG&gt;&amp;nbsp;in a &lt;STRONG&gt;field&lt;/STRONG&gt;&amp;nbsp;where designated fields in a feature class attribute table satisfy a query (in this case, where the value is greater than 0) and then write the count (sum) of the number of &lt;STRONG&gt;rows&lt;/STRONG&gt;&amp;nbsp;that satisfy this query into a new field.&lt;/SPAN&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Jan 2017 23:11:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/count-of-fields-in-a-row-that-satisfy-a-query/m-p/562546#M43992</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2017-01-27T23:11:11Z</dc:date>
    </item>
    <item>
      <title>Re: Count of fields in a row that satisfy a query</title>
      <link>https://community.esri.com/t5/python-questions/count-of-fields-in-a-row-that-satisfy-a-query/m-p/562547#M43993</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the link, adding to my bookmarks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Jan 2017 23:16:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/count-of-fields-in-a-row-that-satisfy-a-query/m-p/562547#M43993</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2017-01-27T23:16:20Z</dc:date>
    </item>
    <item>
      <title>Re: Count of fields in a row that satisfy a query</title>
      <link>https://community.esri.com/t5/python-questions/count-of-fields-in-a-row-that-satisfy-a-query/m-p/562548#M43994</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Nope, I meant the&amp;nbsp;&lt;SPAN style="background-color: #ffffff;"&gt;count of fields per row (per feature) where designated fields satisfy a query. Here I am looking for the the count of fields (this would only pertain to&amp;nbsp;5 of the 40&amp;nbsp;fields in the feature class) which have a value greater than zero. I would also then like to write the count (sum) of the number of fields that satisfy this query into a new field, so this new field would have a count of 0 (or NULL) or an integer from 1 to 5.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;Does this help? I apologize for the lack of clarity. Thanks for the help!&amp;nbsp;&lt;SPAN&gt;I would also like to eventually integrate this into a Python script (eventually).&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Jan 2017 23:34:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/count-of-fields-in-a-row-that-satisfy-a-query/m-p/562548#M43994</guid>
      <dc:creator>TessOldemeyer</dc:creator>
      <dc:date>2017-01-27T23:34:04Z</dc:date>
    </item>
    <item>
      <title>Re: Count of fields in a row that satisfy a query</title>
      <link>https://community.esri.com/t5/python-questions/count-of-fields-in-a-row-that-satisfy-a-query/m-p/562549#M43995</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Some sample data would help. I think I understand but it is a very unusual request and I want to make sure.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 28 Jan 2017 00:03:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/count-of-fields-in-a-row-that-satisfy-a-query/m-p/562549#M43995</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2017-01-28T00:03:32Z</dc:date>
    </item>
    <item>
      <title>Re: Count of fields in a row that satisfy a query</title>
      <link>https://community.esri.com/t5/python-questions/count-of-fields-in-a-row-that-satisfy-a-query/m-p/562550#M43996</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could use the field calculator and something like:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;def&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;FieldCount&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;fld1&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;fld2&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp; fields &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;fld1&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; fld2&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# field values to list&lt;/SPAN&gt;
&amp;nbsp; &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; sum&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;f &lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; f &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; fields&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

FieldCount&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt; !F01!&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; !F02!&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Or this for the function:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;def&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;FieldCount&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;fld1&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;fld2&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; sum&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;v &lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; k&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; v &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; locals&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;iteritems&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also look at &lt;A href="https://community.esri.com/migrated-users/3420" target="_blank"&gt;Joshua Bixby&lt;/A&gt;‌'s answer in &lt;A _jive_internal="true" href="https://community.esri.com/thread/180648" target="_blank"&gt;this thread&lt;/A&gt;.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:15:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/count-of-fields-in-a-row-that-satisfy-a-query/m-p/562550#M43996</guid>
      <dc:creator>RandyBurton</dc:creator>
      <dc:date>2021-12-12T00:15:36Z</dc:date>
    </item>
    <item>
      <title>Re: Count of fields in a row that satisfy a query</title>
      <link>https://community.esri.com/t5/python-questions/count-of-fields-in-a-row-that-satisfy-a-query/m-p/562551#M43997</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you so much. This is exactly what I was looking for! Works great!&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Jan 2017 23:50:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/count-of-fields-in-a-row-that-satisfy-a-query/m-p/562551#M43997</guid>
      <dc:creator>TessOldemeyer</dc:creator>
      <dc:date>2017-01-30T23:50:22Z</dc:date>
    </item>
    <item>
      <title>Re: Count of fields in a row that satisfy a query</title>
      <link>https://community.esri.com/t5/python-questions/count-of-fields-in-a-row-that-satisfy-a-query/m-p/562552#M43998</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I &amp;nbsp;was looking to get the sum of the number of particular fields in a row that had a value greater than zero (to find how many of these unique attributes each feature had, e.g. ). I think Randy hit on exactly what I was looking for. Thanks a bunch!&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Jan 2017 18:22:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/count-of-fields-in-a-row-that-satisfy-a-query/m-p/562552#M43998</guid>
      <dc:creator>TessOldemeyer</dc:creator>
      <dc:date>2017-01-31T18:22:01Z</dc:date>
    </item>
  </channel>
</rss>

