Giter VIP home page Giter VIP logo

Comments (2)

sheppard avatar sheppard commented on May 10, 2024

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.

sheppard avatar sheppard commented on May 10, 2024

I added an example link to the README.

from django-rest-pandas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.