<?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: Python Expression to Change Field Labels in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-expression-to-change-field-labels/m-p/205500#M15821</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;can you check to see if DISTRICT is a text field(string type) or a numeric type?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If text, make it if int([DISTRICT) == 1:&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 13 Aug 2014 19:02:08 GMT</pubDate>
    <dc:creator>IanMurray</dc:creator>
    <dc:date>2014-08-13T19:02:08Z</dc:date>
    <item>
      <title>Python Expression to Change Field Labels</title>
      <link>https://community.esri.com/t5/python-questions/python-expression-to-change-field-labels/m-p/205495#M15816</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How is the Python expression written (i.e. what is the syntax?) to change a field's labels from its unique values to custom labels?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The field I'm working with is DISTRICT.&amp;nbsp; Its unique values are 1, 2, 3, 4, and 5.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On my map, I want the districts to be labeled with their supervisors' names, instead of with their numbers.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Aug 2014 17:59:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-expression-to-change-field-labels/m-p/205495#M15816</guid>
      <dc:creator>ShawnGazzano</dc:creator>
      <dc:date>2014-08-13T17:59:58Z</dc:date>
    </item>
    <item>
      <title>Re: Python Expression to Change Field Labels</title>
      <link>https://community.esri.com/t5/python-questions/python-expression-to-change-field-labels/m-p/205496#M15817</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It is pretty simple.&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14079530837389694 jive_text_macro" jivemacro_uid="_14079530837389694" modifiedtitle="true"&gt;
&lt;P&gt;def FindLabel ( [DISTRICT] ):&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if DISTRICT == 1:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return "Bob Hope" #Input your supervisor name there&lt;/P&gt;
&lt;P&gt;&amp;nbsp; elif DISTRICT == 2:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return "Bob Costas" #Input your Supervisor name there&lt;/P&gt;
&lt;P&gt;&amp;nbsp; elif DISTRICT == 3:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return "Bob Marley" #Input your Supervisor name there&lt;/P&gt;
&lt;P&gt;&amp;nbsp; elif DISTRICT == 4:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return "Bobby Bowden" #Input your Supervisor name there&lt;/P&gt;
&lt;P&gt;&amp;nbsp; elif DISTRICT == 5:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return "Bob the Clown" #Input your Supervisor name there&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;


&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Similar to that, just use if/elif statements to evaluate the value of District and return the name you want. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Use Python for parser and advanced expression checked.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Aug 2014 18:07:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-expression-to-change-field-labels/m-p/205496#M15817</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2014-08-13T18:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: Python Expression to Change Field Labels</title>
      <link>https://community.esri.com/t5/python-questions/python-expression-to-change-field-labels/m-p/205497#M15818</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I entered&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="keyword"&gt;def FindLabel ( [District] &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="keyword"&gt;&amp;nbsp; if&lt;/SPAN&gt; District == &lt;SPAN class="number"&gt;1&lt;/SPAN&gt;:&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword"&gt;return&lt;/SPAN&gt; &lt;SPAN class="string"&gt;"Bob Hope"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but the response to clicking the Verify button was "Carriage returns are not allowed in simple expressions."&lt;/P&gt;&lt;P&gt;I took out the extra "=" in front of "1", but the Verify response was the same.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Aug 2014 18:22:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-expression-to-change-field-labels/m-p/205497#M15818</guid>
      <dc:creator>ShawnGazzano</dc:creator>
      <dc:date>2014-08-13T18:22:11Z</dc:date>
    </item>
    <item>
      <title>Re: Python Expression to Change Field Labels</title>
      <link>https://community.esri.com/t5/python-questions/python-expression-to-change-field-labels/m-p/205498#M15819</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Like I said, make sure the advanced box is checked.&lt;IMG __jive_id="3376" alt="LabelExpression.png" class="jive-image image-1" src="https://community.esri.com/legacyfs/online/3376_LabelExpression.png" style="height: auto;" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It doesn't allow multiple lines of code for simple expressions, so the advanced box needs to be clicked&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Aug 2014 18:25:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-expression-to-change-field-labels/m-p/205498#M15819</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2014-08-13T18:25:39Z</dc:date>
    </item>
    <item>
      <title>Re: Python Expression to Change Field Labels</title>
      <link>https://community.esri.com/t5/python-questions/python-expression-to-change-field-labels/m-p/205499#M15820</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ok, I've got Advanced checked and Python for parser.&amp;nbsp; That validates the expression.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But in the Expression Verification window, the Sample Text String and Sample Label are blank.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I press OK to get out of Expression Verification / Label Expression / Layer Properties windows, my map updates, but without labels; they are all blank.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The expression I have entered is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;def FindLabel ( [DISTRICT] &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; if [DISTRICT] == 1:&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; return "Bob Hope"&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Aug 2014 18:49:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-expression-to-change-field-labels/m-p/205499#M15820</guid>
      <dc:creator>ShawnGazzano</dc:creator>
      <dc:date>2014-08-13T18:49:12Z</dc:date>
    </item>
    <item>
      <title>Re: Python Expression to Change Field Labels</title>
      <link>https://community.esri.com/t5/python-questions/python-expression-to-change-field-labels/m-p/205500#M15821</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;can you check to see if DISTRICT is a text field(string type) or a numeric type?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If text, make it if int([DISTRICT) == 1:&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Aug 2014 19:02:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-expression-to-change-field-labels/m-p/205500#M15821</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2014-08-13T19:02:08Z</dc:date>
    </item>
    <item>
      <title>Re: Python Expression to Change Field Labels</title>
      <link>https://community.esri.com/t5/python-questions/python-expression-to-change-field-labels/m-p/205501#M15822</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That's nice, I was't aware of this possibility.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the list get a little longer, you may want to consider using a dictionary, like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14079574878432755 jive_text_macro" jivemacro_uid="_14079574878432755"&gt;
