<?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 Need help with python script to compare two fields. in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/need-help-with-python-script-to-compare-two-fields/m-p/1523036#M87110</link>
    <description>&lt;P&gt;I am trying to compare two fields in my attribute table. I did a spatial join with a point feature and the closest address. Not all of the addresses matched up correctly so for the point features that have address data, I want to compare just the numbers in that field to another field where I separated the number from the address that was joined. I need to locate all the numbers that do not match up. I am not very experienced with python, so I am trying to use copilot to generate something. Here is what it is giving me:&lt;/P&gt;&lt;P&gt;import re&lt;/P&gt;&lt;P&gt;def compare_fields(Add_Number, LocationDescription):&lt;BR /&gt;# Extract numbers from the LocationDescription field&lt;BR /&gt;address_numbers = re.findall(r'\d+', LocationDescription)&lt;BR /&gt;&lt;BR /&gt;# Convert the extracted numbers to a single string for comparison&lt;BR /&gt;address_number_str = ''.join(address_numbers)&lt;BR /&gt;&lt;BR /&gt;# Compare the Add_Number field with the extracted address numbers&lt;BR /&gt;if str(Add_Number) == address_number_str:&lt;BR /&gt;return "Match"&lt;BR /&gt;else:&lt;BR /&gt;return "No Match"&lt;/P&gt;&lt;P&gt;I am putting this script in the field calculator for a field where I want Match and No Match to be stored. It needs to compare the two fields LocationDescription (This is the script with the full address. These addresses are all in different formats. Some have the number at the end or contain underscores) and Add_Number (just the numbers for the joined address). I also tried a script that would extract the numbers only from LocationDescription because I thought it would be easier to compare if both fields were just numbers, but it also did not work. Does anyone have any idea what I am missing with this? This would help me a ton if someone could help me out otherwise, I will have to manually go through over 15,000 records.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 16 Aug 2024 18:25:09 GMT</pubDate>
    <dc:creator>EGardner7</dc:creator>
    <dc:date>2024-08-16T18:25:09Z</dc:date>
    <item>
      <title>Need help with python script to compare two fields.</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/need-help-with-python-script-to-compare-two-fields/m-p/1523036#M87110</link>
      <description>&lt;P&gt;I am trying to compare two fields in my attribute table. I did a spatial join with a point feature and the closest address. Not all of the addresses matched up correctly so for the point features that have address data, I want to compare just the numbers in that field to another field where I separated the number from the address that was joined. I need to locate all the numbers that do not match up. I am not very experienced with python, so I am trying to use copilot to generate something. Here is what it is giving me:&lt;/P&gt;&lt;P&gt;import re&lt;/P&gt;&lt;P&gt;def compare_fields(Add_Number, LocationDescription):&lt;BR /&gt;# Extract numbers from the LocationDescription field&lt;BR /&gt;address_numbers = re.findall(r'\d+', LocationDescription)&lt;BR /&gt;&lt;BR /&gt;# Convert the extracted numbers to a single string for comparison&lt;BR /&gt;address_number_str = ''.join(address_numbers)&lt;BR /&gt;&lt;BR /&gt;# Compare the Add_Number field with the extracted address numbers&lt;BR /&gt;if str(Add_Number) == address_number_str:&lt;BR /&gt;return "Match"&lt;BR /&gt;else:&lt;BR /&gt;return "No Match"&lt;/P&gt;&lt;P&gt;I am putting this script in the field calculator for a field where I want Match and No Match to be stored. It needs to compare the two fields LocationDescription (This is the script with the full address. These addresses are all in different formats. Some have the number at the end or contain underscores) and Add_Number (just the numbers for the joined address). I also tried a script that would extract the numbers only from LocationDescription because I thought it would be easier to compare if both fields were just numbers, but it also did not work. Does anyone have any idea what I am missing with this? This would help me a ton if someone could help me out otherwise, I will have to manually go through over 15,000 records.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Aug 2024 18:25:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/need-help-with-python-script-to-compare-two-fields/m-p/1523036#M87110</guid>
      <dc:creator>EGardner7</dc:creator>
      <dc:date>2024-08-16T18:25:09Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with python script to compare two fields.</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/need-help-with-python-script-to-compare-two-fields/m-p/1523078#M87117</link>
      <description>&lt;P&gt;The following may help but you may have to modify it as needed.&lt;/P&gt;&lt;P&gt;Btw start by removing import re&lt;/P&gt;&lt;P&gt;In Calculate Field&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;First create and populate address_number_str using Calculate Field. Note that in Calculate Field you can directly create this field and set data type to Text and under = select !address_numbers! to convert the values to text/string&lt;/LI&gt;&lt;LI&gt;Then Open Calculate Field again&lt;/LI&gt;&lt;LI&gt;select the new field let's call it NF&lt;/LI&gt;&lt;LI&gt;Then towards the middle where it says NF =&amp;nbsp; type reclass(!Add_Number!)&lt;/LI&gt;&lt;LI&gt;Then under code adapt the following, don't copy paste the following as it may have indentation errors and is just an idea&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;def reclass(Add_Number):

      if(str(Add_Number) == !Add_Number_str!):

           return "Match"

      else:

         return "No Match"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Aug 2024 19:35:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/need-help-with-python-script-to-compare-two-fields/m-p/1523078#M87117</guid>
      <dc:creator>Ed_</dc:creator>
      <dc:date>2024-08-16T19:35:04Z</dc:date>
    </item>
  </channel>
</rss>

