I am an aspiring data scientist who's working on a passion project, namely to assign danger-level scores to police departments in the United States.

One specific metric I'm developing results from analyzing data on fatal encounter incidents with police since 2000, including the name of the specific agency involved in the death(s), which I've imported as strings, stripped of qualifiers like "Police Department" (among others), and arranged into a list called dept.

For example, take the first element of the list, "Mendocino County Sheriff's Office", which then becomes "Mendocino County", the geographic area I want to know the population of. This is simple enough with semantic interpretation, i.e.,

jurisdiction = SemanticInterpretation[dept[[1]]]

(* output: Entity["AdministrativeDivision", {"MendocinoCounty", "California", 
  "UnitedStates"}] *)

To get the population:

population = AdministrativeDivisionData[jurisdiction, "Population"]

(* output: 87649 people *)

From here it's trivial to calculate my "danger" index for that department and expand to do the calculation for all incidents.

deathCounts = Values[Counts[dept]];
dangerCalc[i_] := Module[{jur, pop, dVal},
   jur = SemanticInterpretation[dept[[i]]];
   pop = QuantityMagnitude[AdministrativeDivisionData[jur, "Population"]];
   dVal = N[deathCounts[[i]]/pop*100];

However, I run into problems trying to apply this same process to non-county jurisdictions (testing the first 100 entries). As an example, the second incident is Highland Park (a city). With dept[[2]] being "Highland Park", I get:

danger = {};
For[i = 1, i < 101, ++i, AppendTo[danger, dangerCalc[i]]];

(* output: 


AdministrativeDivisionData::notent: Highland Park is not a known entity, class, or tag for AdministrativeDivisionData. Use AdministrativeDivisionData[] for a list of entities.



This seems to be related to different classifications like "City", etc. I'm a total novice in this area of Mathematica, so I have little to no clue how to handle varying geographic regions uniformly. I had success with Highland Park by testing:


(* output: Entity["City", {"HighlandPark", "Illinois", "UnitedStates"}] *)

Obviously this doesn't fit neatly into my current code, and given the multiplicity of different inputs, I'm unsure how to create a general-handling function accounting for all possibilities.

Mathematica's built-in functions are so numerous, and the semantic interpretation is so sophisticated that I have no idea how to proceed. The "Entity" and other classifiers confuse me conceptually; in plain English, I want to get the population of cities, counties, states, townships, districts, etc. without knowing ahead of time which category each list element belongs to.

Can anyone more knowledgeable than myself suggest a path forward?

  • $\begingroup$ just to clarify: is dept a list which contains a string referring to a jurisdiction once for each death in that jurisdiction? $\endgroup$
    – thorimur
    Jan 4, 2021 at 4:28
  • 1
    $\begingroup$ also, btw, hope you don't mind me mentioning: the table danger can be more easily written as Table[dangerCalc[i], {i,100}]! $\endgroup$
    – thorimur
    Jan 4, 2021 at 4:30

1 Answer 1


Try appending " Population" after your strings and let SemanticInterpretation do the work for you?
This seems to work for the two inputs in OP:

SemanticInterpretation["Mendocino County Population"]
SemanticInterpretation["Highland Park Population"]

Out[7]= Quantity[87649, "People"]

Out[8]= Quantity[29767, "People"]

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.