<?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 Populate one field based on second in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/populate-one-field-based-on-second/m-p/236688#M18416</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This may be simple but I am only a beginner.&amp;nbsp; Does anyone have a Python script to populate a field based on the code of another field in the same table?&amp;nbsp; Or do have any recommendations where I might find a script?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Pam&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 04 Nov 2010 13:54:38 GMT</pubDate>
    <dc:creator>PamelaLinson-DeVore</dc:creator>
    <dc:date>2010-11-04T13:54:38Z</dc:date>
    <item>
      <title>Populate one field based on second</title>
      <link>https://community.esri.com/t5/python-questions/populate-one-field-based-on-second/m-p/236688#M18416</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This may be simple but I am only a beginner.&amp;nbsp; Does anyone have a Python script to populate a field based on the code of another field in the same table?&amp;nbsp; Or do have any recommendations where I might find a script?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Pam&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Nov 2010 13:54:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/populate-one-field-based-on-second/m-p/236688#M18416</guid>
      <dc:creator>PamelaLinson-DeVore</dc:creator>
      <dc:date>2010-11-04T13:54:38Z</dc:date>
    </item>
    <item>
      <title>Re: Populate one field based on second</title>
      <link>https://community.esri.com/t5/python-questions/populate-one-field-based-on-second/m-p/236689#M18417</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Pam,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; Welcome.&amp;nbsp; Try posting your question under the geoprocessing forum.&amp;nbsp; This forum is more for asking questions about ESRI Map Data.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Nov 2010 18:12:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/populate-one-field-based-on-second/m-p/236689#M18417</guid>
      <dc:creator>RandyKreuziger</dc:creator>
      <dc:date>2010-11-04T18:12:51Z</dc:date>
    </item>
    <item>
      <title>Re: Populate one field based on second</title>
      <link>https://community.esri.com/t5/python-questions/populate-one-field-based-on-second/m-p/236690#M18418</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;This may be simple but I am only a beginner.&amp;nbsp; Does anyone have a Python script to populate a field based on the code of another field in the same table?&amp;nbsp; Or do have any recommendations where I might find a script?&lt;BR /&gt;&lt;BR /&gt;Thank you&lt;BR /&gt;Pam&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi Pam&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In python use an updateCursor to access and update the rows then work row by row making your changes as required.&amp;nbsp; Here is something to get you started:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
cur = arcpy.UpdateCursor(r"c:\your file") #put in your file path here
for row in cur:
&amp;nbsp; row.fieldName1 = row.fieldName2&amp;nbsp; #here I am copying the data from one field to another, just add your own code here.
&amp;nbsp; cur.updateRow(row) #transfer the row changes from memory to the table
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helps &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Stephen&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:56:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/populate-one-field-based-on-second/m-p/236690#M18418</guid>
      <dc:creator>StephenBarrow</dc:creator>
      <dc:date>2021-12-11T11:56:26Z</dc:date>
    </item>
    <item>
      <title>Re: Populate one field based on second</title>
      <link>https://community.esri.com/t5/python-questions/populate-one-field-based-on-second/m-p/236691#M18419</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Does anyone have a Python script to populate a field based on the code of another field in the same table?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This can be done a lot faster by using the CalculateField tool than with a cursor:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Expresson: NEWFIELD =&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;f(!CODEFIELD!)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Code block: &lt;/SPAN&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
def f(code):
&amp;nbsp; codelist = ['a','b','c']
&amp;nbsp; valuelist = [10,20,30]
&amp;nbsp; value = valuelist[codelist.index(code)] 
&amp;nbsp; return value
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Language: "PYTHON"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But I need to say that generally the best way to do this is to have a lookup table and use a join and Calculate Field to calculate values over.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:56:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/populate-one-field-based-on-second/m-p/236691#M18419</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-11T11:56:29Z</dc:date>
    </item>
  </channel>
</rss>

