<?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: Changing Field Characters in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/changing-field-characters/m-p/204083#M15705</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank You bunches! I see where I messed up. My -KG had no spaces so it was thinking it worked the code when the code I provided was wrong.&amp;nbsp; Python. Gotta remember it wants spaces correct! Thanks again.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 13 Oct 2014 20:37:27 GMT</pubDate>
    <dc:creator>MichelleCouden1</dc:creator>
    <dc:date>2014-10-13T20:37:27Z</dc:date>
    <item>
      <title>Changing Field Characters</title>
      <link>https://community.esri.com/t5/python-questions/changing-field-characters/m-p/204076#M15698</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a field with some stuff in it I don't want in it. For Example: It is the highway route name with - KG at the end. Example : IH0045 - KG. I want to remove the -KG. How do I do this??&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Oct 2014 19:39:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/changing-field-characters/m-p/204076#M15698</guid>
      <dc:creator>MichelleCouden1</dc:creator>
      <dc:date>2014-10-10T19:39:45Z</dc:date>
    </item>
    <item>
      <title>Re: Changing Field Characters</title>
      <link>https://community.esri.com/t5/python-questions/changing-field-characters/m-p/204077#M15699</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Michelle,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;this might answer your question.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A _jive_internal="true" href="https://community.esri.com/thread/42674" style="line-height: 1.5;" title="https://community.esri.com/thread/42674"&gt;https://community.esri.com/thread/42674&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Oct 2014 19:44:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/changing-field-characters/m-p/204077#M15699</guid>
      <dc:creator>TimWitt2</dc:creator>
      <dc:date>2014-10-10T19:44:56Z</dc:date>
    </item>
    <item>
      <title>Re: Changing Field Characters</title>
      <link>https://community.esri.com/t5/python-questions/changing-field-characters/m-p/204078#M15700</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Some options in Python&amp;nbsp; interpreter&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; "IH0045 - KG".replace("- KG","")&lt;/P&gt;&lt;P&gt;'IH0045 '&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Not great leaves the trailing space after ...45&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; "IH0045 - KG".replace(" - KG","")&lt;/P&gt;&lt;P&gt;'IH0045'&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Better but you have to remember the extra space&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; "IH0045 - KG".split(" ")[0]&lt;/P&gt;&lt;P&gt;'IH0045'&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #OK allows you to get the first bit&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;now in the field calculator it would look like this&lt;/P&gt;&lt;P&gt;!YourField!.replace("- KG","")&lt;/P&gt;&lt;P&gt;!YourField!.replace(" - KG","")&lt;/P&gt;&lt;P&gt;!YourField!.split(" ")[0]&lt;/P&gt;&lt;P&gt;where !YourField! is obvious but enclosed in exclamation marks.&amp;nbsp; All comments above depend upon the data structure you have provided...other options will depend upon any variants you can now think of&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Oct 2014 19:48:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/changing-field-characters/m-p/204078#M15700</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-10-10T19:48:02Z</dc:date>
    </item>
    <item>
      <title>Re: Changing Field Characters</title>
      <link>https://community.esri.com/t5/python-questions/changing-field-characters/m-p/204079#M15701</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There are a couple ways, depending on your data. Is the format consistent? In Field Calculator (parser set to Python), one way is this, where &amp;lt;yourfield&amp;gt; is your field name:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14129703372578401" jivemacro_uid="_14129703372578401"&gt;
&lt;P&gt;&amp;lt;yourfield&amp;gt;.split()[0]&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will return the part of the string before the first space, e.g. IH0045. split() takes the whole string and breaks it into a list using a space to break the elements of the string as a separator. [0] references the first element of the list. You could give split() an argument and break on that if a space isn't what you want. For example, split('4') would give you the list ['IH00', '5 - KG'}. The 4 in this example, and the space in the first, are not part of the list.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If your data is not in a consistent format, or what you want removed is not consistent, this may not give you what you want. That would be a more complex operation that would depend on the data.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Oct 2014 19:54:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/changing-field-characters/m-p/204079#M15701</guid>
      <dc:creator>Zeke</dc:creator>
      <dc:date>2014-10-10T19:54:32Z</dc:date>
    </item>
    <item>
      <title>Re: Changing Field Characters</title>
      <link>https://community.esri.com/t5/python-questions/changing-field-characters/m-p/204080#M15702</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Find and Replace would work just fine if you didn't want to mess with VB or Python&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Oct 2014 20:07:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/changing-field-characters/m-p/204080#M15702</guid>
      <dc:creator>StevenGraf1</dc:creator>
      <dc:date>2014-10-10T20:07:50Z</dc:date>
    </item>
    <item>
      <title>Re: Changing Field Characters</title>
      <link>https://community.esri.com/t5/python-questions/changing-field-characters/m-p/204081#M15703</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;OK, I used the second one of your codes. &lt;/P&gt;&lt;P&gt;!RID!.replace(" - KG","")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It said it ran and finished in 3 seconds but it did not change the field???&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Oct 2014 20:03:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/changing-field-characters/m-p/204081#M15703</guid>
      <dc:creator>MichelleCouden1</dc:creator>
      <dc:date>2014-10-13T20:03:31Z</dc:date>
    </item>
    <item>
      <title>Re: Changing Field Characters</title>
      <link>https://community.esri.com/t5/python-questions/changing-field-characters/m-p/204082#M15704</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;is your field named RID?&amp;nbsp; Did you toggle on the python processor at the top of the field calculator dialog?&amp;nbsp; See the attached images.&amp;nbsp; Image one is the before when I added the field.&amp;nbsp; Image 2 is when I did the field calculation.&amp;nbsp;&amp;nbsp; As for the dataframe...it is a long story &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;P&gt;The exact expression I used was&amp;nbsp; &lt;STRONG&gt; !RID!.replace(" - KG","")&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="20794" alt="Pumpkin1.png" class="jive-image image-1" src="https://community.esri.com/legacyfs/online/20794_Pumpkin1.png" style="width: 274px; height: 195px;" /&gt;&lt;IMG __jive_id="20879" alt="Pumpkin2.png" class="jive-image image-2" height="529" src="https://community.esri.com/legacyfs/online/20879_Pumpkin2.png" style="width: 269px; height: 194px;" width="731" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Oct 2014 20:18:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/changing-field-characters/m-p/204082#M15704</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-10-13T20:18:55Z</dc:date>
    </item>
    <item>
      <title>Re: Changing Field Characters</title>
      <link>https://community.esri.com/t5/python-questions/changing-field-characters/m-p/204083#M15705</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank You bunches! I see where I messed up. My -KG had no spaces so it was thinking it worked the code when the code I provided was wrong.&amp;nbsp; Python. Gotta remember it wants spaces correct! Thanks again.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Oct 2014 20:37:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/changing-field-characters/m-p/204083#M15705</guid>
      <dc:creator>MichelleCouden1</dc:creator>
      <dc:date>2014-10-13T20:37:27Z</dc:date>
    </item>
  </channel>
</rss>

