Hello,
I am trying to use python dictionaries to change the feature values of different fields.
I created the script below to change the feature values of a field called "DOR_UC" and as you can see there is a list of other fields where I need to do something similar - that's why there is a long list of other fields.
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="comment token"># script to assign values to features in one field based on a value in the dictionary</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"D:\APRX_MXDS\USA_Parcels_2019_Project\test_featureclasses.gdb"</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>overwriteOutput <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
<SPAN class="comment token"># feature class</SPAN>
fc <SPAN class="operator token">=</SPAN> <SPAN class="string token">"testing_fc"</SPAN>
<SPAN class="comment token"># printing all fields in fc</SPAN>
fields <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>f<SPAN class="punctuation token">.</SPAN>name <SPAN class="keyword token">for</SPAN> f <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFields<SPAN class="punctuation token">(</SPAN>fc<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>fields<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># dictionary</SPAN>
uses <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="string token">"000"</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"Vacant Residential – with/without extra features"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"001"</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"Single Family"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"002"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"Mobile Homes"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"003"</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"Multi-family - 10 units or more"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"004"</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"Condominiums"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"005"</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"Cooperatives"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"006"</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"Retirement Homes not eligible for exemption"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"007"</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"Miscellaneous Residential (migrant camps, boarding homes, etc.)"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"008"</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"Multi-family - fewer than 10 units"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"009"</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"Residential Common Elements/Areas"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"010"</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"Vacant Commercial - with/without extra features"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"011"</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"Stores, one story"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"012"</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"Mixed use - store and office or store and residential combination"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="comment token"># dictionary keys to list</SPAN>
usesKey <SPAN class="operator token">=</SPAN> list<SPAN class="punctuation token">(</SPAN>uses<SPAN class="punctuation token">.</SPAN>keys<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># dictionary values to list</SPAN>
usesvalues <SPAN class="operator token">=</SPAN> list<SPAN class="punctuation token">(</SPAN>uses<SPAN class="punctuation token">.</SPAN>values<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># List of fields</SPAN>
fields <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"BAS_STRT"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"DOR_UC"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"TEST"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"PAR_SPLT"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"CONST_CLASS"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"IMP_QUAL"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"M_PAR_SAL1"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"QUAL_CD1"</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>UpdateCursor<SPAN class="punctuation token">(</SPAN>fc<SPAN class="punctuation token">,</SPAN> fields<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> cursor<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> cursor<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> usesKey <SPAN class="keyword token">in</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">:</SPAN>
row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> usesvalues
cursor<SPAN class="punctuation token">.</SPAN>updateRow<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN> Field DOR_UC currently has some codes that I need to convert into a sentence.
See image below for fc attribute's table:

Each of those codes has a meaning in the form of a sentence. I need to assign their meaning and delete the codes.
To do this I've created a dictionary where the key is the code and the value is the sentence (See attached csv).
To start testing the script I created a field called "TEST" where I want to put the value part of the dictionary.
So the code would go something like this:
If a feature in field DOR_UC is equal to 000 then the feature value in field TEST would be "Vacant Residential - with/without extra features".
When I try to run the code I am getting this first error:
Traceback (most recent call last):
File "D:/APRX_MXDS/USA_Parcels_2019_Project/Scripts/Dictionary Key() method_2.py", line 44, in <module>
for row in cursor:
RuntimeError: A column was specified that does not exist.<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>The weird thing is that I have both of the columns.
Not sure how to solve this.
Also, not sure if the overall code has more errors.
Could someone help me with this? I need to finish this today and I have no idea on how to continue.
thank you!