Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Given weather data for 2013 and 2014 as follows:

t = 
    WeatherData["California", "MeanTemperature", {{2013, 1, 1}, {2014, 1, 1}, "Day"}] 

how can I get the average temperature for each day during 2 years as a list of associations, for example:

January 1 -> 12
 December 31 -> -20 
share|improve this question
up vote 6 down vote accepted

For me your command doesn't run. I run:

t = 
      {{2013, 1, 1}, {2014, 1, 1}, "Day"}

This contains all temperature quantities.

A list of dates in your period is easily constructed by

DateRange[DateObject[{2013, 1, 1}], DateObject[{2014, 1, 1}]]

so the association array you're looking for can be obtained from

    DateRange[DateObject[{2013, 1, 1}], DateObject[{2014, 1, 1}]] -> t


In fact, a neater way to achieve this is:

t = WeatherData["California", "MeanTemperature", {{2013, 1, 1}, {2014, 1, 1}, "Day"}];
Association[Rule @@@ MapAt[DateObject, t["Path"], {All, 1}]]
share|improve this answer
Thanks for the answer, but what if one of the years has February 29, how can that be considered for the calculation? – Mike Aug 13 '14 at 13:18
If the year is a leap year, like 2012, February 29 will be included in DateRange[{2012, 1, 1}, {2012, 12, 31}] automatically. Does that answer your question? – Thijs Aug 13 '14 at 13:22
Actually no, can I explain the question to you via pm? – Mike Aug 13 '14 at 13:24
Sure, but I don't know how that works :p – Thijs Aug 13 '14 at 13:27
You can create your own chat room here (Mike might need >10 rep to be able to participate). But @Mike if there is a problem with this answer you should make an effort to explain that here so that future visitors can see it. Welcome to MMA.SE. – C. E. Aug 13 '14 at 14:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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