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.

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

  • $\begingroup$ The first code does not seem to work for me, I tried ctrl+c and ctrl+v and only got Grid[TimeSeries[...],Dividers->All]. $\endgroup$ – Skumin Feb 23 '15 at 12:14
  • $\begingroup$ @Skumin, for version 10, you can use Grid[{DateList[#][[;;3]],#2}&@@@Normal@wd, Dividers -> All] instead. $\endgroup$ – kglr Feb 23 '15 at 13:18
  • $\begingroup$ This works fine, thank you! $\endgroup$ – Skumin Feb 24 '15 at 8:18
  • $\begingroup$ @Skumin, glad it was useful. $\endgroup$ – kglr Feb 24 '15 at 8:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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