Registry / data / django-pandas

django-pandas

JSON →
library0.6.7pypypiunverified

django-pandas provides tools to seamlessly integrate Django models with Pandas DataFrames. It allows you to query your Django models and return the results directly as Pandas DataFrames, simplifying data analysis, reporting, and machine learning workflows within Django projects. As of version 0.6.7, it's actively maintained with releases focused on compatibility with recent Django and Pandas versions.

pip install django-pandas
INSTALL
IMPORT
SIG · DJANGO-PANDAS
D
django-pandas
datapythonv0.6.7
Install
7.7s avg
Import
—
Disk
164MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.6.7 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 164.8MB
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 7.7s · import 0.000s · 157MB
164MB installed
● package 164MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

DataFrameManager
✓ from django_pandas.managers import DataFrameManager
✗ from django_pandas.managers import DataFrameManager

To use django-pandas, add `objects = DataFrameManager()` to your Django model. Then, you can call `.to_dataframe()` on your model's manager or any QuerySet to convert the results into a Pandas DataFrame. Remember to ensure your Django app is configured and migrations are run.

from django.db import models from django_pandas.managers import DataFrameManager # Define a simple Django model class Product(models.Model): name = models.CharField(max_length=255) price = models.DecimalField(max_digits=10, decimal_places=2) stock = models.IntegerField(default=0) last_updated = models.DateTimeField(auto_now=True) # Attach DataFrameManager to your model objects = DataFrameManager() def __str__(self): return self.name # --- Usage example (in a Django shell or view) --- # Make sure to run migrations for the Product model first. # from myapp.models import Product # Assuming Product is in 'myapp' # Product.objects.create(name='Laptop', price=1200.00, stock=50) # Product.objects.create(name='Mouse', price=25.50, stock=200) # Fetch data directly as a Pandas DataFrame # df = Product.objects.to_dataframe() # print(df.head()) # You can also filter before converting to DataFrame # low_stock_df = Product.objects.filter(stock__lt=100).to_dataframe() # print(low_stock_df)
Debug
Known issues
gotchaConverting very large QuerySets to DataFrames directly can consume significant memory and impact performance, especially for tables with millions of rows. Consider filtering or chunking your data.
fix
Apply `.filter()` or `.values()` to select specific rows/columns before calling `.to_dataframe()`. For extremely large datasets, consider iterating over chunks or using database-level aggregations first.
affects: All versions
gotchaBy default, `to_dataframe()` does not automatically include related fields (e.g., ForeignKeys) as their actual values; it typically includes their IDs. To include related object data, you need to specify them.
fix
Use the `related` argument in `to_dataframe()` (e.g., `to_dataframe(related=['foreign_key_field__name'])`) or use `.select_related()` on your QuerySet before calling `to_dataframe()` for one-to-one/many-to-one relationships, or `.prefetch_related()` for many-to-many/one-to-many.
affects: All versions
breakingdjango-pandas has specific compatibility requirements for Django and Pandas versions. Using incompatible versions can lead to unexpected errors or silent failures.
fix
Always check the `install_requires` in the `pyproject.toml` or `setup.py` on the GitHub repository for the exact version ranges supported. As of 0.6.7, Django>=2.2 and pandas>=1.0 are required. Upgrade or downgrade your Django/Pandas installations as necessary.
affects: <0.6.0 (older Django/Pandas versions), >0.6.7 (future versions)
Upgrade
Version history
0.6.7latest on PyPI · released Apr 3, 2024
Audit
Dependencies
DjangorequiredRequired for integration with Django projects (>=2.2)
pandasrequiredCore data structure and analysis library (>=1.0)
Agent activity
38 hits · last 30 days
node
32
OpenAI (training)
1
Resources
django-pandas — pip install django-pandas · libregistry