<?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: Help with Python Code/Field Calculator in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/help-with-python-code-field-calculator/m-p/1402048#M70216</link>
    <description>&lt;P&gt;Thanks a bunch! That did exactly what I was trying to do. Will keep this in the back pocket for future uses.&lt;/P&gt;</description>
    <pubDate>Thu, 28 Mar 2024 16:27:02 GMT</pubDate>
    <dc:creator>BETAGIS</dc:creator>
    <dc:date>2024-03-28T16:27:02Z</dc:date>
    <item>
      <title>Help with Python Code/Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/help-with-python-code-field-calculator/m-p/1401971#M70205</link>
      <description>&lt;P&gt;Hi. I have a String Type field in a large attribute table. I want to add a "-0" a the end of each entry or "-1", "-2", etc. See examples below:&lt;/P&gt;&lt;P&gt;Example entries in this case would be:&lt;/P&gt;&lt;P&gt;CROOKED ST 1&lt;/P&gt;&lt;P&gt;CROOKED ST 2&lt;/P&gt;&lt;P&gt;CROOKED ST 3&lt;/P&gt;&lt;P&gt;CROOKED ST 4&lt;/P&gt;&lt;P&gt;CROOKED ST 5&lt;/P&gt;&lt;P&gt;CROOKED ST 6&lt;/P&gt;&lt;P&gt;CROOKED ST 7&lt;/P&gt;&lt;P&gt;CROOKED ST 8&lt;/P&gt;&lt;P&gt;CROOKED ST 9&lt;/P&gt;&lt;P&gt;CROOKED ST 10&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I add the '-0' to the end of each entry so it'd look like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CROOKED ST-01&lt;/P&gt;&lt;P&gt;CROOKED ST-02&lt;/P&gt;&lt;P&gt;CROOKED ST-03&lt;/P&gt;&lt;P&gt;CROOKED ST-04&lt;/P&gt;&lt;P&gt;CROOKED ST-05&lt;/P&gt;&lt;P&gt;CROOKED ST-06&lt;/P&gt;&lt;P&gt;CROOKED ST-07&lt;/P&gt;&lt;P&gt;CROOKED ST-08&lt;/P&gt;&lt;P&gt;CROOKED ST-09&lt;/P&gt;&lt;P&gt;CROOKED ST-10&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone know if this is possible? Even if I cant change the double digit values proceeding after the 10th entry it would be a great help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2024 14:35:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-with-python-code-field-calculator/m-p/1401971#M70205</guid>
      <dc:creator>BETAGIS</dc:creator>
      <dc:date>2024-03-28T14:35:55Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Python Code/Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/help-with-python-code-field-calculator/m-p/1401988#M70208</link>
      <description>&lt;P&gt;Depending on a few things, you could do this with a regex calculation, or you can brute-force it.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Are the numbers already present?&lt;/LI&gt;&lt;LI&gt;Are the numbers&amp;nbsp;&lt;STRONG&gt;all&lt;/STRONG&gt; formatted per your first example?&lt;OL&gt;&lt;LI&gt;Numbers are not zero-padded&lt;/LI&gt;&lt;LI&gt;Always a space before the number&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;How high do the numbers go?&lt;/LI&gt;&lt;LI&gt;How many roadway types do you have in this dataset (e.g., ST, DR, RD, STREET)&lt;OL&gt;&lt;LI&gt;Be exacting here: "ST" and "STREET" would likely need to be treated differently.&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;/OL&gt;</description>
      <pubDate>Thu, 28 Mar 2024 14:49:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-with-python-code-field-calculator/m-p/1401988#M70208</guid>
      <dc:creator>MErikReedAugusta</dc:creator>
      <dc:date>2024-03-28T14:49:36Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Python Code/Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/help-with-python-code-field-calculator/m-p/1401992#M70209</link>
      <description>&lt;P&gt;Hi, thank you for the response. I have an answer for each of your questions:&lt;/P&gt;&lt;P&gt;1.) Yes the numbers are already present&lt;/P&gt;&lt;P&gt;2.) Yes, all numbers are per my first example throughout the dataset - always a space before the number.&lt;/P&gt;&lt;P&gt;3.) The highest number is 115 on one of the larger length roads in the dataset.&lt;/P&gt;&lt;P&gt;4.) There are 10 roadway types in total - they are all abbreviated: ST, PL, DR, RD, PKWY, PK, AVE, WAY, TER, and CT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you think it's better to do it "manually" - I'll trust your judgement. Thanks again!&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2024 15:01:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-with-python-code-field-calculator/m-p/1401992#M70209</guid>
      <dc:creator>BETAGIS</dc:creator>
      <dc:date>2024-03-28T15:01:24Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Python Code/Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/help-with-python-code-field-calculator/m-p/1402008#M70211</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Here is a function / code block I wrote that does what you're describing:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def number_streets(street):
    components = street.split(" ")
    num = components[-1]
    if len(num) == 1:
        num = "-0" + num
    else:
        num = "-" + num
    stname = " ".join(components[:-1])
    result = stname + num
    return result&lt;/LI-CODE&gt;&lt;P&gt;If you want to test it out, here's an example of how I tested it:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;sts = ["MY ST 1", "MY ST 2", "MY ST 10", "MY ST 41"]
for st in sts:
    print(number_streets(st))&lt;/LI-CODE&gt;&lt;P&gt;The results I got were:&lt;/P&gt;&lt;P&gt;MY ST-01&lt;BR /&gt;MY ST-02&lt;BR /&gt;MY ST-10&lt;BR /&gt;MY ST-41&lt;/P&gt;&lt;P&gt;For a field calculation, the expression would be:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;number_streets(!YOUR_FIELD_NAME!)&lt;/LI-CODE&gt;&lt;P&gt;I'd be interested to hear if you use this and/or if it works for your purposes.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2024 15:26:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-with-python-code-field-calculator/m-p/1402008#M70211</guid>
      <dc:creator>AllenDailey1</dc:creator>
      <dc:date>2024-03-28T15:26:39Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Python Code/Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/help-with-python-code-field-calculator/m-p/1402009#M70212</link>
      <description>&lt;P&gt;If the max number goes to 115, do you want the result to be "001" so that all the values are 3 characters.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2024 15:31:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-with-python-code-field-calculator/m-p/1402009#M70212</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2024-03-28T15:31:32Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Python Code/Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/help-with-python-code-field-calculator/m-p/1402044#M70215</link>
      <description>&lt;P&gt;No, I'd prefer the numbers to be "01" and then be 3 characters if necessary.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2024 16:25:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-with-python-code-field-calculator/m-p/1402044#M70215</guid>
      <dc:creator>BETAGIS</dc:creator>
      <dc:date>2024-03-28T16:25:40Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Python Code/Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/help-with-python-code-field-calculator/m-p/1402048#M70216</link>
      <description>&lt;P&gt;Thanks a bunch! That did exactly what I was trying to do. Will keep this in the back pocket for future uses.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2024 16:27:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-with-python-code-field-calculator/m-p/1402048#M70216</guid>
      <dc:creator>BETAGIS</dc:creator>
      <dc:date>2024-03-28T16:27:02Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Python Code/Field Calculator</title>
      <link>https://community.esri.com/t5/python-questions/help-with-python-code-field-calculator/m-p/1402051#M70217</link>
      <description>&lt;P&gt;Awesome, I'm glad!&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2024 16:29:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-with-python-code-field-calculator/m-p/1402051#M70217</guid>
      <dc:creator>AllenDailey1</dc:creator>
      <dc:date>2024-03-28T16:29:13Z</dc:date>
    </item>
  </channel>
</rss>

