<?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 Calculate Field based on another field using Python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/calculate-field-based-on-another-field-using/m-p/692750#M53707</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am working on a TIGER line file of roads in my county in shapefile format (although I am having the same problem with geodatabase format). I am attempting to update a created field named SpeedMPH based on another field. If the field named ROAD_MTFCC is equal to S1200 then update the SpeedMPH field to 25. My code block is written in Python 3.6 and I am running ArcGIS Pro 2.2.1 with the latest updates. My code block is:&lt;/P&gt;&lt;P&gt;def Reclass(fld):&lt;BR /&gt; if(ROAD_MTFCC == 'S1200'):&lt;BR /&gt; return 25&lt;BR /&gt; elif(ROAD_MTFCC == 'S1400'):&lt;BR /&gt; return 35&lt;BR /&gt; elif(ROAD_MTFCC == 'S1500'):&lt;BR /&gt; return 45&lt;BR /&gt; elif(ROAD_MTFCC == 'S1640'):&lt;BR /&gt; return 55&lt;/P&gt;&lt;P&gt;I then click the green check to verify my code and it is accepted. I click the run button and it runs for a few seconds. When I look at my TIGER line file of roads attribute table the SpeedMPH field is NULL. Nothing was updated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;What am I doing wrong?&lt;/P&gt;&lt;P&gt;Enclosed is a picture of the Calculate field window and a 7zip of my TIGER line shapefile. It is pretty standard Census data.&lt;IMG alt="if then code block Python" class="image-1 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/418071_CalculateField.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 03 Aug 2018 19:32:34 GMT</pubDate>
    <dc:creator>DavidKulpanowski1</dc:creator>
    <dc:date>2018-08-03T19:32:34Z</dc:date>
    <item>
      <title>Calculate Field based on another field using Python</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-based-on-another-field-using/m-p/692750#M53707</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am working on a TIGER line file of roads in my county in shapefile format (although I am having the same problem with geodatabase format). I am attempting to update a created field named SpeedMPH based on another field. If the field named ROAD_MTFCC is equal to S1200 then update the SpeedMPH field to 25. My code block is written in Python 3.6 and I am running ArcGIS Pro 2.2.1 with the latest updates. My code block is:&lt;/P&gt;&lt;P&gt;def Reclass(fld):&lt;BR /&gt; if(ROAD_MTFCC == 'S1200'):&lt;BR /&gt; return 25&lt;BR /&gt; elif(ROAD_MTFCC == 'S1400'):&lt;BR /&gt; return 35&lt;BR /&gt; elif(ROAD_MTFCC == 'S1500'):&lt;BR /&gt; return 45&lt;BR /&gt; elif(ROAD_MTFCC == 'S1640'):&lt;BR /&gt; return 55&lt;/P&gt;&lt;P&gt;I then click the green check to verify my code and it is accepted. I click the run button and it runs for a few seconds. When I look at my TIGER line file of roads attribute table the SpeedMPH field is NULL. Nothing was updated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;What am I doing wrong?&lt;/P&gt;&lt;P&gt;Enclosed is a picture of the Calculate field window and a 7zip of my TIGER line shapefile. It is pretty standard Census data.&lt;IMG alt="if then code block Python" class="image-1 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/418071_CalculateField.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Aug 2018 19:32:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-based-on-another-field-using/m-p/692750#M53707</guid>
      <dc:creator>DavidKulpanowski1</dc:creator>
      <dc:date>2018-08-03T19:32:34Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field based on another field using Python</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-based-on-another-field-using/m-p/692751#M53708</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Pass ROAD_MTFCC to your function, and in your function reference fld.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;Reclass&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;!ROAD_MTFCC!&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;Reclass&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;fld&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;fld &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'S1200'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;25&lt;/SPAN&gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="comment token"&gt;#&amp;nbsp; etc.....&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;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 05:09:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-based-on-another-field-using/m-p/692751#M53708</guid>
      <dc:creator>RandyBurton</dc:creator>
      <dc:date>2021-12-12T05:09:05Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field based on another field using Python</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-based-on-another-field-using/m-p/692752#M53709</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;STRONG&gt;Thank you Randy Burton.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;That was very helpful. I am posting a screen grab of the answer as it is supposed to look.&lt;/P&gt;&lt;P&gt;&lt;IMG alt="if then code block Python" class="image-1 jive-image j-img-original" src="https://community.esri.com/legacyfs/online/418072_Anwer.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Aug 2018 19:48:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-based-on-another-field-using/m-p/692752#M53709</guid>
      <dc:creator>DavidKulpanowski1</dc:creator>
      <dc:date>2018-08-03T19:48:52Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field based on another field using Python</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-based-on-another-field-using/m-p/692753#M53710</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You may want to restructure your if/elif/else in&amp;nbsp;your function&amp;nbsp;so that&amp;nbsp;it will always return something - perhaps a zero&amp;nbsp;or 25 for any unknown value.&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;if&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;fld &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'S1640'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp; &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;55&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;elif&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;fld &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'S1500'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp; &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;45&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;elif&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;fld &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'S1400'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp; &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;35&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&amp;nbsp; &lt;SPAN class="comment token"&gt;# for S1200 and any other value, just in case&lt;/SPAN&gt;
