我正在使用sub-daily data上的先知教程。我也使用默认的example_yosemite_temps.csv。我试图将ds和yhat预测数据导出到CSV文件。以下是我到目前为止的情况。出于某种原因,只有标题会保存到CSV。
如何将所有ds数据放入一列,将所有数据放入另一列?
import pandas as pd
import numpy as np
from fbprophet import Prophet
import csv
df = pd.read_csv('example_yosemite_temps.csv')
m = Prophet(changepoint_prior_scale=0.01).fit(df)
future = m.make_future_dataframe(periods=10, freq='H')
forecast = m.predict(future)
timestamp = forecast[['ds']]
tempFuture = forecast[['yhat']]
#print(timestamp)
#print(tempFuture)
rows = zip(timestamp,tempFuture)
with open('predict.csv', "w") as f:
writer = csv.writer(f)
for row in rows:
writer.writerow(row)
答案 0 :(得分:1)
找到解决方案:
forecast.to_csv('PredictOutput.csv')
http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_csv.html