I am a nood in coding and web development. I want to use web2py to establish a small APP for my research. But I have some problems to import the csv data and then use the data for calculation (or model establishment). I search for some examples in manual book, web2pyslices.com and some other websites, but still could not solve it.
Here is my controllers and views for my app *#controller data.py (import csv data which contains 3 columns salinity, N2 and chla)* def data(): import numpy as np import pandas as pd dat = pd.read_csv('C:\Users\wangfeng\Desktop\TEST.csv') sal = dat['salinity'] N2 = dat['N2'] chl = dat['chla'] return dict(sal=sal, N2=N2, chl=chl) *# controller csv.py (creat a form to upload data, this code is copied from some other websites)* def import_table(): form = SQLFORM.factory(Field('table',requires=IS_IN_SET(db.tables)), Field('csvfile','upload',uploadfield=False)) form.process() if form.accepted: try: db[form.vars.table].import_from_csv_file(request.vars.csvfile.file) except: form.errors.csvfile = 'invalid file' return dict(form = form) *#data/data.html (for calculation of my research)* *#show the data* <h1>这是 This is raw data</h1> <h5>sal={{=sal}}</h5> <h5>N2={{=N2}}</h5> <h5>chl={{=chl}}</h5> {{import numpy as np}} {{from scipy.optimize import leastsq}} #calculation *#data standization* {{s_sal=((chl-np.mean(sal))/np.std(sal))}} {{s_N2=((chl-np.mean(N2))/np.std(N2))}} *#model fitting* {{def func1(t,x,y):}} {{return 1/(t[0]+t[1]*np.exp(t[2]*x))-y}} {{t0=np.array([1.0,1.0,1.0])}} {{for i in np.arange(0,2.0,0.05):}} {{index = i*s_sal + (2-i)*s_N2}} {{cf = leastsq(func1,t0,args=(index,chl))}} *#show the results* <li> "Model: "{{=i}}"*salinity+"{{=2-i}}"*N2" "Equation: 1/("{{=round(cf[0][0],2)}}"+"{{=round(cf[0][1],2)}}"*EXP("{{=round(cf[0][2],2)}}"*x))" </li> {{pass}} Thanks all -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
salinity,N2,chla -0.8,0.6,7.9 -0.38,0.37,4.1 -0.23,-0.01,3.2 -0.27,-0.09,5 -0.13,-0.14,2.6 0.03,-0.13,2.2 0.11,0.07,1.5 0.1,-0.06,1 0.15,-0.08,0.7 0.29,-0.08,0.7 0.16,-0.09,0.9 0.07,-0.02,3.5 0.05,-0.05,1.9 0,-0.17,2.4 -0.49,0.44,7.8 -0.17,-0.13,3.7 -0.33,-0.14,3.7 -0.58,0.62,9.1 -0.17,-0.09,3.1 -0.07,-0.14,3.1 -0.5,0.09,6.2 -0.09,-0.12,3.8 -0.12,-0.07,2.5 -0.29,0.01,5.2 -0.12,-0.08,3 -0.1,-0.11,3.9 -0.11,-0.14,5.6 -0.14,-0.14,8.1 -0.49,0.32,6.6 -0.11,-0.19,5.3 -0.48,0.18,8.9 -0.28,-0.17,3.4 -0.16,-0.22,2.5 -0.13,-0.18,2.7 -0.03,-0.18,2.8 -0.17,-0.02,3.4 0.02,-0.12,3.6 -0.19,0.56,8.6 -0.04,0.09,1.9 -0.03,0.12,2.4 -0.07,0.03,2 -0.27,0.3,7.1 -0.27,0.09,2 0.04,-0.08,1.8 0.04,0.02,1.4 -0.1,0.1,4.8 -0.3,-0.08,2.9 -0.39,0.01,5.7 0.09,-0.03,1.8 -0.03,0.18,3.2 -0.11,-0.05,2.6 -0.23,-0.15,1.8 -0.23,-0.18,1.4 0.22,-0.21,1.5 -0.21,-0.2,1.6 0.26,-0.2,1.4 -0.23,-0.14,1.4 -0.41,0.36,3.6 -0.66,0.42,4.1 -0.3,0.05,1.5 -0.36,0.09,2.2 -1.38,0.43,7.8 -0.14,0.41,1.6 -1.02,0.39,5.9 -0.19,0.26,1.9 -0.58,0.66,3.2 0.16,-0.11,3.6 0.26,-0.14,2.6 0.14,-0.12,1.9 0.28,-0.19,2.3 0.38,-0.16,1.3 0.34,-0.18,1.6 0.25,-0.19,2.2 0.36,-0.17,1 0.36,-0.13,0.6 0.41,-0.19,1.1 0.27,-0.04,1.2 0.32,-0.14,0.7 0.26,-0.07,0.8 -0.26,1.31,3.5 0.21,-0.08,1 0.33,-0.16,0.9 0.08,0.14,2.2 0.15,-0.07,0.4 0.16,-0.08,0.9 0.15,-0.03,1 -0.01,0.36,4.5 0.14,0.08,1.7 0.08,0.03,0.9 -0.07,0.3,0.5 -0.24,0.02,2.9 0.1,0.21,1.1 -0.05,0.34,2.5 -0.35,0.46,1.5 0.02,0.22,1.5 -0.08,0.35,0.7 -0.03,0.2,2.3 -0.31,1.05,2.1 -0.05,0.57,3 -0.03,0.73,4.5 -0.01,0.18,8.4 -0.1,0.39,12.2 0.55,-0.15,3.1 0.57,-0.17,1.2 0.61,-0.19,1.4 0.52,-0.16,1.2 0.62,-0.15,0.8 0.54,-0.19,1.3 0.51,-0.21,1.7 0.59,-0.2,1.4 0.61,-0.19,1.7 0.46,-0.22,1 0.17,0,2.5 0.14,0.11,2.5 0.51,-0.1,1.4 0.5,-0.08,1.3 0.53,-0.1,0.8 -0.18,0.13,1.6 -0.11,0.01,1.5 -0.3,0.13,3 0.06,-0.16,1.7 -0.23,0.17,3.3 0.15,-0.19,2.2 0.06,-0.06,4.3 0.12,-0.15,3 0.19,-0.22,2 0.21,-0.19,1.9 0.18,-0.22,1.7 0.17,-0.22,2.1 0.14,-0.23,1.8 0.11,-0.23,1.9 0.02,-0.07,1.1 0.26,-0.22,2 0.22,-0.22,2.1 0.21,-0.23,1.7 -0.8,0.49,6.5 -0.33,0.02,2.9 -0.22,-0.13,3 -0.19,0.15,2.6 -0.19,-0.09,2 -0.13,-0.11,1.8 0.04,-0.18,4 -0.02,-0.14,1.9 -0.12,-0.2,1.6 -0.15,-0.2,1.4 -0.31,0.21,3.6 -0.2,-0.14,1 -0.14,-0.19,1.4 -0.28,-0.04,1.6 -0.14,-0.16,1 -0.08,-0.15,0.8 -0.41,0.37,4.5 -0.17,-0.11,1.1 -0.11,-0.16,0.9 -0.06,-0.17,1.2 -0.23,-0.12,2.6 -0.12,-0.12,1.2 -0.07,-0.13,1.2 -0.12,-0.12,2 -0.21,-0.11,1.7 -0.16,-0.13,1 -1.24,1.77,13.7 -0.64,0.58,5.1 -0.06,-0.14,2.6 -0.28,0,2 0.32,-0.16,1 0.29,-0.12,1.4 0.28,-0.19,1.2 0.21,-0.23,1.3 0.27,-0.23,1.6 0.24,-0.19,2.2 0.31,-0.17,0.5 0.36,-0.16,0.7 0.34,-0.14,0.4 0.15,-0.19,1.6 0.1,-0.16,1.2 0.03,0.12,1.5 0.08,-0.11,0.6 0.06,-0.13,0.9 0.01,0.04,1.2 0.05,0,0.7 0,0.12,1.1 0.28,-0.2,2.2 0.12,0.04,2.3 -0.02,0.14,1.5 0.08,0.26,0.8 0.14,0.09,0.8 0.1,0.27,0.9 0.11,0.02,0.6 0.13,0.16,0.5 0,0.33,0.9 0.19,0.02,0.3 0.09,0.22,0.7 0.19,0.08,0.3 0.16,0.07,0.6 0.17,0.3,1 0.19,0.01,0.4 0.13,0.03,0.9 0.25,-0.05,0.7 0.23,-0.09,0.6 0.28,-0.06,0.3 0.28,-0.1,0.5 0.33,-0.13,0.9 -0.19,-0.15,3.5 -0.08,-0.17,2.5 -0.16,-0.14,5.2 -0.04,-0.17,2.1 -0.18,-0.24,2.4 -0.33,-0.16,5.2 -0.38,-0.14,5.4 -0.21,-0.18,2.5 -0.33,0.03,3.9 -0.19,-0.17,2.2 -0.19,-0.18,3.5 -0.1,-0.07,2.7 -0.03,-0.09,1 -0.14,-0.23,2.4 -0.07,-0.04,1.1 -0.01,-0.08,0.5 -0.01,-0.02,0.7 -0.07,0.06,0.9 -0.07,0.09,1.2 0.15,-0.12,1.5 0.19,-0.12,0.9 0.16,-0.11,2.4 0.04,-0.15,1.7 0.21,-0.1,0.8 0.22,-0.04,1.2 -0.05,-0.06,2.7 0.35,-0.09,0.6 0.23,-0.11,1.3 0.06,-0.06,2.4 0.37,-0.09,0.7 0.2,-0.07,1.2 0.4,-0.1,0.6 -0.1,-0.07,2.3