pythonpytorchu8darts

Exporting forecast data from darts


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?


Solution

  • 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.