Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Using multiple variables to generate a table or csv

  1. May 20, 2012 #1
    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. If you enter:


    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.

    Thanks in advance,

  2. jcsd
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted