I have been struggling all day with this. I wish Python were more like SQL it would be so easy for me, but I am still learning.

Basically, I just want to group numbers based on their first four digits, and then find the min and max of those numbers for each group.

Consider a dataset of doubles:


and the result I want is like this:

  • for all numbers begining with 1111, the minimum value is 11112222 and the maximum value is 11114444
  • for all numbers begining with 5555, the minimum value is 55556666 and the maximum value is 55558888

I have considered making a layer in ArcMap from my feature class and using SQL to select from there, but I just can't figure out the query it never seems to work.

I've spent most of my time trying a search cursor, but that is not working out very well for me either as I can't seem to use where clauses correctly.

Is there anyway I can just bring in the data as a list or dictionary or something and perform everything from there?

closed as off-topic by PolyGeo Apr 30 at 22:02

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "When seeking help to debug/write/improve code always provide the desired behavior, a specific problem/error and the shortest code (as formatted text, not pictures) needed to reproduce it in the question body. Providing a clear problem statement and a code attempt helps others to help you." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.


The query you want is like Value like "1111%" (% or * depending on the database).

I suggest add a field called FirstFour and calculate it to the first four digits:

FirstFour = left(str("Values"),4)

In VB, the default parser. Fairly similar in Python if you wish.

Then use summary statistics with min & max of values and case field of FirstFour.

Not the answer you're looking for? Browse other questions tagged or ask your own question.