Thank you for sharing Gosia. The subject came up in a conversation with a friend this summer and I thought then: “I can compute the answer with the WL language”.
I would like to reply and expand on your post.
Now that you got me thinking about the subdivisions of the US states, I learned that most states in the US are subdivided into counties, except for Alaska and Louisiana which are called boroughs and parishes, resp.
I would like to reply and expand on your post.
Now that you got me thinking about the subdivisions of the US states, I learned that most states in the US are subdivided into counties, except for Alaska and Louisiana which are called boroughs and parishes, resp.
In[]:=
states=EntityClass["AdministrativeDivision","AllUSStatesPlusDC"]["Entities"];
The counties, parishes and boroughs can also be calculated with the entity property “Subdivisions” :
In[]:=
Out[]=
,,
In[]:=
Out[]=
,,
So the list of subdivision entities is simply this expression (which is slightly faster to calculate than mapping over an entity list of geoentities, and the result does not comprise of empty entities either).
In[]:=
subdivisions=["Subdivisions"]//Flatten;
If you remove the subdivision designations i.e. county or parish, we can focus on the most popular names given to US states’ subdivisions. This can be achieved within the entity framework too:
In[]:=
names=EntityValue[EntityClass[subdivisions,All],EntityFunction[a,StringTrim[#,(" County"|" Parish")]&@*First@StringSplit[#,","]&@*CommonName@a]];
In[]:=
PopularSubdivisionNames=ReverseSort@Counts@names;
The subdivisions that appear in at least 25 states gives me just three names, not five:
In[]:=
Select[#>=25&]@PopularSubdivisionNames
Out[]=
Washington31,Jefferson26,Franklin25
In[]:=
PieChart[Select[#>=25&]@PopularSubdivisionNames,ChartLabels->Automatic]
Out[]=
Some subdivisions share the name of a state: how many are there?
Some subdivisions share the name of a state: how many are there?
We’ll use the common names of the states to select the subdivisions in question:
In[]:=
StateNames=EntityValue[states,EntityFunction[a,First@StringSplit[#,","]&@*CommonName@a]]
Out[]=
{Alabama,Alaska,Arizona,Arkansas,California,Colorado,Connecticut,Delaware,District of Columbia,Florida,Georgia,Hawaii,Idaho,Illinois,Indiana,Iowa,Kansas,Kentucky,Louisiana,Maine,Maryland,Massachusetts,Michigan,Minnesota,Mississippi,Missouri,Montana,Nebraska,Nevada,New Hampshire,New Jersey,New Mexico,New York,North Carolina,North Dakota,Ohio,Oklahoma,Oregon,Pennsylvania,Rhode Island,South Carolina,South Dakota,Tennessee,Texas,Utah,Vermont,Virginia,Washington,West Virginia,Wisconsin,Wyoming}
Now we can calculate how many subdivisions with the same names as states there are:
In[]:=
sameNames=Select[MemberQ[StateNames,#]&]@names//Counts//ReverseSort
Out[]=
Washington31,Delaware6,Wyoming3,Ohio3,Texas2,Iowa2,Nevada2,Mississippi2,Utah1,Colorado1,Indiana1,Oklahoma1,Oregon1,Idaho1,Hawaii1,District of Columbia1,Arkansas1
What subdivisions have the same name as the state they belong to?
What subdivisions have the same name as the state they belong to?
First we will find all subdivision entities that share the name of a state:
First we will find all subdivision entities that share the name of a state:
In[]:=
stateNameEntities=FilteredEntityClass[EntityClass[subdivisions,All],EntityFunction[a,MemberQ[Keys@sameNames,StringTrim[#,(" County"|" Parish")]&@*First@StringSplit[#,","]&@*CommonName@a]]]["Entities"]
Out[]=
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
The subdivisions that have same name as that state they belong to, can now be filtered from the list of entities as so:
In[]:=
sameNameEntities=FilteredEntityClass[EntityClass[stateNameEntities,All],EntityFunction[a,SameQ[#[[1]],#[[2]]]&@StringTrim[#,(" County"|" Parish")]&@Part[#,1;;2]&@StringSplit[#,", "]&@CommonName@a]]["Entities"]
Out[]=
,,,,,,
