I am working with Arcgis 10.3 and currently this problem keeps me awake at night. I import a csv file into ARCGIS with XY-coordinates and the Age of a person. I create a feature class which i later join with a layer file containing county boundaries. What i would like to know is how many Persons in a county fall in a certain age class.

My Goal is to get a table that groups the persons in a county in various age groups.

Name       Age0-30    Age31-60     AgeOver60
county1     25            10           9
county2     12            54           60

Is this possible and how?

1 Answer 1


I'm thinking this is possible, using a few steps. I'm seeing you have already added the CSV file as point events using Add XY Data, and have also exported it to a permanent feature class, let's call this feature class Persons, and assume it lines up nicely in with your CountyPolygons layer in terms of projection.

Next, you're joining Name information from CountyPolygons to Persons via a spatial join, we will call your output PersonsJoined. Using the ArcMap Python window, or by feeding these arguments to the Spatial Join geoprocessing tool gui we would run:

SpatialJoin_analysis('Persons', 'CountyPolygons', 'PersonsJoined')

If you follow these arguments verbatim the spatial join tool is going to dump PersonsJoined at the default geodatabase location, this can be set in the ArcCatalog window or by using:

arcpy.env.workspace = 'Z:\\My_Path\\To_Workspace\\Stuff.gdb' 

The PersonsJoined feature class should carry a value for Name for each point, based on the CountyPolygon it fell in during the spatial join.

For your analysis goal, you're interested in a count of persons in each of three age range categories (0-30, 31-59, 60+). We need to tag each of the PersonsJoined points with a field value marking their participation in a given age group. Add 3 fields for these 1/0 tags:


Then you can use an UpdateCursor to tag/flag each person record by age category:

cursor = arcpy.da.UpdateCursor('PersonsJoined',['Age','Age0_30',
                                                'Age31_59', 'Age60_plus'])

for row in cursor:
    if row[0] <= 30:
        row[1] = 1
        row[2] = 0
        row[3] = 0
    elif row[0] > 30 and row[0] <60:
        row[1] = 0
        row[2] = 1
        row[3] = 0
    elif row[0] >= 60:
        row[1] = 0
        row[2] = 0
        row[3] = 1

Now each PersonsJoined record has a flag denoting its appropriate age group.

Lastly, we can get a total count of age group flags, per-age group, on a per-county basis Summarize function in the PersonsJoined attribute table on the Name field. Check the boxes to return a SUM of Age0_30, Age31_59, and Age60_plus fields in the output table of your Summarize tool run.

Best Luck with this. Sometimes it's easier in situations like this one to do the spatial joining in GIS and then export the PersonsJoined table into a database environment, where you could get similar results using logical comparisons and GROUP BY statements. Today we used GIS for it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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