4
$\begingroup$

Here I learned that I can get the US population for every year that Wolfram has data on using the following:

CountryData["UnitedStates", {"Population", All}]

Next I wanted to find the population of Maryland for every year Wolfram has data on. The closest I can get is the following:

AdministrativeDivisionData

I tried the obvious approach, and got the following:

AdministrativeDivisionData fails

Wolfram-Alpha made a plot with data going back over 200 years, so Wolfram clearly has more than just the latest population. So how can I get a result for Maryland population that is similar to what I get from CountryData above?

$\endgroup$
3
$\begingroup$

A simple function does the job

pop[state_] :=
 Entity["AdministrativeDivision", {state, "UnitedStates"}][
   EntityProperty["AdministrativeDivision", 
    "Population", {"Date" -> All}]]["Path"]

Now for example

DateListPlot[pop["Utah"] /. Quantity[a_, __] :> a/10^6.,
 AspectRatio -> 1/2,
 Filling -> Bottom,
 GridLines -> Automatic]

enter image description here

Or

pop["Utah"] /. {a_, Quantity[b_, __]} :> {First@DateList@a, 
    PaddedForm[b/10^6., {3, 2}]} // Grid

enter image description here

$\endgroup$
  • $\begingroup$ Entity[...]["Path"] returns the dates in strange units, but the dates are useful if I use Entity["AdministrativeDivision", {"Maryland", "UnitedStates"}][ EntityProperty["AdministrativeDivision", "Population", {"Date" -> All}]][ "Path"] /. {date_, pop_} :> {First@DateList@date, pop} $\endgroup$ – Ted Ersek Aug 7 '17 at 10:18
  • $\begingroup$ Love the part about converting the graphic in WA into TimeSeriesData. $\endgroup$ – Ted Ersek Aug 7 '17 at 10:20
4
$\begingroup$

You can use free-form input to find this information:

Mathematica graphics

And similarly, with inline free-form input:

Mathematica graphics

We can inspect the entities involved to see how we could have specified it using code:

Mathematica graphics

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.