5

I am trying to export the forecasts I made with Pytorch models in darts library to some exchangeable format like XLS or CSV.

Is it somehow possible to export the predictions from the Timeseries class? How can I specify output format?

TheMP
  • 8,257
  • 9
  • 44
  • 73

2 Answers2

9

Forecasts in Darts are nothing but regular TimeSeries objects and a TimeSeries is internally represented as a pandas.DataFrame.

You can access this DataFrame using series.pd_dataframe() (to get a copy of the DataFrame) or series._df directly if you want to avoid copying the DataFrame to save it. Be careful in the latter case however, as modifying the DataFrame in place will break the TimeSeries immutability.

You can then use any method you'd like to save pandas dataframes, e.g. pandas.DataFrame.to_csv() or pandas.DataFrame.to_pickle(). You can have a look at this article on Medium to see a comparison of a couple different formats' performances for saving and loading dataframes.

Nap
  • 145
  • 6
  • It saved entire data into xarray object into pandas (e.g. "\narray(8.25364938)\nCoordinates:\n datetime datetime64[ns] 2016-06-01\n component – user1098761 Nov 25 '22 at 01:43
  • The second proposed option of series._df does not seem valid (any more ?). I am with darts 0.24.0 – user3692662 Jul 14 '23 at 14:45
0

You can directly use .to_csv(), .to_json() or .to_pickle() on your time series.

See https://unit8co.github.io/darts/generated_api/darts.timeseries.html.

Ken Jiiii
  • 474
  • 9
  • 21