Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Given weather data for 2013 and 2014 as follows:

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

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

1 Answer 1

up vote 5 down vote accepted

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

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

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

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

edit

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 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 at 13:22
    
Actually no, can I explain the question to you via pm? –  Mike Aug 13 at 13:24
    
Sure, but I don't know how that works :p –  Thijs Aug 13 at 13:27
1  
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. –  Pickett Aug 13 at 14:36

Your Answer

 
discard

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.