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' '体能']] 打印数据集的某行某列: 拳法
  • 相关阅读:
    chrome调试Android webview页面
    Ractive 的 一些认识
    backbone的一些认识
    关于Maven打包(Jar)时文件过滤的正确做法
    网页中实现微信登录(OAuth)的不完整记录
    将项目发布到Maven中央仓库时关于GPG的一些操作日志
    记录一下自己在 eclipse 中使用的 javadoc 模板
    记录一下MySQL的表分区常用操作
    在H5 App中实现自定义Token的注意事项
    再来复习一下Javascript中关于数组和对象的常用方法
  • 原文地址:https://www.cnblogs.com/saintdingspage/p/10453761.html
Copyright © 2011-2022 走看看