Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using CountryData to Get US Population by State

66 views
Skip to first unread message

Gregory Lypny

unread,
Jun 2, 2012, 5:47:17 AM6/2/12
to
Hello everyone,

Can anyone help me with the syntax for CountryData so that I can get the population of individual US states?

Regards,

Gregory


Harvey P. Dale

unread,
Jun 3, 2012, 5:00:15 AM6/3/12
to
You could submit this query to WolframAlpha: "population of
states in the United States"
Best,
Harvey

Bob Hanlon

unread,
Jun 3, 2012, 5:02:49 AM6/3/12
to
statePopulations = {#, WolframAlpha[
"population of " <> #, {{"Result", 1}, "ComputableData"}]} & /@
DeleteCases[
CountryData["UnitedStates", "Regions"],
"DistrictOfColumbia"];


Bob Hanlon

Gregory Lypny

unread,
Jun 3, 2012, 5:04:21 AM6/3/12
to
You rock, Bob. I never would have figured this one out.

Gregory

Bob Hanlon

unread,
Jun 3, 2012, 4:03:38 PM6/3/12
to
After closer comparison between the two results, my original approach
provides erroneous results due to misinterpretation of names (e.g.,
New York resulted in the population of New York City rather than New
York State, Georgia resulted in Country of Georgia rather than US
state of Georgia). So Harvey's approach is not only faster it is
correct.


Bob Hanlon


On Sun, Jun 3, 2012 at 8:01 AM, Bob Hanlon <hanlo...@gmail.com> wrote:
> Harvey's solution is much faster than mine. Here is his in detail
>
> (statePopulations = WolframAlpha[
> "population of states in the United States",
> {{"PropertyRanking:USStateData", 1},
> "ComputableData"}]) // Grid
>
>
> Bob Hanlon
>
> On Sun, Jun 3, 2012 at 4:59 AM, Harvey P. Dale <hp...@nyu.edu> wrote:
>> You could submit this query to WolframAlpha: "population =
of
>> states in the United States"
>> Best,
>> Harvey
>>
>> -----Original Message-----
>> From: Gregory Lypny [mailto:GREGOR...@videotron.ca]
>> Sent: Saturday, June 02, 2012 5:45 AM
>> To: math...@smc.vnet.net
>> Subject: Using CountryData to Get US Population by State
>>
>> Hello everyone,
>>
>> Can anyone help me with the syntax for CountryData so that I can get the
>> population of individual US states?
>>
>> Regards,
>>
>> Gregory
>>
>>
>>
>
>
>
> --
> Bob Hanlon



--
Bob Hanlon

Bob Hanlon

unread,
Jun 3, 2012, 4:03:07 PM6/3/12
to
Harvey's solution is much faster than mine. Here is his in detail

(statePopulations = WolframAlpha[
"population of states in the United States",
{{"PropertyRanking:USStateData", 1},
"ComputableData"}]) // Grid


Bob Hanlon

On Sun, Jun 3, 2012 at 4:59 AM, Harvey P. Dale <hp...@nyu.edu> wrote:
> You could submit this query to WolframAlpha: "population o=

Kevin J. McCann

unread,
Jun 3, 2012, 4:04:09 PM6/3/12
to
An observation about the results: all of the states have integer
populations except Georgia, which is floating point. Curious.

Kevin

Gregory Lypny

unread,
Jun 4, 2012, 4:20:18 AM6/4/12
to
Thanks again, Bob. And thank you, Harvey. At first I did not appreciate how to turn your Wolfram Alpha query into a Mathematica statement.

Regards,

Gregory


On Sun, Jun 3, 2012, at 8:45 AM, Bob Hanlon wrote:

> After closer comparison between the two results, my original approach
> provides erroneous results due to misinterpretation of names (e.g.,
> New York resulted in the population of New York City rather than New
> York State, Georgia resulted in Country of Georgia rather than US
> state of Georgia). So Harvey's approach is not only faster it is
> correct.
>
>
> Bob Hanlon
>
>
> On Sun, Jun 3, 2012 at 8:01 AM, Bob Hanlon <hanlo...@gmail.com> wrote:
>> Harvey's solution is much faster than mine. Here is his in detail
>>
>> (statePopulations = WolframAlpha[
>> "population of states in the United States",
>> {{"PropertyRanking:USStateData", 1},
>> "ComputableData"}]) // Grid
>>
>>
>> Bob Hanlon
>>
>> On Sun, Jun 3, 2012 at 4:59 AM, Harvey P. Dale <hp...@nyu.edu> wrote:
>>> You could submit this query to WolframAlpha: "population of
>>> states in the United States"
>>> Best,
>>> Harvey
>>>
>>> -----Original Message-----
>>> From: Gregory Lypny [mailto:GREGOR...@videotron.ca]
>>> Sent: Saturday, June 02, 2012 5:45 AM
>>> To: math...@smc.vnet.net
>>> Subject: Using CountryData to Get US Population by State
>>>
>>> Hello everyone,
>>>
>>> Can anyone help me with the syntax for CountryData so that I can get the
>>> population of individual US states?
>>>
>>> Regards,
>>>
>>> Gregory
>>>
>>>
>>>
>>
>>
>>

Hobbs, Sylvia (DPH)

unread,
Jun 4, 2012, 4:20:49 AM6/4/12
to
or input in Mathematica = state population rankings

too bad it doesn't automatically create a gradient map like is SAS or STATA.

Sylvia D. Hobbs, MPH

Director of Research & Evaluation
Bureau of Health Care Safety and Quality
Massachusetts Department of Public Health
99 Chauncy Street, 11th Floor
Boston MA 02111
________________________________________
From: Bob Hanlon [hanlo...@gmail.com]
Sent: Sunday, June 03, 2012 4:02 PM
Subject: Re: Using CountryData to Get US Population by State

Bob Hanlon

unread,
Jun 5, 2012, 4:53:05 AM6/5/12
to
statePopulationData =
WolframAlpha[
"population of states in the United States", \
{{"PropertyRanking:USStateData", 1}, "ComputableData"}];

statePopulations = Thread[
statePopulationData[[All, 2]] ->
statePopulationData[[All, 3]]];

maxPopulation = Max[statePopulationData[[All, 3]]];
minPopulation = Min[statePopulationData[[All, 3]]];

statePopulationRankings = Thread[
statePopulationData[[All, 2]] ->
statePopulationData[[All, 1]]];

usaMapData =
Import["http://code.google.com/apis/kml/documentation/us_states.kml",
"Data"][[1]];

states = StringDrop[#, -7] & /@ ("PlacemarkNames" /. usaMapData);

statePolygons = Thread[states -> ("Geometry" /. usaMapData)];

color = ColorData["Temperature"];

stateGraphic[value_, poly_] :=
GraphicsGroup[{EdgeForm[{Thin, Black}], FaceForm[color[value]], poly}]


Color by population ranking

Graphics[stateGraphic @@@
({1 - Rescale[#, {1, 50}] /.
statePopulationRankings,
# /. statePolygons} & /@
states)]


Color by population

Graphics[stateGraphic @@@
({Rescale[#, {minPopulation, maxPopulation}] /.
statePopulations,
# /. statePolygons} & /@ states)]


Bob Hanlon


On Mon, Jun 4, 2012 at 4:20 AM, Hobbs, Sylvia (DPH)
<sylvia...@state.ma.us> wrote:
> or input in Mathematica = state population rankings
>
> too bad it doesn't automatically create a gradient map like is SAS or STATA.
>
> Sylvia D. Hobbs, MPH
>
> Director of Research & Evaluation
> Bureau of Health Care Safety and Quality
> Massachusetts Department of Public Health
> 99 Chauncy Street, 11th Floor
> Boston MA 02111
> ________________________________________
> From: Bob Hanlon [hanlo...@gmail.com]
> Sent: Sunday, June 03, 2012 4:02 PM
> To: math...@smc.vnet.net
0 new messages