<?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: Find records with number/character that should not be there. in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/find-records-with-number-character-that-should-not/m-p/1281450#M67485</link>
    <description>&lt;P&gt;Hello!&amp;nbsp; I think this function will do what your looking for:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def mark_records(records):
    result = []
    for rec in records:
        # Check if the 9th character (index &lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt; is an alphabetic character
        if rec[8].isalpha() or rec[8].isspace():
            # Mark as ok
            result.append({"Rec": rec, "Mark": "ok"})
        elif rec[8].isdigit():
            # Mark as Not ok
            result.append({"Rec": rec, "Mark": "Not ok"})
        else:
            # If neither alphabetic nor digit nor space, mark as Invalid
            result.append({"Rec": rec, "Mark": "Invalid"})
    return result&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 21 Apr 2023 19:57:55 GMT</pubDate>
    <dc:creator>Jordan_Silver</dc:creator>
    <dc:date>2023-04-21T19:57:55Z</dc:date>
    <item>
      <title>Find records with number/character that should not be there.</title>
      <link>https://community.esri.com/t5/python-questions/find-records-with-number-character-that-should-not/m-p/1281430#M67483</link>
      <description>&lt;P&gt;I have a filed that I need to find records in a layer that have a number that should not be there. Not really sure on how to do this.&lt;/P&gt;&lt;P&gt;Rec field has length of 10. In the example below the first and fourth records has 0 in the 9th space (it could be a different digit) and some records will have an alph character in the 9th space, which is ok as long as it's an alph character. I would like to somehow mark the records.&amp;nbsp; Essentially, I need to find which records have a digit(skip if alph character is there) on the 9th space of the records. Hopefully this makes sense.&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="50%"&gt;&lt;P&gt;Rec&lt;/P&gt;&lt;/TD&gt;&lt;TD width="50%"&gt;&lt;P&gt;mark&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;12345678 0&lt;/TD&gt;&lt;TD width="50%"&gt;ok ( or 1)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;22345108A0&lt;/TD&gt;&lt;TD width="50%"&gt;ok ( or 0)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;6523148000&lt;/TD&gt;&lt;TD width="50%"&gt;Not ok ( or 0)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="50%"&gt;62315010 9&lt;/TD&gt;&lt;TD width="50%"&gt;Ok ( or 1)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6218921801&lt;/TD&gt;&lt;TD&gt;Not ok ( or 0)&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Fri, 21 Apr 2023 19:10:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/find-records-with-number-character-that-should-not/m-p/1281430#M67483</guid>
      <dc:creator>CCWeedcontrol</dc:creator>
      <dc:date>2023-04-21T19:10:08Z</dc:date>
    </item>
    <item>
      <title>Re: Find records with number/character that should not be there.</title>
      <link>https://community.esri.com/t5/python-questions/find-records-with-number-character-that-should-not/m-p/1281445#M67484</link>
      <description>&lt;P&gt;Using Field Calculator in the attribute table&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/help/data/tables/fundamentals-of-field-calculations.htm" target="_blank"&gt;https://pro.arcgis.com/en/pro-app/latest/help/data/tables/fundamentals-of-field-calculations.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;or GP tool&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/calculate-field.htm" target="_blank"&gt;https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/calculate-field.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Calculate into the new field you've created for this i.e. 'mark'.&lt;/P&gt;&lt;P&gt;Expression type = Python 3&lt;/P&gt;&lt;P&gt;enter this in the box below "="&amp;nbsp;&lt;/P&gt;&lt;P&gt;digitron(!tableName.rec or whatever your field is called - double click on the fields window to auto add the field!)&lt;/P&gt;&lt;P&gt;enter this in the 'Code Block' window:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def digitron(rec):
  try:
    if rec[8].isnumeric():
      return 'Not OK'
    else:
      return 'OK'
  except:
    return 'Some error'&lt;/LI-CODE&gt;&lt;P&gt;validate then apply&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 19:51:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/find-records-with-number-character-that-should-not/m-p/1281445#M67484</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2023-04-21T19:51:57Z</dc:date>
    </item>
    <item>
      <title>Re: Find records with number/character that should not be there.</title>
      <link>https://community.esri.com/t5/python-questions/find-records-with-number-character-that-should-not/m-p/1281450#M67485</link>
      <description>&lt;P&gt;Hello!&amp;nbsp; I think this function will do what your looking for:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def mark_records(records):
    result = []
    for rec in records:
        # Check if the 9th character (index &lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt; is an alphabetic character
        if rec[8].isalpha() or rec[8].isspace():
            # Mark as ok
            result.append({"Rec": rec, "Mark": "ok"})
        elif rec[8].isdigit():
            # Mark as Not ok
            result.append({"Rec": rec, "Mark": "Not ok"})
        else:
            # If neither alphabetic nor digit nor space, mark as Invalid
            result.append({"Rec": rec, "Mark": "Invalid"})
    return result&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 19:57:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/find-records-with-number-character-that-should-not/m-p/1281450#M67485</guid>
      <dc:creator>Jordan_Silver</dc:creator>
      <dc:date>2023-04-21T19:57:55Z</dc:date>
    </item>
    <item>
      <title>Re: Find records with number/character that should not be there.</title>
      <link>https://community.esri.com/t5/python-questions/find-records-with-number-character-that-should-not/m-p/1281502#M67486</link>
      <description>&lt;P&gt;This worked in Arcmap, but how can run it outside.&lt;/P&gt;&lt;P&gt;I tired the following but I get "Parameters are not valid." or with updatecursor?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;import arcpy

