Pandas in Django

339 views
Skip to first unread message

judy wawira

unread,
Mar 6, 2014, 9:44:13 PM3/6/14
to django...@googlegroups.com
Hello 

I have a CSV file that i wish to manipulate based on user inputs and show this on a Djnago project

I dont necessarily wish to save the data in the model 

Can anyone point me to a direction on how to do this 

I have tried creating a normal app like below but it says listmethod not found 

    mydf = pd.read_csv(file,header=1)

    #get header
    cols = list(mydf.columns.values)
    colheader = cols.tolist()

Alvin Lindstam

unread,
Mar 8, 2014, 5:16:59 AM3/8/14
to django...@googlegroups.com
Hello Judy.

You could increase the likelihood of a helpful response:

-Provide more of the code, such as relevant imports. 

-Provide the full error report when you get an exception (copy-pasted).

-Use the correct channel. It seems that you are using the pandas library and the code you included does not contain anything django-related. Does it run correctly outside of django? Perhaps the pandas community is a better forum for such issues? http://pandas.pydata.org/community.html

Perhaps this is your issue:
You call list(), which is a Python built in function that returns a list (unless you have written or imported your own list function). You then call the tolist method on that list, but lists doesn't have a tolist method (and I don't understand why you do it, since it's already a list).

judy wawira

unread,
Mar 8, 2014, 4:23:16 PM3/8/14
to django...@googlegroups.com
here is what i am trying to do 

I have an application that is django driven that allows users to upload a  csv file , and map concepts to export to a separate application .. essentially a middleware for data migration 
I would like to provide users with some summary analysis of their data in csv e.g missing values , mapped concepts, and i wish to use pandas for this task 
From the command line i am able to do the summary statistics, draw charts, but i am not able to do so in django.
I have checked out djnago-pandas , but this is for interacting with django models , and hence i would have to import csv data into the models to use this.
I am looking for examples where pandas is working within django, and for this method , i was trying to retirve the header and provide it as a list that i can manipulate in my app

Alex Mandel

unread,
Mar 8, 2014, 4:57:11 PM3/8/14
to django...@googlegroups.com
There is no reason to think you can't use Pandas or any other python
library within Django.

In your views.py or in a subfile that it references, import the library
you want, manipulate any objects in django or from the filesystem(in
this case I assume you've saved the csv somewhere django can see it,
real file or fileIO object), then return a result as part of the view.
Traditionally it would be to a rendertoresponse with a template, but
could be a json return if the page is calling it with ajax.

So as others have pointed out:
1. Do you have your csv already loaded as a python object
2. Can you show us the View code your using with Pandas

Thanks,
Alex
Reply all
Reply to author
Forward
0 new messages