# Using multiple variables to generate a table or csv

#### mlucas

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:

Module[
{dateRange, mean, cdd, hdd, station, country, location, population,
GDPPerCapita,
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]]],
1]}],
2]}];
Grid[station, country, location, population, GDPPerCapita,
Last[cumList]]]

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. If you enter:

CityData[]

the output looks like this {City, Region, Country} (for all of the cities in the world)

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 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.

Matt

Related Math Software Workshop News on Phys.org

"Using multiple variables to generate a table or csv"

### Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving