Skip to content

Instantly share code, notes, and snippets.

@berellevy
Last active January 30, 2022 19:16
Show Gist options
  • Save berellevy/e02ce01cdcf60c2b807b9d286b1212df to your computer and use it in GitHub Desktop.
Save berellevy/e02ce01cdcf60c2b807b9d286b1212df to your computer and use it in GitHub Desktop.
Import pandas as pd
from django.db import models
class QuerySetWithDataFrame(models.QuerySet):
def df(self, *args, **kwargs):
return pd.DataFrame.from_records(self,
*args,
**kwargs)
# usage:
(Model.objects
.values() # necessary, see note below.
.df())
# IMPORTANT: This method is best for when you want to
# take a quick look at your data. Don't use this in production
# since there are some unexpected behaviors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment