Skip to content

Instantly share code, notes, and snippets.

@c0ldlimit
Created March 14, 2013 19:00
Show Gist options
  • Save c0ldlimit/5164171 to your computer and use it in GitHub Desktop.
Save c0ldlimit/5164171 to your computer and use it in GitHub Desktop.
#python #flask #pandas Using flask to return a csv response from a dataframe
import StringIO
from flask import Flask, Response
@app.route('/some_dataframe.csv')
def output_dataframe_csv():
output = StringIO.StringIO()
some_dataframe.to_csv(output)
return Response(output.getvalue(), mimetype="text/csv")
@jackgolding
Copy link

In Python 3 this would be

from io import StringIO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment