# Extract data from WeatherData as a list of associations

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

-

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}]]

-
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. –  Pickett Aug 13 '14 at 14:36