【问题标题】:How to Get all the Output如何获取所有输出
【发布时间】:2018-11-04 12:59:44
【问题描述】:

假设我想预测给定随机行中的时间序列数据。假设 Index = (2000, 4000, 12000) ,这意味着我想预测第 2000、4000 和 12000 行的输出 以下是我的代码:

index = df['Index']
y=[]
for index in index:
    ind_1 = index - 1;
    ind = data.iloc[:ind_1]
    fit = SimpleExpSmoothing(ind).fit(smoothing_level=0.65,optimized=False)
    y = fit.forecast(1)
    y.append(y)

print(y)

但它只显示了第 12000 行的最后一个预测。

是否有可能知道如何在第 2000 行和第 4000 行获得其他输出?

谢谢。

【问题讨论】:

  • 请修正你的缩进。

标签: python pandas loops for-loop


【解决方案1】:

重命名您的y 列表 别的东西,它被覆盖了 - 你在这里改变它

y   = fit.forecast(1);

所以最后你要打印上面的最后一个输出。您一定没有粘贴所有代码,因为如果您附加到此处不是列表的任何内容,您会崩溃

y.append(y)

完整的修复如下

index = df['Index']

y = []
for index in index:
    ind_1 = index - 1;
    ind = data.iloc[:ind_1]
    fit = SimpleExpSmoothing(ind).fit(smoothing_level=0.65,optimized=False)
    x = fit.forecast(1)
    y.append(x)

print(y)

【讨论】:

  • 感谢您的评论。我仍然不清楚你的解释。你能详细说明一下或给我看一个例子吗?抱歉,我还是 python 新手。。谢谢。
猜你喜欢
  • 1970-01-01
  • 2023-03-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-21
  • 2016-11-06
  • 2018-07-04
  • 1970-01-01
相关资源
最近更新 更多