tornado下pandas ndarray乱试
from tornado.web import RequestHandler from pymongo import MongoClient import pandas,xlrd from pandas import DataFrame,Series import json import os import time currentpath =os.getcwd() class multiupload(RequestHandler): def get(self): self.render('multifilesupload.html') def post(self): if self.request.files: sourcefile = self.request.files for i in sourcefile.keys(): targetpath = currentpath+"\\temfile\\"+sourcefile[i][0]['filename'] with open(targetpath,"wb") as writer: writer.write(sourcefile[i][0]['body']) self.write(json.dumps({"status":"ok"})) else: self.write(json.dumps({"status": "motherfuck"})) class qingxiniaodao(RequestHandler): def get(self): self.render('mongowithpanda.html') def post(self): if self.request.files: filename = self.request.files['fileobj'][0]['filename'] filename =currentpath+"\\temfile\\"+filename with open(filename,"wb") as writer: writer.write(self.request.files['fileobj'][0]['body']) mydataframe = pandas.read_excel(filename) #print(mydataframe) title =[] rets=[] superdict = {} retlist =[] print("这是表头:",mydataframe.columns) for i in mydataframe.columns: title.append(i) #mydataframe.values----结果集ndarray类型 print("算出数据集的行,列数:", mydataframe.values.shape) rowcount = mydataframe.values.shape[0]#ndarray的行数,--元组 i=0 print("打印数据集的值:", mydataframe.values) print("打印数据集的某行某列:", mydataframe.values[0][2]) k=0 for i in range(0,rowcount): for k in range(0,len(title)): superdict[title[k]]=mydataframe.values[i][k] retlist.append(superdict) superdict = {} i+=1 # for i in title: # superdict.a self.write(json.dumps({"rets":retlist}))
输出结果:
这是表头: Index(['articleflid', 'articlefl', 'articleflcn'], dtype='object') 算出数据集的行,列数: (5, 3) 打印数据集的值: [[1 'fist' '拳法'] [2 'kick' '腿法'] [3 'knee' '膝击'] [4 'wrestling' '摔法'] [5 'fit' '体能']] 打印数据集的某行某列: 拳法