<?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: Need some Python code for field calculator! in Transportation Questions</title>
    <link>https://community.esri.com/t5/transportation-questions/need-some-python-code-for-field-calculator/m-p/56388#M210</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: jofuchs&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Try changing your square brakets in your expression to normal brackets ()&lt;BR /&gt;Anthony&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you very much! That worked fine!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 03 Dec 2013 05:52:44 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2013-12-03T05:52:44Z</dc:date>
    <item>
      <title>Need some Python code for field calculator!</title>
      <link>https://community.esri.com/t5/transportation-questions/need-some-python-code-for-field-calculator/m-p/56382#M204</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: jofuchs&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi all!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am a very beginner with Python, so that will be an easy task for most of you. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I want to calculate a new field of an attribute table, something like that: ((Field X/ Field Y)*100). Since 0-Values are existent, I have to exclude these values from dividing. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;What I tried so far is displayed in the screenshot, but doesnt word untill now... (Perhaps it is totally wrong...)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]29480[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope you can help me! Many Thanks in advance!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jo&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Dec 2013 12:16:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/need-some-python-code-for-field-calculator/m-p/56382#M204</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2013-12-02T12:16:15Z</dc:date>
    </item>
    <item>
      <title>Re: Need some Python code for field calculator!</title>
      <link>https://community.esri.com/t5/transportation-questions/need-some-python-code-for-field-calculator/m-p/56383#M205</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;&lt;SPAN&gt;Original User: &lt;/SPAN&gt;&lt;A class="jive-link-email-small" href="mailto:ad_giles@hotmail.com" rel="nofollow noopener noreferrer" target="_blank"&gt;ad_giles@hotmail.com&lt;/A&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jo,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
def calc(f1,f2):
&amp;nbsp; if (f1 &amp;lt;&amp;gt; 0):
&amp;nbsp;&amp;nbsp;&amp;nbsp; return (f1/f2)*100
&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Anthony&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:08:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/need-some-python-code-for-field-calculator/m-p/56383#M205</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-10T22:08:35Z</dc:date>
    </item>
    <item>
      <title>Re: Need some Python code for field calculator!</title>
      <link>https://community.esri.com/t5/transportation-questions/need-some-python-code-for-field-calculator/m-p/56384#M206</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: jofuchs&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi Anthony,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thanks for your reply. There is still this error message appearing &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]29484[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For your information:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The field i am calculating is double formatted; f1 and f2 are long integer. But I think thsi should be ok so!?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jo&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Dec 2013 13:00:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/need-some-python-code-for-field-calculator/m-p/56384#M206</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2013-12-02T13:00:08Z</dc:date>
    </item>
    <item>
      <title>Re: Need some Python code for field calculator!</title>
      <link>https://community.esri.com/t5/transportation-questions/need-some-python-code-for-field-calculator/m-p/56385#M207</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Jo&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It looks like you have zeros for both columns, try&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
def calc(f1,f2):
&amp;nbsp; if (f1 &amp;lt;&amp;gt; 0 and f2 &amp;lt;&amp;gt; 0):
&amp;nbsp;&amp;nbsp;&amp;nbsp; return (f1/f2)*100
&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:08:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/need-some-python-code-for-field-calculator/m-p/56385#M207</guid>
      <dc:creator>AnthonyGiles</dc:creator>
      <dc:date>2021-12-10T22:08:38Z</dc:date>
    </item>
    <item>
      <title>Re: Need some Python code for field calculator!</title>
      <link>https://community.esri.com/t5/transportation-questions/need-some-python-code-for-field-calculator/m-p/56386#M208</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: jofuchs&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I corrected this, you are right. That might be another potential error, but nevertheless I always have the same error message posted before...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;EDIT:&lt;/STRONG&gt;&lt;SPAN&gt; Field f1 is long, field f2 is double, target field is double! Can this be a problem?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Dec 2013 13:46:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/need-some-python-code-for-field-calculator/m-p/56386#M208</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2013-12-02T13:46:51Z</dc:date>
    </item>
    <item>
      <title>Re: Need some Python code for field calculator!</title>
      <link>https://community.esri.com/t5/transportation-questions/need-some-python-code-for-field-calculator/m-p/56387#M209</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have created a sample feature class with three columns a,b and c. A and B are Long and C is a double. The code in the attached screenshot works fine:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]29490[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try changing your square brakets in your expression to normal brackets ()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Anthony&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Dec 2013 14:08:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/need-some-python-code-for-field-calculator/m-p/56387#M209</guid>
      <dc:creator>AnthonyGiles</dc:creator>
      <dc:date>2013-12-02T14:08:25Z</dc:date>
    </item>
    <item>
      <title>Re: Need some Python code for field calculator!</title>
      <link>https://community.esri.com/t5/transportation-questions/need-some-python-code-for-field-calculator/m-p/56388#M210</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: jofuchs&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Try changing your square brakets in your expression to normal brackets ()&lt;BR /&gt;Anthony&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you very much! That worked fine!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Dec 2013 05:52:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/need-some-python-code-for-field-calculator/m-p/56388#M210</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2013-12-03T05:52:44Z</dc:date>
    </item>
  </channel>
</rss>

