I am trying to pull items out of an attribute table. I want to pull out all county names that are in capital letters. I was using UPPER (County) = 'ANDREWS' but it was only pulling up Andrews. I need to pull up several different named counties.
No on to what you have to do... since I don't think you can do the query all at once.
Add a field to contain a string or boolean
Calculate the new field using
allcaps(!YourFieldNameHere')
and calculate into a boolean or string field. then you have a field for querying.
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">allcaps</SPAN><SPAN class="punctuation token">(</SPAN>a<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"""check for all caps"""</SPAN> uc <SPAN class="operator token">=</SPAN> <SPAN class="string token">'ABCDEFGHIJKLMNOPQRSTUVWXYZ'</SPAN> n <SPAN class="operator token">=</SPAN> len<SPAN class="punctuation token">(</SPAN>a<SPAN class="punctuation token">)</SPAN> m <SPAN class="operator token">=</SPAN> sum<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN>i <SPAN class="keyword token">in</SPAN> uc <SPAN class="keyword token">for</SPAN> i <SPAN class="keyword token">in</SPAN> a<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">return</SPAN> n <SPAN class="operator token">==</SPAN> m <SPAN class="comment token"># ---- test case </SPAN> a <SPAN class="operator token">=</SPAN> <SPAN class="string token">'ANDREWS'</SPAN> allcaps<SPAN class="punctuation token">(</SPAN>a<SPAN class="punctuation token">)</SPAN> <SPAN class="token boolean">True</SPAN> b <SPAN class="operator token">=</SPAN> <SPAN class="string token">'AnDrews'</SPAN> allcaps<SPAN class="punctuation token">(</SPAN>b<SPAN class="punctuation token">)</SPAN> <SPAN class="token boolean">False</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>
python lesson
I think the field calculator/query stuff supports the 'IN' operator.. what you want is to compare to the first value of the string to the capital letters in a list
A demo, but this can easily be made into a function if you don't want to copy ucl over obviously so your expression would be
'Yourfield'[0] in uc # or whatever surrounding characters are used for field names
uc <SPAN class="operator token">=</SPAN> string<SPAN class="punctuation token">.</SPAN>ascii_uppercase <SPAN class="comment token"># ---- make a list for future reference</SPAN> ucl <SPAN class="operator token">=</SPAN> list<SPAN class="punctuation token">(</SPAN>uc<SPAN class="punctuation token">)</SPAN> <SPAN class="string token">'ABCDEFGHIJKLMNOPQRSTUVWXYZ'</SPAN> <SPAN class="comment token"># ucl = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',</SPAN> <SPAN class="string token">'O'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'P'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Q'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'R'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'S'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'T'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'U'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'V'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'W'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'X'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Y'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'Z'</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># --- a test</SPAN> a <SPAN class="operator token">=</SPAN> <SPAN class="string token">'ANDREWS'</SPAN> <SPAN class="comment token"># now 'a' would be your field</SPAN> a<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">in</SPAN> ucl <SPAN class="token boolean">True</SPAN> a<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">in</SPAN> ucl <SPAN class="token boolean">True</SPAN> <SPAN class="comment token"># ---- a quick test for lowercase</SPAN> <SPAN class="string token">'b'</SPAN> <SPAN class="keyword token">in</SPAN> ucl <SPAN class="token boolean">False</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>
So there is not a simple syntax for inside the select by attributes??
Bummer!! Thanks for the help.
What if you calculated the names to be ALL UPPER CASE or All Proper Case? (Hmmmm.... sounds dangerously like a standard....)
Using the Python parser in the Field calculator:
(Pre-Logic Script Code box)
def myUpper(instring): x = instring.upper() return x<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
myUpper<SPAN class="punctuation token">(</SPAN>!YourFieldName!<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
changed slightly:
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">myProper</SPAN><SPAN class="punctuation token">(</SPAN>instring<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> x <SPAN class="operator token">=</SPAN> instring<SPAN class="punctuation token">.</SPAN>title<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">return</SPAN> x<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
myProper<SPAN class="punctuation token">(</SPAN>!YourFieldName!<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
I started with the field value of jose diablo and get JOSE DIABLO and Jose Diablo respectively....
as long as you leave the original field alone... and calculate in a new field... then you would have a choice... but what if they were to be all lower... or upper then lower... the possibilities are endless... there are so many 'standards' to choose from as one of our illustrious compatriots said
I'm an upper case kind of guy. The data bases I manage are UC. Nothing else....
I am too much pythonic... all lower case for me
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.