修改response

This commit is contained in:
zhaojinghao 2022-12-12 09:51:49 +08:00
parent 5c19f8ec24
commit fa190dc1df
1 changed files with 6 additions and 4 deletions

10
run.py
View File

@ -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)