pythonpandastime-seriesu8darts

Darts how to build Timeseries - ValueError: cannot reindex from a duplicate axis


I'm using DARTS to run forecasting model

I have two columns:

TIME, QUANTITY

value is allocated quarterly with missing value.

2006-01-01  13.0
2006-04-01   2.0
2007-0-01   3.0
2007-10-01  11.0

I want to build Timeseries

_df.index = _df[TIME]

series = TimeSeries.from_dataframe(_df, 
                                   #time_col=TIME, 
                                   value_cols=[QUANTITY], 
                                   freq='Q',
                                   fill_missing_dates=True)

series = fill_missing_values(series=series, fill=0.0)

and I got

/usr/local/lib/python3.8/dist-packages/pandas/core/indexes/base.py in
_can_reindex(self, indexer)    3281         # trying to reindex on an axis with duplicates    3282         if not self.is_unique and len(indexer):
-> 3283             raise ValueError("cannot reindex from a duplicate axis")    3284     3285     def reindex(self, target, method=None, level=None, limit=None, tolerance=None):

ValueError: cannot reindex from a duplicate axis

also removing comment

time_col=TIME, 

I got the same error.


Solution

  • Solved using pandas interpolation

    _df.index = _df[c_time]
    #_df = _df[c_quantity]
    _df = _df.resample('Q').sum().interpolate(method='time')