<?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: How to create a syntax that will replace the same values in different fields in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-create-a-syntax-that-will-replace-the-same/m-p/754360#M58177</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Since you mentioned the field calculator, does that mean you have no issus doing this in ArcMap, or do you need code?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If so, in ArcMap, load the FC, right-click and select open attribute table.&amp;nbsp; then, in the upper left of the table, under the drop down arrow, you will see Find and Replace.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This will let you find a value and replace with another in all or just selected columns.&amp;nbsp; Should be what you want unless you are after code.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 01 Jul 2013 17:59:16 GMT</pubDate>
    <dc:creator>RhettZufelt</dc:creator>
    <dc:date>2013-07-01T17:59:16Z</dc:date>
    <item>
      <title>How to create a syntax that will replace the same values in different fields</title>
      <link>https://community.esri.com/t5/python-questions/how-to-create-a-syntax-that-will-replace-the-same/m-p/754358#M58175</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am not familiar with Python programming and would appreciate your assitance.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Basically, I have an attribute table of more than 150,000 records and several fields. In 6 of the fields I need to replace a code (or recode) some values for something else. If I use the field calculator I will have to go through each of those fields and would be too cumbersome and tedious. I have the feeling that there is a way to do this simultaneously for all fields but I am not sure how to create the syntax.&amp;nbsp; I have a few failed trials of comin up with that syntax based on what I have been reading on internet but I am missing something. Any thoughts?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jay&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt; import arcpy &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;... import os&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;... &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;...&amp;nbsp; !RUseCode02!.replace("999", "9999"), !RUseCode03!.replace("999", "9999"),!RUseCode04!.replace("999", "9999"),&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;run&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 29 Jun 2013 16:00:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-create-a-syntax-that-will-replace-the-same/m-p/754358#M58175</guid>
      <dc:creator>JayMata</dc:creator>
      <dc:date>2013-06-29T16:00:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a syntax that will replace the same values in different fields</title>
      <link>https://community.esri.com/t5/python-questions/how-to-create-a-syntax-that-will-replace-the-same/m-p/754359#M58176</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You can either do this using the field calculator, or an update cursor.&amp;nbsp; Are the RUseCode values a text string or are they integers? If they are numbers, you will not need the quotes around the find or replace values.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Field Calculator:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Pre-logic&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
def Replace( field, find, replace ):
&amp;nbsp; if field != find:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return field
&amp;nbsp; elif field == find:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return replace
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Expression&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
Replace( !RUseCode04!, "999", "9999")
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]25605[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Or you could try and use an update cursor to do it all at once.&amp;nbsp; You can just put all of your fields you want to do this to in the "fields" list.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy

fc = r'C:\path\to_your\feature_class'
fields = ['RUseCode02', 'RUseCode03', 'RUseCode04']
rows = arcpy.UpdateCursor(fc)
for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for field in fields:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if row.getValue(field) == '999':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue(field, '9999')
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)
del row, rows
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think your original code should have worked by the way...Did you set the parser to Python first and supply those expressions one at a time?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 08:00:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-create-a-syntax-that-will-replace-the-same/m-p/754359#M58176</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-12T08:00:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a syntax that will replace the same values in different fields</title>
      <link>https://community.esri.com/t5/python-questions/how-to-create-a-syntax-that-will-replace-the-same/m-p/754360#M58177</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Since you mentioned the field calculator, does that mean you have no issus doing this in ArcMap, or do you need code?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If so, in ArcMap, load the FC, right-click and select open attribute table.&amp;nbsp; then, in the upper left of the table, under the drop down arrow, you will see Find and Replace.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This will let you find a value and replace with another in all or just selected columns.&amp;nbsp; Should be what you want unless you are after code.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Jul 2013 17:59:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-create-a-syntax-that-will-replace-the-same/m-p/754360#M58177</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2013-07-01T17:59:16Z</dc:date>
    </item>
  </channel>
</rss>

