由于“未定义名称'结果'”而出现错误

时间:2019-11-11 00:01:30

标签: python facebook-prophet

我正在运行以下代码:

import pandas as pd
from fbprophet import Prophet
data = pd.read_csv(r'C:\Users\XXX.csv')
ids = data['id'].unique()
series = []
for id in ids:
   f = data[data['id'] == id]
   frames.append(f)

def run_prophet(timeserie):
    model = Prophet(yearly_seasonality=False,daily_seasonality=False)
    model.fit(timeserie)
    forecast = model.make_future_dataframe(periods=90, include_history=False)
    forecast = model.predict(forecast)
    return forecast

results = list(map(lambda timeserie: run_prophet(timeserie), series))

result[0] 
result[1] 

但是在result [0]之后,出现错误“名称'result'未定义”。我能做什么?谢谢

数据的结构为:

id        ds        y
id_1  2017-01-01    11
id_2  2017-01-01    13

2 个答案:

答案 0 :(得分:0)

该变量应命名为“结果”而不是“结果”。我还要指出,熊猫有一个apply方法https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.apply.html

答案 1 :(得分:0)

让您最后2行替换为:

results[0] 
results[1]