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.
Solved! Go to Solution.
edited
same error
edited
just printed "complete" without printed values
Check your attribute table, should have populated it
the column has filled up but a huge number of invalid values in the median column
Wow looks awful.
I've edited the code to just spit out the values, -999 represents rows where no median could be computed.
again, it only prints 10,000 values instead of 18,000, without 0 and null
Edited. If that doesnt work try it on a subset of features, say 100
prints all values for which the median can be calculated and those for which cannot be calculated (as -9999). I exported the attribute table to Excel and pasted the values printed in Python IDLE and everything is fine now! Can you do it so that the values are directly saved in the ArcGIS attribute table?