<?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: Copy value from one cell to another, if condition met in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/copy-value-from-one-cell-to-another-if-condition/m-p/416665#M14080</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/12727" target="_blank"&gt;Malcolm,&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When calling a function to assign a value to an attribute in field calculator you need to pass the parameters needed in the function.&amp;nbsp; In this case, the pinning function needs to pass the datetime (FullDateTime) and the temperature (Jan26_temp) so your function call should be &lt;STRONG&gt;pinning(!FullDateTime!, !Jan26_temp!)&lt;/STRONG&gt;&amp;nbsp; These will be passed to the function as the variables defined in the def statement.&amp;nbsp; In&amp;nbsp;the case below,&amp;nbsp;FullDateTime is assigned to &lt;STRONG&gt;dt&lt;/STRONG&gt; and Jan26_temp is assigned to&lt;STRONG&gt; temp&lt;/STRONG&gt;.&amp;nbsp; You then use dt and temp in your function to perform your calculations/comparisons and return a value or variable using a &lt;STRONG&gt;return&lt;/STRONG&gt; statement, in this case the value of temp or -99.&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;pinning&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;dt&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; temp&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; dt&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;strftime&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"%Y/%m/%d"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"2019/01/26"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; temp
  &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="operator token"&gt;-&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;99&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;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Working with dates in ArcGIS is temperamental.&amp;nbsp; What I have done above is used the &lt;STRONG&gt;strftime&lt;/STRONG&gt; method of a datetime class to return a &lt;SPAN style="text-decoration: underline;"&gt;string&lt;/SPAN&gt; representing the date in the format of YYYY/MM/DD and compare it to the string "2019/01/26", the date you are checking.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Another method you could use would be to create a datetime for 1/26/2019 and check the date portion of this value to the date portion of your FullDateTime&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;chk &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; datetime&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;datetime&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;2019&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;26&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;def&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;pinning&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;dt&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; tmp&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; dt&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;date&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; chk&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;date&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
        &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; tmp
    &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="operator token"&gt;-&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;99&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;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope that helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 18:51:30 GMT</pubDate>
    <dc:creator>LanceCole</dc:creator>
    <dc:date>2021-12-11T18:51:30Z</dc:date>
    <item>
      <title>Copy value from one cell to another, if condition met</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/copy-value-from-one-cell-to-another-if-condition/m-p/416664#M14079</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm trying some field calculation Python code that would copy over a corresponding value from one float field to another float field, based on whether a Date field is a specific date. Essentially, I want temperature values (Jan26_temp) copied over to another field (Pin_temp) &lt;STRONG&gt;&lt;EM&gt;only&lt;/EM&gt; &lt;/STRONG&gt;if the FullDateTime field's date is January 26, 2019. Unfortunately, my code returns only Null values. Here is my code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="image-1 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/452568_Untitled2.png" /&gt;&lt;IMG alt="" class="image-2 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/452588_Untitled.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Jul 2019 18:23:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/copy-value-from-one-cell-to-another-if-condition/m-p/416664#M14079</guid>
      <dc:creator>MalcolmLittle</dc:creator>
      <dc:date>2019-07-08T18:23:03Z</dc:date>
    </item>
    <item>
      <title>Re: Copy value from one cell to another, if condition met</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/copy-value-from-one-cell-to-another-if-condition/m-p/416665#M14080</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/12727" target="_blank"&gt;Malcolm,&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When calling a function to assign a value to an attribute in field calculator you need to pass the parameters needed in the function.&amp;nbsp; In this case, the pinning function needs to pass the datetime (FullDateTime) and the temperature (Jan26_temp) so your function call should be &lt;STRONG&gt;pinning(!FullDateTime!, !Jan26_temp!)&lt;/STRONG&gt;&amp;nbsp; These will be passed to the function as the variables defined in the def statement.&amp;nbsp; In&amp;nbsp;the case below,&amp;nbsp;FullDateTime is assigned to &lt;STRONG&gt;dt&lt;/STRONG&gt; and Jan26_temp is assigned to&lt;STRONG&gt; temp&lt;/STRONG&gt;.&amp;nbsp; You then use dt and temp in your function to perform your calculations/comparisons and return a value or variable using a &lt;STRONG&gt;return&lt;/STRONG&gt; statement, in this case the value of temp or -99.&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;pinning&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;dt&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; temp&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; dt&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;strftime&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"%Y/%m/%d"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"2019/01/26"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; temp
  &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="operator token"&gt;-&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;99&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;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Working with dates in ArcGIS is temperamental.&amp;nbsp; What I have done above is used the &lt;STRONG&gt;strftime&lt;/STRONG&gt; method of a datetime class to return a &lt;SPAN style="text-decoration: underline;"&gt;string&lt;/SPAN&gt; representing the date in the format of YYYY/MM/DD and compare it to the string "2019/01/26", the date you are checking.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Another method you could use would be to create a datetime for 1/26/2019 and check the date portion of this value to the date portion of your FullDateTime&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;chk &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; datetime&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;datetime&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;2019&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;26&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;def&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;pinning&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;dt&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; tmp&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; dt&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;date&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; chk&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;date&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
        &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; tmp
    &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="operator token"&gt;-&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;99&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;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope that helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 18:51:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/copy-value-from-one-cell-to-another-if-condition/m-p/416665#M14080</guid>
      <dc:creator>LanceCole</dc:creator>
      <dc:date>2021-12-11T18:51:30Z</dc:date>
    </item>
    <item>
      <title>Re: Copy value from one cell to another, if condition met</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/copy-value-from-one-cell-to-another-if-condition/m-p/416666#M14081</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the clarification, Lance. I actually modified the else: statement to send &lt;EM&gt;pass &lt;/EM&gt;instead of -99, seeing that I will need to pin the temperature data for a total of 12 data collection days.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Jul 2019 14:23:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/copy-value-from-one-cell-to-another-if-condition/m-p/416666#M14081</guid>
      <dc:creator>MalcolmLittle</dc:creator>
      <dc:date>2019-07-09T14:23:41Z</dc:date>
    </item>
  </channel>
</rss>

