POST
|
You could pretty easily populate the column by copying and pasting the printed values into your blank column whilst editing the table. Are they correct?
... View more
01-31-2020
04:47 PM
|
2
|
1
|
579
|
POST
|
Wow, I'd test the results against your website, bear in mind it may have calculated lower class boundaries different from what you expected. Basically test quite a few features to see if correct result
... View more
01-31-2020
04:40 PM
|
2
|
1
|
579
|
POST
|
What's the names of your columns? Are those aliases? I was guessing the spaces were underscores. Replace the names in the 'with arcpy.searchcursor ' line with their proper names
... View more
01-31-2020
04:06 PM
|
2
|
1
|
579
|
POST
|
Haha, I've edited the original to count it as a list rather than new parameters. My bad.
... View more
01-31-2020
03:56 PM
|
2
|
9
|
756
|
POST
|
Can you export your shapefile to a feature class? Not sure what's wrong.
... View more
01-31-2020
03:34 PM
|
2
|
11
|
756
|
POST
|
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'
... View more
01-31-2020
03:04 PM
|
2
|
15
|
756
|
POST
|
Sorry change all those double equal signs to one equals sign up to and including line13
... View more
01-31-2020
02:39 PM
|
2
|
18
|
2379
|
POST
|
Rafael, Unfortunately I dont have a home license for arcmap to test this. Do you have an IDE? If not I cant talk you through making it as a tool
... View more
01-31-2020
02:13 PM
|
2
|
22
|
2379
|
POST
|
import arcpy
input_table = r'put the path to your table here'
#lcb is the lower class boundary
width_age_range_1 = 14.5
lcb_age_range_1 = 0.0
width_age_range_2 = 50.0
lcb_age_range_2 = 14.5
width_age_range_3 = 35.5
lcb_age_range_3 = 64.5
median_list = [ ]
with arcpy.da.SearchCursor(input_table, ["TOT", "TOT_0_14", "TOT_15_64", "TOT_65"]) as cursor :
for row in cursor :
#if all numeric fields hopefully
n_over2 = (row[0]/2.0)
if row[1] >= n_over2 :
#cumulative freq of groups before median group
cumu_freq = 0.0
if row[1] != 0.0 :
median = lcb_age_range_1 + ( ((n_over2 - cumu_freq)/row[1]) * width_age_range_1)
median_list.append(median)
continue
continue
if (row[1] + row[2]) >= n_over2 :
#cumulative freq of groups before median group
cumu_freq = row[1]
if row[2] != 0.0 :
median = lcb_age_range_2 + ( ((n_over2 - cumu_freq)/row[2]) * width_age_range_2)
median_list.append(median)
continue
continue
if (row[1] + row[2] + row[3]) >= n_over2 :
#cumulative freq of groups before median group
cumu_freq = row[1] + row[2]
if row[3] != 0.0 :
median = lcb_age_range_3 + ( ((n_over2 - cumu_freq)/row[3]) * width_age_range_3)
median_list.append(median)
continue
continue
else:
median_list.append("error")
for median in median_list :
print(median)
#obviously can add a field and append these values in rather than printing them. look at arcpy.da.UpdateCursors
... View more
01-31-2020
12:04 PM
|
3
|
24
|
2379
|
POST
|
It's not actually too hard. N/2 will be the cumulative frequency you're looking for, so a search cursor and a few conditional statements should find your median group. Then just plug that group's range and upper and lower bands into the grouped median formula. I can write it out if you like.
... View more
01-31-2020
11:19 AM
|
2
|
26
|
2379
|
Title | Kudos | Posted |
---|---|---|
1 | 02-06-2021 09:35 AM | |
1 | 05-19-2021 01:44 PM | |
1 | 02-22-2024 12:10 PM | |
1 | 02-16-2024 11:52 AM | |
1 | 02-16-2024 11:45 AM |
Online Status |
Offline
|
Date Last Visited |
07-02-2024
01:56 PM
|