inTable = "fc"
fieldName = "rec"
expression = "digitron(rec)"

codeblock = """
def digitron(rec):
  try:
    if rec[8].isnumeric():
      return 'Not OK'
    else:
      return 'OK'
  except:
    return 'Some error' """

arcpy.management.CalculateField(inTable, fieldName, expression, "PYTHON3", codeblock)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 21:58:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/find-records-with-number-character-that-should-not/m-p/1281502#M67486</guid>
      <dc:creator>CCWeedcontrol</dc:creator>
      <dc:date>2023-04-21T21:58:30Z</dc:date>
    </item>
    <item>
      <title>Re: Find records with number/character that should not be there.</title>
      <link>https://community.esri.com/t5/python-questions/find-records-with-number-character-that-should-not/m-p/1281508#M67487</link>
      <description>&lt;LI-CODE lang="python"&gt;import arcpy

in_table = "fc"
field_names = ["rec", "mark?"]

with arcpy.da.UpdateCursor(in_table, field_names) as cursor:
    for row in cursor:
        try:
            if (row[0])[8].isnumeric():
                row[1] = 'Not OK'
            else :
                row[1] = 'OK'
        except:
            row[1] = 'Some error'
        cursor.updateRow(row) &lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 21 Apr 2023 22:09:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/find-records-with-number-character-that-should-not/m-p/1281508#M67487</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2023-04-21T22:09:01Z</dc:date>
    </item>
    <item>
      <title>Re: Find records with number/character that should not be there.</title>
      <link>https://community.esri.com/t5/python-questions/find-records-with-number-character-that-should-not/m-p/1281840#M67500</link>
      <description>&lt;P&gt;oh I see, line 9&amp;nbsp; (row[0])[8].isnumeric.&lt;/P&gt;&lt;P&gt;Thanks for the help.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 14:24:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/find-records-with-number-character-that-should-not/m-p/1281840#M67500</guid>
      <dc:creator>CCWeedcontrol</dc:creator>
      <dc:date>2023-04-24T14:24:56Z</dc:date>
    </item>
    <item>
      <title>Re: Find records with number/character that should not be there.</title>
      <link>https://community.esri.com/t5/python-questions/find-records-with-number-character-that-should-not/m-p/1281843#M67502</link>
      <description>&lt;P&gt;I tried you function but I couldn't get it to work right.&lt;/P&gt;&lt;P&gt;pre-logic script code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;def mark_records(records):
    result = []
    for rec in records:
        # Check if the 9th character (index  is an alphabetic character
        if rec[8].isalpha() or rec[8].isspace():
            # Mark as ok
            result.append({"Rec": rec, "Mark": "ok"})
        elif rec[8].isdigit():
            # Mark as Not ok
            result.append({"Rec": rec, "Mark": "Not ok"})
        else:
            # If neither alphabetic nor digit nor space, mark as Invalid
            result.append({"Rec": rec, "Mark": "Invalid"})
    return result&lt;/LI-CODE&gt;&lt;P&gt;Field = (!rec!)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 14:29:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/find-records-with-number-character-that-should-not/m-p/1281843#M67502</guid>
      <dc:creator>CCWeedcontrol</dc:creator>
      <dc:date>2023-04-24T14:29:02Z</dc:date>
    </item>
  </channel>
</rss>

