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' '体能']] 打印数据集的某行某列: 拳法
  • 相关阅读:
    网站被刷导致404解决
    vim常用
    curl, wget常用选项
    使用paramiko远程登录并执行命令脚本
    批量监测dns是否可用脚本,不可用时并切换
    shell脚本收集服务器基本信息并入库
    沃通SSL证书及国密SSL证书入驻百度云市场
    电子合同,相比纸质合同有哪些好处?
    DV型域名https证书的优点及申请流程
    Chrome 浏览器显示“网站连接不安全”,是什么原因?
  • 原文地址:https://www.cnblogs.com/saintdingspage/p/10453761.html
Copyright © 2011-2022 走看看