Ouput a CSV of a Pandas Dataframe in Flask without tempfile
Looked for this damn thing everywhere. Was not keen on writing a tempfile!
def serve_csv(filename):
dataframe = filtered_dataframe(filename)
buffer = StringIO()
dataframe.to_csv(buffer,encoding='utf-8')
buffer.seek(0)
return send_file(buffer,
attachment_filename="test.csv",
mimetype='text/csv')
Written by monkee_magic
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Python
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#