Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ReedJessen/5abb06f78c045573d93c7c570e887e4b to your computer and use it in GitHub Desktop.
Save ReedJessen/5abb06f78c045573d93c7c570e887e4b to your computer and use it in GitHub Desktop.
Serve pandas dataframe as csv with Django
from django.http import HttpResponse
import pandas as pd
def foo():
your_dataframe = pd.Dataframe()
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename=filename.csv'
results.to_csv(path_or_buf=response,sep=';',float_format='%.2f',index=False,decimal=",")
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment