Mathematica 9 is now available
Student Support Forum
Student Support Forum: 'Using items in a list as variables in a function' topicStudent Support Forum > General > Archives > "Using items in a list as variables in a function"

Next Comment >Help | Reply To Topic
Author Comment/Response
05/21/12 01:50am

Hi All,

I am new to mathematica and this kind of work in general, and was looking to score a little help on this thread. I basically need to build a data set that contains city information, country information, coordinates, and weather information. I want to do this using Mathematica's curated data sets. WeatherData, CityData, and CountryData. Below is what I have worked out so far:

{dateRange, mean, cdd, hdd, station, country, location, population,
reference = (65 - 32)/1.8, cumList},
station = "Chicago";
country = CityData[station, "Country"];
population = CityData[station, "Population"];
location = CityData[station, "Coordinates"];
GDPPerCapita = CountryData[country, "GDPPerCapita"];
dateRange = {{2011, 1, 1}, {2011, 12, 31}, "Day"};
mean = WeatherData[station, "MeanTemperature", dateRange];
cdd = Join[Transpose[{mean[[All, 1]]}],
Transpose[{Max[# - reference, 0] & /@ mean[[All, 2]]}], 2];
hdd = Join[Transpose[{mean[[All, 1]]}],
Transpose[{Min[# - reference, 0] & /@ mean[[All, 2]]}], 2];
cumList = Transpose[{Join[
Transpose[{cdd[[All, 1]]}],
Transpose[{Drop[FoldList[Plus, 0, cdd[[All, 2]] + hdd[[All, 2]]],
Grid[station, country, location, population, GDPPerCapita,

Which gives the following result...

Grid["Chicago", "UnitedStates", {41.8376, -87.6818}, 2695598, \
45230.2, {{{2011, 12, 31}, -2842.41}}]

Basically what I am looking for is a way to make the "station" variable, I want my function to cycle through all of the 160,000ish cities on the list and make a table record for each one.

The search term i want to use is simply the city name, all items in the list below

cityList = CityData[#, "Name"] & /@ CityData[]

I'm sure this is possible, but i am a complete newbie when it comes to anything like this, I thought I would seek some expert advice.

So to repeat myself, i just need the station name to be variable, and for the function to loop through all the cities, and to output to a table form or csv.

Thanks in advance,


URL: ,

Subject (listing for 'Using items in a list as variables in a function')
Author Date Posted
Using items in a list as variables in a function mlucas 05/21/12 01:50am
Re: Using items in a list as variables in a fun... yehuda 05/21/12 10:58pm
Next Comment >Help | Reply To Topic