&amp;nbsp; &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;25&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;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 05:09:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-based-on-another-field-using/m-p/692753#M53710</guid>
      <dc:creator>RandyBurton</dc:creator>
      <dc:date>2021-12-12T05:09:08Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field based on another field using Python</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-based-on-another-field-using/m-p/692754#M53711</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Although if/elif statements can be used to create simple mappings, the statements tend to get cumbersome for anything but the most trivial mappings.&amp;nbsp; The primary mapping type in Python is dict, and it makes for a much more straightforward function in your case:&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;fld&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; d &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'S1200'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;25&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'S1400'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;35&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'S1500'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;45&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'S1640'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;55&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; d&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;get&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;fld&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;upper&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="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;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Using the get method takes care of the missing values being passed to the dictionary.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 05:09:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-based-on-another-field-using/m-p/692754#M53711</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-12T05:09:11Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field based on another field using Python</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-based-on-another-field-using/m-p/1042998#M60617</link>
      <description>&lt;P&gt;Very Slick!&amp;nbsp; Thanks for the example Josh. Used it to convert some numeric domains to text.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;def Reclass(fld):
    d = {
'0':'Unclassified',
'1':'Cemetery',
'2':'Dock',
'3':'Park',
'4':'Parkin Lot',
'5':'Sign',
'6':'Stormwater Treatment Area',
'7':'Telecom',
'8':'Utility-Water',
'9':'Utility-Electric',
'10':'Utility-Sewer',
'11':'Utility-Gas',
'12':'Vacant',
'13.1':'Apartment',
'13.01':'Single Family Unit',
'13.02':'Duplex',
'13.03':'Triplex'
'13.04':'Quadplex',
'13.05':'Mobile Home',
'13.06':'Townhouse',
'13.07':'Condominium',
'13.08':'Prefabricated Home',
'13.09':'Abandoned-Dilapidated',
'13.11':'Multi-Family',
'13.12':'Abandoned Mobile Home',
'14':'Commercial',
'15':'FSU',
'16':'TCC',
'17':'FAMU',
'18':'Elementary School',
'19':'Middle School',
'20':'High School',
'21':'Religious',
'22':'Airport',
'23':'Community Center',
'24':'Cultural',
'25':'General',
'26.01':'Govt-City',
'26.02':'Govt-County',
'26.03':'Govt-State',
'26.04':'Govt-Federal',
'27':'Hotel',
'28':'Industrial',
'29':'Medical',
'30':'Recreation',
'31':'Transportation',
'32':'Bar-Shed-Shop',
'33':'Delete',
'34':'New Building See Notes',
'35':'Garage Carport',
'36':'Mobile Home Storage',
'99':'Re-Review',
}
    return d.get(fld.upper())&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Apr 2021 17:29:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-based-on-another-field-using/m-p/1042998#M60617</guid>
      <dc:creator>NedCake1</dc:creator>
      <dc:date>2021-04-01T17:29:30Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field based on another field using Python</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-based-on-another-field-using/m-p/1043172#M60620</link>
      <description>&lt;P&gt;&lt;A href="https://docs.python.org/3/library/stdtypes.html#dict.get" target="_self"&gt;Dictionary &lt;FONT face="courier new,courier"&gt;.get()&lt;/FONT&gt;&lt;/A&gt;&amp;nbsp;is great! You can also specify a default value (besides &lt;FONT face="courier new,courier"&gt;None&lt;/FONT&gt;) if the key is not found.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Apr 2021 20:54:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-based-on-another-field-using/m-p/1043172#M60620</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-04-01T20:54:20Z</dc:date>
    </item>
  </channel>
</rss>

