I would like to know how to randomly select certain values from the attribute table.
A good discussion along with several good code examples can be found in previous threads, including https://community.esri.com/thread/121745 .
You can use the random module. Do you need random values in an attribute table? Or random rows?
I need to use it from python and not from ArcMap. Also, I just need to select the attributes and not assign random numbers to it.
Add a field to your table
Do a field calculation as described here
or you can substitute random.randint in place of random.random if you want integers.
a <SPAN class="operator token">=</SPAN> random<SPAN class="punctuation token">.</SPAN>randint<SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">100</SPAN><SPAN class="punctuation token">)</SPAN> a <SPAN class="number token">96</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
or even draw from a uniform distribution
u <SPAN class="operator token">=</SPAN> int<SPAN class="punctuation token">(</SPAN>random<SPAN class="punctuation token">.</SPAN>uniform<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">100</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> u <SPAN class="number token">54</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
or other types of distributions depending on your needs
The random module is a Python module.... Do you need to select random attributes from a single field? All fields? Some fields?
Please expand on your question. Give an example.
Ahhh, then generate your random integers, and use those in a search cursor to extract the values you need
Thank you so much. This seems to work for me.
Membros conectados podem postar, seguir atualizações e mais. Novo aqui? Registre uma conta gratuita.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.