3
HEJは、すべての応答ストリームに直接書き込み、フラスコ:
私は場所でフラスコrestplusサーバーを持っていると私は私のクライアントへのオクテットストリームとしてExcelを提供するために達成しようとしています。大規模なDataFramesを直列化するとき、pandas.to_excel(..)は多くの時間(約120k行で30秒)を消費するようです。
私の現在の実装では、以下を参照してください。
def format(data_frame):
# Idea is to directly write to the flask output stream, instead of buffering
# the whole excel as io.BytesIO. Is there a way to do it?
output = io.BytesIO()
writer = pandas.ExcelWriter(output, engine='xlsxwriter')
data_frame_ordered = data_frame.reindex_axis(sorted(data_frame.columns), axis=1)
# This consumes a lot of time
data_frame_ordered.to_excel(writer, sheet_name='ML Data', na_rep=0, index=False, encoding='utf-8')
# This consumes a lot of time, too.
writer.save()
return output.getvalue()
@api.route('/excel', methods=['GET'])
class ExcelResource(Resource):
def get(self, args):
# Well, thats a huge pandas.DataFrame
data_frame = ...
resp = make_response(format(data_frame))
resp.headers['Content-Length'] = resp.content_length
resp.headers['Content-Type'] = 'application/octet-stream'
return resp
はBytesIOインスタンスにそれをバッファリングせずに、フラスコの出力ストリームに直接Excelを書くための方法はありますか?事前
デニス