Calculating median in grouped data using ArcMap

6325
53
Jump to solution
01-31-2020 10:46 AM
RafaelMichael
Occasional Contributor

I got stuck when calculating the median age in grouped data (age ranges) for each feature (each feature is a single administrative unit). I have about 18,000 features.

Field names indicate age ranges: 0-14, 15-64, 65-100. In the "median" field I would like to calculate the median age for each feature. I found a website https://atozmath.com/StatsG.aspx?q=1 where you can calculate such a median for a single feature, for example the first feature from the attribute table above.

The page easily calculated the median for the first feature in the image, and the page also wrote how it calculated it, but I don't know how to write a universal script for a "median" field to calculate the median for each feature.

0 Kudos
53 Replies
RafaelMichael
Occasional Contributor

now there is an error with this file path

0 Kudos
RafaelMichael
Occasional Contributor

how to write it so that was good?

0 Kudos
DavidPike
MVP Frequent Contributor

Hi,

I've edited the original code to account for my stupidity.

Also you need to specify you path with 'r' then in quotes as per the code.

E.g.         r'c:/users/david/project.gdb'

RafaelMichael
Occasional Contributor

0 Kudos
DavidPike
MVP Frequent Contributor

Have you done as I said mate?

RafaelMichael
Occasional Contributor


my path looks like this and still error

0 Kudos
DavidPike
MVP Frequent Contributor

Can you export your shapefile to a feature class? Not sure what's wrong.

RafaelMichael
Occasional Contributor

0 Kudos
DavidPike
MVP Frequent Contributor

Haha, I've edited the original to count it as a list rather than new parameters. My bad.

RafaelMichael
Occasional Contributor

0 Kudos