Comments (2)
Looks like an interesting use case. I am working on some examples myself, but they won't be ready until next week.
To use Django REST Pandas in your project, the first thing to do would be to set up Django and Django REST Framework if you don't have them running already. (Even if you aren't using the Django ORM, these libraries are needed to set up the URL routing and request/response handling). As I noted in my reply to your tweet, DRP is optimized for the use case where the source data is coming out of a Django queryset. That said, there is a PandasSimpleView
precisely for the use case where you want to supply your own data. The class has a get_data
function that you can override with your own version, however it (currently) expects you to return a list of dictionaries which it will push into a dataframe for you.
I'll look into allowing you to return a pre-constructed dataframe from get_data
, but in the meantime you should be able to get it to work with something like this:
# views.py
from rest_framework.response import Response
from rest_pandas import PandasSimpleView
class MyDataView(PandasSimpleView):
def get(self, request, *args, *kwargs):
dataframe = my_dataframe_fn()
if "filter" in request.GET:
dataframe = dataframe[...]
return Response(dataframe)
You can then set up your urls.py
as in the README to allow specifying the renderer via a file-extension-like format suffix. FWIW, I've had the most success working with the CSV renderer (which uses dataframe.to_csv
behind the scenes). Since the CSV header generated by Pandas is often more complex than a simple list of columns, I'm also working on a d3 extension to load Pandas-style csv served up by DRP.
Thanks for your interest, I'll try to update the README with some of this information and get DRP out to PyPI within a week or so. Also, I am curious whether the Bokeh plotting server would meet your particular use case better - could you elaborate on why you want to serve up the dataframe separately?
from django-rest-pandas.
I added an example link to the README.
from django-rest-pandas.
Related Issues (20)
- Using a renderer in DRF settings for Excel output option HOT 5
- models with ID columns not named ID cause exception HOT 3
- Permission_class is ignored HOT 2
- Set filename in view HOT 1
- Use as a method in a ViewSet HOT 4
- license in pypi HOT 1
- Calling `PandasBaseRenderer().render(data)` throws `TypeError` HOT 2
- add Django 2.0 and DRF 3.8 to Travis tests HOT 2
- Response data is a ReturnList, not a DataFrame! Did you extend PandasMixin? HOT 2
- date_format not used when creating csv HOT 2
- how to return a json Response when query_params with 'format=xlsx' HOT 2
- Template does not exist rest_pandas.html HOT 1
- Links to `wq/chart.js` are no longer necessary in the README. HOT 1
- Not clear on how to return nested data
- how to pass id parameter example y = Times.objects.get(id=id) or Profile = Profile.objects.get(user=request.user) because i want individual chart for any user but i don't understand how to pass this parameters on pandas view
- Demo returns Access Denied
- Possible to Access ExcelRenderer from PandasSimpleView?
- Change comma separator from ',' to something else (e.g.: ';')
- make it Python 3.6 + django 2.2+ only
- Pypi release?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-rest-pandas.