如何在字典中循环数据框?蟒蛇

时间:2017-03-15 17:34:38

标签: python pandas dictionary for-loop

我在字典中存储了多个DataFrame,

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

字典看起来像这样,

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

我想写一个for循环来将每个DataFrame预测结果存储在列表或字典中。我就是这样做的,字典中的值是DataFrames,关键是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)

但是,在列表a = []中,重置索引而不是字典中的键。有没有办法用键存储结果作为参考索引?

0 个答案:

没有答案