Hi,
Could you explain me, how to change field value with dictionaries?
for example :
dict = {"A" : "A-150",
"B" : "B-200",
"C" : "C-250"}
And i want change A with A-150, B with B-200
Thanks !
you still need the def example and you call it
if i is None:
<SPAN> row<N> = "NULL"</N></SPAN>
<SPAN>else:</SPAN>
<SPAN> row<N> = get_val</N></SPAN><SPAN>(</SPAN>i<SPAN>) # get)val is the def and it needs your dictionary</SPAN>
It has to be a piece of that script. You see like this part(code) if any row hasn`t a value, in CSV will write Null.
<SPAN class="keyword token">for</SPAN> n<SPAN class="punctuation token">,</SPAN>i <SPAN class="keyword token">in</SPAN> enumerate<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">if</SPAN> i<SPAN class="operator token">==</SPAN>None<SPAN class="punctuation token">:</SPAN> row<SPAN class="punctuation token">[</SPAN>n<SPAN class="punctuation token">]</SPAN><SPAN class="operator token">=</SPAN><SPAN class="string token">"NULL"</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
So I think I need only a couple lines of code to reach a goal.
Now I have this:
well it is clear now that you want to do this in a script, I thought you were wanting to do this in the field calculator. That is the part that wasn't clear.
You need to use the function (ie def ) with your dictionary to make the change within your tabletocsv function but I am not sure what it is doing there. Does this work without the conversion or is it an attempt to piece a script together?
Any ideas ?
Sorry, yeah I mean rows ... So like I said, I have 2000 rows and ~ 25 columns. One column is Values. So what expression would be the best ? Values column should have A-150, B-200, C-250 values. Not A,B,C. And I dont know solution for that...
2000 fields? Do you mean 2000 rows? Your statement "2000 Fields in Values Column" is confusing since field and column describes the same aspect of a table.
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">get_val</SPAN><SPAN class="punctuation token">(</SPAN>val<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">""" get a dictionary value"""</SPAN> dict <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="string token">"A"</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"A-150"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"B"</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"B-200"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"C"</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"C-250"</SPAN><SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">return</SPAN> dict<SPAN class="punctuation token">[</SPAN>val<SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># python parser</SPAN> <SPAN class="comment token"># field calculator code</SPAN> <SPAN class="comment token"># field calculator expression for a text field</SPAN> get_val<SPAN class="punctuation token">(</SPAN>!YourFieldNameHere!<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>
I know this, but what statement should be, if I have 2000 Fields in Values Column ? Every field in this column has A, B or C value. How to change values with dict in all 2000 fields ?
Or set it to anything.
dict<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"A"</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Anything you want it to be"</SPAN> <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN></SPAN>
Are you trying to retrieve the value?
dict <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="string token">"A"</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"A-150"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"B"</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"B-200"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"C"</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"C-250"</SPAN><SPAN class="punctuation token">}</SPAN> dict<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'A'</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># get its value</SPAN> <SPAN class="string token">'A-150'</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.