0

I stored multiple DataFrames in a dictionary,

df_dict = {product: product_df.drop(['productID', 'productName'],axis = 1).sort(['date'])
          for product, product_df in products}

The dictionary looks like this,

Key   Type      Size           Values
1   DataFrame  (100,2)  Column names: date, sales
2   DataFrame  (130,2)  Column names: date, sales
3   DataFrame  (115,2)  Column names: date, sales
4   DataFrame  (137,2)  Column names: date, sales

I would like to write a for loop to store each DataFrame forecasting results in a list or a dictionary. This is how I did it, the value in the dictionary is DataFrames and the key is productID

a = []
for key, value in df_dict:
    m = Prophet()
    m.fit(value)
    future = m.make_future_dataframe(periods = 365)
    forecast = m.predict(future)
    a.append(forecast)

However, in the list a = [], the index is reset rather than the keys in a dictionary. Is there any ways to store the results with keys as reference index?

Peggy
  • 143
  • 3
  • 14
  • Please look at (and post) the complete stack trace. It will tell you which lines of your programs are responsible for the error. – DYZ Mar 15 '17 at 17:48
  • Iterating directly over a dictionary iterates over its *keys* – juanpa.arrivillaga Mar 15 '17 at 18:05
  • @juanpa.arrivillaga Thank you for the information. It took time to iterate over a dictionary with 100+ DataFrames. Will try other ways to see if the run time improves. – Peggy Mar 15 '17 at 18:57
  • The time it takes to actually loop over the 100 keys in a dictionary is trivial. If you must optimize, you should probably check whatever is going in inside your loop body. I dig the name `Prophet` by the way. – juanpa.arrivillaga Mar 15 '17 at 19:18

0 Answers0