When retrieving curated data, v10 now returns TimeSeries objects.

For example,

ts = WeatherData["KP60", "Temperature", {{2013, 7, 1}, {2013, 9, 30}}]


What is the most convenient way to extract a range from this temporal data, for example for plotting purposes? E.g. only plot the first two weeks of August from this data.

I know I can simply convert it to a list using Normal and then use e.g. Select to filter. Is there anything better?

  • $\begingroup$ Congratulations on being our foremost question poster! $\endgroup$
    – Mr.Wizard
    Jul 27 '14 at 15:45
  • $\begingroup$ WeatherData fails when I try w/ 10.0.1: ibraryFunction::versint: The version number 1 of the library is from a previous WolframLibrary that cannot support integers as large as 4472425792. Anyone else? $\endgroup$ Sep 29 '14 at 17:43

One of the new operations on TimeSeries objects is TimeSeriesWindow. I think it does what you need.

ts = WeatherData["KP60", "Temperature", {{2013, 7, 1}, {2013, 9, 30}}];
DateListPlot[TimeSeriesWindow[ts, {{2013, 8, 1}, {2013, 8, 14}}]]

enter image description here

  • $\begingroup$ How do I get the results back into a TimeSeries? It's returning a different format causing subsequent errors in code that expects a TimeSeries. $\endgroup$
    – Michael
    Jul 11 at 17:09
  • $\begingroup$ @Michael, the TimeSeriesWindow argument to DateListPlot will be a TimeSeries. You might be using the DateListPlot output which is not a TimeSeries. $\endgroup$
    – david
    Jul 12 at 16:17
  • $\begingroup$ I'm actually using the output of FinancialData $\endgroup$
    – Michael
    Jul 14 at 19:44
  • $\begingroup$ I'm not sure what to say without more information. I do know that TimeSeriesWindow will return a TimeSeries when used as documented. $\endgroup$
    – david
    Jul 14 at 22:38

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.