zoukankan      html  css  js  c++  java
  • 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' '体能']] 打印数据集的某行某列: 拳法
  • 相关阅读:
    mybatis自动生成代码配置文件
    Struts2的类型转换器
    CSS布局自适应高度终极方法
    Winform WebBrowser控件对访问页面执行、改写、添加Javascript代码
    利用using语句解决Lock抛出异常时发生死锁的问题
    Flash与Silverlight终极大比拼
    System.Collections.Specialized.NameValueCollection PostVars
    Hook浏览器控件WebBrowser对WININET.dll的调用
    WebBrowser中打开新页面保留sessionid
    Linksys路由器自动重启加流量
  • 原文地址:https://www.cnblogs.com/saintdingspage/p/10453761.html
Copyright © 2011-2022 走看看