<?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 Using Python in Field calculator to update null values in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/using-python-in-field-calculator-to-update-null/m-p/671046#M51974</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am trying to update some entries in an attribute table so that where I have blanks I now have information based on another field in the table using the following code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def firstupdate(DescGroup, DescTerm):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (DescGroup in ['Inland Water', 'Tidal Water']) and (DescTerm == &amp;lt;Null&amp;gt;):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 'Water'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif (DescGroup in ['Building' , 'Structure' , 'Glasshouse']) and (DescTerm == &amp;lt;Null&amp;gt;):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 'Structure'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif (DescGroup in ['Road' , 'Track' , 'Path', 'Rail' , 'Roadside']) and (DescTerm == &amp;lt;Null&amp;gt;):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 'Track'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else DescTerm == &amp;lt;Null&amp;gt;:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 'Landform'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My problem is making sure I am recognising Null properly - I have tried with or without quotes as DescTerm is a string field but neither work and I get a syntax error. I have also just tried with using '' rather than the word Null.My attribute table has a field called DescTerm which has some blank entries which I want to update by what is in the DescGroup field.&amp;nbsp; I want all the ones that aren't blank to be left as they are!&amp;nbsp;&amp;nbsp; Any advice on how to do this is much appreciated as this is my first foray into Python!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ps i have also tried doing this just by selecting the blank ones and running an abridged version of the code without the reference to null and I still get a syntax error or it runs and it doesnt actually do anything.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 22 Apr 2014 13:20:04 GMT</pubDate>
    <dc:creator>LucindaKirkpatrick</dc:creator>
    <dc:date>2014-04-22T13:20:04Z</dc:date>
    <item>
      <title>Using Python in Field calculator to update null values</title>
      <link>https://community.esri.com/t5/python-questions/using-python-in-field-calculator-to-update-null/m-p/671046#M51974</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am trying to update some entries in an attribute table so that where I have blanks I now have information based on another field in the table using the following code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; def firstupdate(DescGroup, DescTerm):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (DescGroup in ['Inland Water', 'Tidal Water']) and (DescTerm == &amp;lt;Null&amp;gt;):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 'Water'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif (DescGroup in ['Building' , 'Structure' , 'Glasshouse']) and (DescTerm == &amp;lt;Null&amp;gt;):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 'Structure'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif (DescGroup in ['Road' , 'Track' , 'Path', 'Rail' , 'Roadside']) and (DescTerm == &amp;lt;Null&amp;gt;):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 'Track'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else DescTerm == &amp;lt;Null&amp;gt;:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 'Landform'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My problem is making sure I am recognising Null properly - I have tried with or without quotes as DescTerm is a string field but neither work and I get a syntax error. I have also just tried with using '' rather than the word Null.My attribute table has a field called DescTerm which has some blank entries which I want to update by what is in the DescGroup field.&amp;nbsp; I want all the ones that aren't blank to be left as they are!&amp;nbsp;&amp;nbsp; Any advice on how to do this is much appreciated as this is my first foray into Python!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ps i have also tried doing this just by selecting the blank ones and running an abridged version of the code without the reference to null and I still get a syntax error or it runs and it doesnt actually do anything.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Apr 2014 13:20:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-python-in-field-calculator-to-update-null/m-p/671046#M51974</guid>
      <dc:creator>LucindaKirkpatrick</dc:creator>
      <dc:date>2014-04-22T13:20:04Z</dc:date>
    </item>
    <item>
      <title>Re: Using Python in Field calculator to update null values</title>
      <link>https://community.esri.com/t5/python-questions/using-python-in-field-calculator-to-update-null/m-p/671047#M51975</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;DescTerm == &amp;lt;Null&amp;gt; &lt;/PRE&gt;&lt;SPAN&gt;is an invalid statement.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This should capture any blank or null entries in a string field.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;if DescTerm in ("", " ", None):
