<?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: Conditional replace function in Field Calculator in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/conditional-replace-function-in-field-calculator/m-p/345317#M27117</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Also be mindful of indentation. My earlier post didn't show correct indentation after the if statement. Apologies for that.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 20 Jun 2012 19:53:06 GMT</pubDate>
    <dc:creator>JimCousins</dc:creator>
    <dc:date>2012-06-20T19:53:06Z</dc:date>
    <item>
      <title>Conditional replace function in Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/conditional-replace-function-in-field-calculator/m-p/345313#M27113</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm trying to write an expression that will allow me to change the text of a string field based on it's values.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's what I have so far.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;----&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim output as String&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;IF [DUPLICATE] = "0"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;THEN &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;output = replace( [DUPLICATE], "0", "CATEGORY 1")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;end if&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;IF [DUPLICATE] = "1"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;THEN &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;output = replace( [DUPLICATE], "1", "CATEGORY 2")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;end if&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;IF [DUPLICATE] = "2"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;THEN &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;output = replace( [DUPLICATE], "2", "CATEGORY 3")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;end&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;----&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help would be appreciated.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Jun 2012 12:11:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/conditional-replace-function-in-field-calculator/m-p/345313#M27113</guid>
      <dc:creator>BenjaminYoung</dc:creator>
      <dc:date>2012-06-20T12:11:23Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional replace function in Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/conditional-replace-function-in-field-calculator/m-p/345314#M27114</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;A single "=" is an assignment. In order to do a comparison, use "==" a double equal sign. You could also nest these individual if statements with:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if [DUPLICATE] == "0":&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; output = replace( [DUPLICATE], "0", "CATEGORY 1")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;elif [DUPLICATE] == "1":&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; output = replace( [DUPLICATE], "1", "CATEGORY 2")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;....&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Jun 2012 13:21:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/conditional-replace-function-in-field-calculator/m-p/345314#M27114</guid>
      <dc:creator>JimCousins</dc:creator>
      <dc:date>2012-06-20T13:21:28Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional replace function in Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/conditional-replace-function-in-field-calculator/m-p/345315#M27115</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks but still not working. Is it something with the &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;if [DUPLICATE] == "0":&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;output = replace( [DUPLICATE], "0", "CATEGORY 1")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Tried that line by itself and returned an error.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Jun 2012 17:21:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/conditional-replace-function-in-field-calculator/m-p/345315#M27115</guid>
      <dc:creator>BenjaminYoung</dc:creator>
      <dc:date>2012-06-20T17:21:48Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional replace function in Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/conditional-replace-function-in-field-calculator/m-p/345316#M27116</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;In the Field Calc, need to do &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;!DUPLICATE!&lt;/SPAN&gt;&lt;SPAN&gt; and not &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;[DUPLICATE]&lt;/SPAN&gt;&lt;SPAN&gt; in Python.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Jun 2012 17:23:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/conditional-replace-function-in-field-calculator/m-p/345316#M27116</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2012-06-20T17:23:41Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional replace function in Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/conditional-replace-function-in-field-calculator/m-p/345317#M27117</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Also be mindful of indentation. My earlier post didn't show correct indentation after the if statement. Apologies for that.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Jun 2012 19:53:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/conditional-replace-function-in-field-calculator/m-p/345317#M27117</guid>
      <dc:creator>JimCousins</dc:creator>
      <dc:date>2012-06-20T19:53:06Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional replace function in Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/conditional-replace-function-in-field-calculator/m-p/345318#M27118</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Firstly, you need to decide if you want to use VBScript or Python. You started with almost functional VBScript and have been slowly drifting into functional Python.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;PYTHON:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;In the expression box:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;func(!DUPLICATE!)&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;Then, in the codeblock:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def func(dup):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if dup == "0":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return "CATEGORY 1"
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif dup == "1":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return "CATEGORY 2"
 &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;VBSCRIPT:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;In the expression box:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;result&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;Codeblock:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;if [DUPLICATE] = 0 then
&amp;nbsp; result = "CATEGORY 1"
elseif [DUPLICATE] = 1 then
&amp;nbsp; result = "CATEGORY 2"
else
&amp;nbsp; result = [DUPLICATE]
end if&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:16:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/conditional-replace-function-in-field-calculator/m-p/345318#M27118</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-11T16:16:35Z</dc:date>
    </item>
  </channel>
</rss>

