Pandas in Django

462 views
Skip to first unread message

judy wawira

unread,
Mar 6, 2014, 9:43:36 PM3/6/14
to pyd...@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()

Judy

Juan Na

unread,
Mar 7, 2014, 2:54:15 AM3/7/14
to pyd...@googlegroups.com
Hi Judy,

Perhaps I don't understand your question. That I see is: .tolist() is a numpy method, but in your example 'cols' is a list not a numpy array. If you try to obtain a list of name of headers, 'cols' is this list.

Juan

judy wawira

unread,
Mar 7, 2014, 6:54:00 PM3/7/14
to pyd...@googlegroups.com
but the cols list would not be displayed on the Django app.

judy wawira

unread,
Mar 8, 2014, 4:24:05 PM3/8/14
to pyd...@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

Juan Na

unread,
Mar 9, 2014, 5:02:52 AM3/9/14
to pyd...@googlegroups.com
Pandas with Django can work in the same way that in the command line, the only different thing is how show the data in a web page. For example, you have a .csv file. Your read the data, and show this summary. For this, if you know Django, you make a view that will show when is solicited via http.

#in Django views
def mydescribe_view(request):
       df=df.read_csv ('mifile.csv')
       dfd=df.describe()
       ctx={'mydesc':dfd.to_html()}
       return render_to_response('mypage.html',ctx,context_instance= RequestContext(request))

#in the template: mypage.html
....
<b>This is the summary of the data</b>
{{ mydesc | safe }}
....

#the safe option is for Django accept html simbols like '<'
#in the render process, Django will substitute {{ mydesc | safe }} by the table of describe of Pandas

hope it's helpful
Juan


Reply all
Reply to author
Forward
0 new messages