TimeSeries - Values & Dates



How can I display a TimeSeries object in a Table or Grid so that I could see the Dates and corresponding Values next to each other? I wrote the following code:

dates = Table[0, {i,Length[WeatherData["CYYZ","TotalPrecipitation",{{1985,1,1,0,0,0}{1986,1,1,0,0,0},"Day"}]["Dates"]]}]; Do[dates[[t]]=DateList[WeatherData["CYYZ","TotalPrecipitation",{{1985,1,1,0,0,0},{1986,1,1,0,0,0},"Day"}]["Dates"][[t]]],{t,1,Length[dates]}]; Transpose[{dates,WeatherData["CYYZ","TotalPrecipitation",{{1985,1,1,0,0,0},{1986,1,1,0,0,0},"Day"}]["Values"]}] // Grid

but it's, unfortunately, relatively time-demanding even when there are only approx. 365 values as in the example above. The main problem is that TableViewapparently does not accept the dates when they are in DateObject form.


Posted 2015-02-23T10:50:06.067

Reputation: 545



wd = WeatherData["CYYZ", "TotalPrecipitation", 
                {{1985, 1, 1, 0, 0, 0}, {1986, 1, 1, 0, 0, 0}, "Day"}];

Grid[wd, Dividers -> All]

enter image description here

Note: In version 10, you can use

Grid[{DateList[#][[;;3]], #2}& @@@ Normal @ wd, Dividers -> All]

If you have to use TableView, you can change the first column of wd to DateString or to String:

wda = MapAt[DateString, wd, {All, 1}];
wdb = MapAt[ToString, wd, {All, 1}];
Row[TableView /@ {wda, wdb}]

enter image description here

or to a DateString with date format of your choice, e.g.,

wdc = MapAt[DateString[#, {"{", "Year", ",", "Month", ",", "Day", "}"}] &, wd, {All, 1}];

enter image description here


Posted 2015-02-23T10:50:06.067

Reputation: 302 076

The first code does not seem to work for me, I tried ctrl+c and ctrl+v and only got Grid[TimeSeries[...],Dividers->All]. – Skumin – 2015-02-23T12:14:57.640

@Skumin, for version 10, you can use Grid[{DateList[#][[;;3]],#2}&@@@Normal@wd, Dividers -> All] instead. – kglr – 2015-02-23T13:18:54.097

This works fine, thank you! – Skumin – 2015-02-24T08:18:27.613

@Skumin, glad it was useful. – kglr – 2015-02-24T08:20:17.440