<?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 python compare two fields, update a third in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-compare-two-fields-update-a-third/m-p/443798#M34784</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to compare two fields to each other and then use that information to update a third field.&amp;nbsp; Here are the fields that I have in my data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Field A:&amp;nbsp; &lt;SPAN&gt;Direction (numeric)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Field B:&amp;nbsp; &lt;SPAN&gt;Bearing (numeric)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Field C:&amp;nbsp; &lt;SPAN&gt;KeepDiscardFlag (text)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below is the code that I've tried based on other discussions in GeoNet, but it doesn't work&amp;nbsp;(errors out saying that it couldn't evaluate the python expression).&amp;nbsp; What I'm trying to do is this:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Make sure that Direction and Bearing are not null&lt;/LI&gt;&lt;LI&gt;Set the&amp;nbsp;&lt;SPAN&gt;KeepDiscardFlag field to "Keep" if Bearing is between Direction (plus or minus 22.5), or&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;Set the KeepDiscardFlag field to "Delete" if Bearing is not between Direction (plus or minus 22.5)&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Expression&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Reclass(!KeepDiscardFlag!, !Direction!, !Bearing!)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Code Block&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE&gt;def Reclass(KeepDiscardFlag, Direction, Bearing):&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;if ( (&lt;SPAN&gt;Direction&lt;/SPAN&gt; is None or&amp;nbsp;Bearing is None) and (&lt;SPAN&gt;Direction&lt;/SPAN&gt; - 22.5) &amp;lt;=&amp;nbsp;Bearing &amp;lt;= (&lt;SPAN&gt;Direction&lt;/SPAN&gt; + 22.5) ):&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN&gt;KeepDiscardFlag&lt;/SPAN&gt; = "Keep"&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;elif ( (&lt;SPAN&gt;Direction&lt;/SPAN&gt; is None or &lt;SPAN&gt;Bearing&lt;/SPAN&gt; is None) or (&lt;SPAN&gt;Direction&lt;/SPAN&gt; - 22.5) &amp;gt;= &lt;SPAN&gt;Bearing&lt;/SPAN&gt; &amp;gt;= (&lt;SPAN&gt;Direction&lt;/SPAN&gt; + 22.5) ):&lt;BR /&gt; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;KeepDiscardFlag&lt;/SPAN&gt; = "Delete"&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 22 Jul 2019 19:33:09 GMT</pubDate>
    <dc:creator>NickO_Day</dc:creator>
    <dc:date>2019-07-22T19:33:09Z</dc:date>
    <item>
      <title>python compare two fields, update a third</title>
      <link>https://community.esri.com/t5/python-questions/python-compare-two-fields-update-a-third/m-p/443798#M34784</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to compare two fields to each other and then use that information to update a third field.&amp;nbsp; Here are the fields that I have in my data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Field A:&amp;nbsp; &lt;SPAN&gt;Direction (numeric)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Field B:&amp;nbsp; &lt;SPAN&gt;Bearing (numeric)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Field C:&amp;nbsp; &lt;SPAN&gt;KeepDiscardFlag (text)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below is the code that I've tried based on other discussions in GeoNet, but it doesn't work&amp;nbsp;(errors out saying that it couldn't evaluate the python expression).&amp;nbsp; What I'm trying to do is this:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Make sure that Direction and Bearing are not null&lt;/LI&gt;&lt;LI&gt;Set the&amp;nbsp;&lt;SPAN&gt;KeepDiscardFlag field to "Keep" if Bearing is between Direction (plus or minus 22.5), or&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;Set the KeepDiscardFlag field to "Delete" if Bearing is not between Direction (plus or minus 22.5)&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Expression&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Reclass(!KeepDiscardFlag!, !Direction!, !Bearing!)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Code Block&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE&gt;def Reclass(KeepDiscardFlag, Direction, Bearing):&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;if ( (&lt;SPAN&gt;Direction&lt;/SPAN&gt; is None or&amp;nbsp;Bearing is None) and (&lt;SPAN&gt;Direction&lt;/SPAN&gt; - 22.5) &amp;lt;=&amp;nbsp;Bearing &amp;lt;= (&lt;SPAN&gt;Direction&lt;/SPAN&gt; + 22.5) ):&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN&gt;KeepDiscardFlag&lt;/SPAN&gt; = "Keep"&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;elif ( (&lt;SPAN&gt;Direction&lt;/SPAN&gt; is None or &lt;SPAN&gt;Bearing&lt;/SPAN&gt; is None) or (&lt;SPAN&gt;Direction&lt;/SPAN&gt; - 22.5) &amp;gt;= &lt;SPAN&gt;Bearing&lt;/SPAN&gt; &amp;gt;= (&lt;SPAN&gt;Direction&lt;/SPAN&gt; + 22.5) ):&lt;BR /&gt; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;KeepDiscardFlag&lt;/SPAN&gt; = "Delete"&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Jul 2019 19:33:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-compare-two-fields-update-a-third/m-p/443798#M34784</guid>
      <dc:creator>NickO_Day</dc:creator>
      <dc:date>2019-07-22T19:33:09Z</dc:date>
    </item>
    <item>
      <title>Re: python compare two fields, update a third</title>
      <link>https://community.esri.com/t5/python-questions/python-compare-two-fields-update-a-third/m-p/443799#M34785</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/20331" target="_blank"&gt;Nick,&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) When you have a question it is better to post as a question.&amp;nbsp; You will get a better response.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2) looking at your logic, it needs some work as it very hard to follow and your text does not match your code.&amp;nbsp;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;def&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;Reclass&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;Direction&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; Bearing&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
  &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; Direction &lt;SPAN class="operator token"&gt;and&lt;/SPAN&gt; Bearing&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; abs&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;Direction &lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt; Bearing&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;&amp;lt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;22.5&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
      &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Keep"&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;elif&lt;/SPAN&gt; abs&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;Direction &lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt; Bearing&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;22.5&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
      &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Delete"&lt;/SPAN&gt;
  &lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"None"&lt;/SPAN&gt;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When you call your function use&amp;nbsp;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #3d3d3d; font-family: arial,helvetica,'helvetica neue',verdana,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;&lt;STRONG&gt;Reclass(!Direction!, !Bearing!)&lt;/STRONG&gt; as you will be setting the value for&amp;nbsp;!KeepDiscardFlag! using the return statement.&amp;nbsp; I added a "None" return if Direction or Bearing are either None or Null.&amp;nbsp; The logic also does not address bearing and direction values around north such as 350 and 10.&amp;nbsp; The difference is 20 in actual degrees but the math (350-10) is 340, it would return "Delete".&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:51:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-compare-two-fields-update-a-third/m-p/443799#M34785</guid>
      <dc:creator>LanceCole</dc:creator>
      <dc:date>2021-12-11T19:51:08Z</dc:date>
    </item>
    <item>
      <title>Re: python compare two fields, update a third</title>
      <link>https://community.esri.com/t5/python-questions/python-compare-two-fields-update-a-third/m-p/443800#M34786</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Lance,&lt;/P&gt;&lt;P&gt;Thanks for the help.&amp;nbsp; I was trying to write the code as explicitly as possible to explain what I'm doing, but appreciate your cleaning it up.&amp;nbsp; That was perfect!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Jul 2019 20:13:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-compare-two-fields-update-a-third/m-p/443800#M34786</guid>
      <dc:creator>NickO_Day</dc:creator>
      <dc:date>2019-07-22T20:13:24Z</dc:date>
    </item>
    <item>
      <title>Re: python compare two fields, update a third</title>
      <link>https://community.esri.com/t5/python-questions/python-compare-two-fields-update-a-third/m-p/443801#M34787</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/20331" target="_blank"&gt;Nick O'Day&lt;/A&gt;‌&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I revised the code to handle values around north, such as Reclass(350,10) and return the correct data.&amp;nbsp; This can be reduced to just a few lines but for readability I left it longer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;def&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;Reclass&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;Direction&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; Bearing&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
  &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; Direction &lt;SPAN class="operator token"&gt;and&lt;/SPAN&gt; Bearing&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    delta &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; abs&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;Direction &lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt; Bearing&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;%&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;360&lt;/SPAN&gt;
    delta &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;360&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt;delta &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; delta&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;180&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt; delta
    &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; delta &lt;SPAN class="operator token"&gt;&amp;lt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;22.5&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
      &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Keep"&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;elif&lt;/SPAN&gt; delta &lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;22.5&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
      &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Delete"&lt;/SPAN&gt;
  &lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"None"&lt;/SPAN&gt;
&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:51:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-compare-two-fields-update-a-third/m-p/443801#M34787</guid>
      <dc:creator>LanceCole</dc:creator>
      <dc:date>2021-12-11T19:51:11Z</dc:date>
    </item>
    <item>
      <title>Re: python compare two fields, update a third</title>
      <link>https://community.esri.com/t5/python-questions/python-compare-two-fields-update-a-third/m-p/443802#M34788</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If one of Lance's responses answered your question, please "Mark Correct" to both give credit and close out the question.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Jul 2019 21:57:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-compare-two-fields-update-a-third/m-p/443802#M34788</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2019-07-22T21:57:26Z</dc:date>
    </item>
  </channel>
</rss>