&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:19:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-python-in-field-calculator-to-update-null/m-p/671047#M51975</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-12T04:19:16Z</dc:date>
    </item>
    <item>
      <title>Re: Using Python in Field calculator to update null values</title>
      <link>https://community.esri.com/t5/python-questions/using-python-in-field-calculator-to-update-null/m-p/671048#M51976</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Python doesn't recognize 'Null'. Instead, use None. Also, the proper way to check is 'is None', or 'is not None'. Without quotes, of course.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Apr 2014 13:29:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-python-in-field-calculator-to-update-null/m-p/671048#M51976</guid>
      <dc:creator>Zeke</dc:creator>
      <dc:date>2014-04-22T13:29:36Z</dc:date>
    </item>
    <item>
      <title>Re: Using Python in Field calculator to update null values</title>
      <link>https://community.esri.com/t5/python-questions/using-python-in-field-calculator-to-update-null/m-p/671049#M51977</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you - that worked, so it did replace the Null values - but it also then replaced all the other values as well that were already in there from before! Is there something about the way I have ended the script that caused it? This is the updated version of the script I used:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#DescGroup update&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;firstupdate(!DescGroup!, !DescTerm!)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;def firstupdate(DescGroup, DescTerm):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; if (DescGroup in ['Inland Water', 'Tidal Water']) and (DescTerm in '', " ", None):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 'Water' #Needs to be string&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; elif (DescGroup in ['Building' , 'Structure' , 'Glasshouse']) and (DescTerm in '', " ", None):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 'Structure' #all fields in DescGroup with Building / Structure / Glasshouse in catagorised as Building&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; elif (DescGroup in ['Road' , 'Track' , 'Path', 'Rail' , 'Roadside']) and (DescTerm in '', " ", None):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 'Track'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; elif (DescTerm in '', " ", None):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 'Landform' #if blank and dont fit any other catagory&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; else:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return DescTerm&amp;nbsp; # if not blank&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also can you make python recognise text within a string so that 'Road' and 'Road; Path' are both relabelled Track without having to go through all the different catagories? I have many catagories like this that need to be lumped together and I thought that python would recognise just the letters in the string rather than the whole string having to match? Thank you!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Apr 2014 13:43:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-python-in-field-calculator-to-update-null/m-p/671049#M51977</guid>
      <dc:creator>LucindaKirkpatrick</dc:creator>
      <dc:date>2014-04-22T13:43:14Z</dc:date>
    </item>
    <item>
      <title>Re: Using Python in Field calculator to update null values</title>
      <link>https://community.esri.com/t5/python-questions/using-python-in-field-calculator-to-update-null/m-p/671050#M51978</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You have your brackets off. You don't need the whole term in brackets just your listed items.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Good&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;DescTerm in ("", " ", None)&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;Bad&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;(DescTerm in '', " ", None)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For your second part the easiest way is using the in method.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;if 'road' in DescGroup&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Apr 2014 13:47:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-python-in-field-calculator-to-update-null/m-p/671050#M51978</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2014-04-22T13:47:29Z</dc:date>
    </item>
    <item>
      <title>Re: Using Python in Field calculator to update null values</title>
      <link>https://community.esri.com/t5/python-questions/using-python-in-field-calculator-to-update-null/m-p/671051#M51979</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;You have your brackets off. You don't need the whole term in brackets just your listed items.&lt;BR /&gt;&lt;BR /&gt;Good&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;DescTerm in ("", " ", None)&lt;/PRE&gt;&lt;BR /&gt;Bad&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;(DescTerm in '', " ", None)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;For your second part the easiest way is using the in method.&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;if 'road' in DescGroup&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;That worked, thank you! Now just to figure out the catagories...read somewhere that using regular expressions may help!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Apr 2014 13:51:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-python-in-field-calculator-to-update-null/m-p/671051#M51979</guid>
      <dc:creator>LucindaKirkpatrick</dc:creator>
      <dc:date>2014-04-22T13:51:49Z</dc:date>
    </item>
  </channel>
</rss>