&lt;P&gt;def FindLabel([YourFieldName]):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dct = {1: "Bob Hope", 2: "Bob Costas", 3: "Bob Marley",&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4: "Bobby Bowden", 5:"Bob the Clown"}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; district = int([YourFieldName])&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if district in dct:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return dct[district]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return "&amp;lt;ITA&amp;gt;Unknow supervisor&amp;lt;/ITA&amp;gt;"&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I used this on the feature ID (FID) field of a shapefile with values ranging from 0 to 7 and got this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="LabelExpression.png" class="jive-image image-1" src="https://community.esri.com/legacyfs/online/3430_LabelExpression.png" style="height: auto;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Aug 2014 19:21:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-expression-to-change-field-labels/m-p/205501#M15822</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2014-08-13T19:21:48Z</dc:date>
    </item>
    <item>
      <title>Re: Python Expression to Change Field Labels</title>
      <link>https://community.esri.com/t5/python-questions/python-expression-to-change-field-labels/m-p/205502#M15823</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;It's a text field.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;def FindLabel ( [DISTRICT] &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; if int( [DISTRICT] ) == 1:&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; return "Bob Hope"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;still returns blank labels.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Aug 2014 19:38:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-expression-to-change-field-labels/m-p/205502#M15823</guid>
      <dc:creator>ShawnGazzano</dc:creator>
      <dc:date>2014-08-13T19:38:51Z</dc:date>
    </item>
    <item>
      <title>Re: Python Expression to Change Field Labels</title>
      <link>https://community.esri.com/t5/python-questions/python-expression-to-change-field-labels/m-p/205503#M15824</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hmm, mine works just fine on a sample dataset.&amp;nbsp; Did you make sure that you turned labels on for that layer?&amp;nbsp; Also, python is case sensitive, so make sure that your field is syntactically correct(proper upper/lower case, spaces,etc. included.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Aug 2014 19:48:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-expression-to-change-field-labels/m-p/205503#M15824</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2014-08-13T19:48:50Z</dc:date>
    </item>
    <item>
      <title>Re: Python Expression to Change Field Labels</title>
      <link>https://community.esri.com/t5/python-questions/python-expression-to-change-field-labels/m-p/205504#M15825</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, the layer's labels are turned on, and the expression appears to be syntactically correct. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I also tried Xander's suggestion:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;def FindLabel([DISTRICT]): &lt;/P&gt;&lt;P&gt;dct = {1: "Bob Hope", 2: "Bob Costas", 3: "Bob Marley", 4: "Bobby Bowden", 5:"Bob the Clown"} &lt;/P&gt;&lt;P&gt;district = int([DISTRICT])&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but same result: expression is validated, but with blank labels.&amp;nbsp; I'll continue to test....&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Aug 2014 20:15:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-expression-to-change-field-labels/m-p/205504#M15825</guid>
      <dc:creator>ShawnGazzano</dc:creator>
      <dc:date>2014-08-13T20:15:41Z</dc:date>
    </item>
  </channel>
</rss>

