From fa190dc1dffd17911bced6d10c4d30259e535a85 Mon Sep 17 00:00:00 2001 From: zhaojinghao Date: Mon, 12 Dec 2022 09:51:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9response?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- run.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/run.py b/run.py index aa63fc1..406d76b 100644 --- a/run.py +++ b/run.py @@ -16,10 +16,14 @@ TEXT = "text" app = Flask(__name__) -def generate(data): +def generate(data: pd.DataFrame): # 用 StringIO 在内存中写,不会生成实际文件 out = io.StringIO() w = csv.writer(out) + w.writerow(data.columns.tolist()) # 先写入表头 + yield out.getvalue() + out.seek(0) + out.truncate(0) for i in range(data.shape[0]): # 对于 data 中的每一条 w.writerow(data.iloc[i].values.tolist()) # 传入的是一个数组 ['xxx','xxx@xxx.xxx'] csv.writer 会把它处理成逗号分隔的一行 # 需要注意的是传入仅一个字符串 '' 时,会被逐字符分割,所以要写成 ['xxx'] 的形式 @@ -133,9 +137,7 @@ def run_ts_predict(): try: data = pd.read_csv(data_file) logger.info(data.shape) - rest = run_prophet(data, period=int(period), freq=freq)[[ - 'ds', 'yhat' - ]] + rest = run_prophet(data, period=int(period), freq=freq) logger.info(rest.columns) rest['ds'] = rest['ds'].apply(str) rest['yhat'] = rest['yhat'].apply(str)