Last active
January 30, 2022 19:16
-
-
Save berellevy/e02ce01cdcf60c2b807b9d286b1212df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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