首页 星云 工具 资源 星选 资讯 热门工具
:

PDF转图片 完全免费 小红书视频下载 无水印 抖音视频下载 无水印 数字星空

怎样将matplotlib生成的图形通过Flask输出到页面

后端 30.12KB 9 需要积分: 1
立即下载

资源介绍:

matplotlib生成的图片通过flask输出到页面
""" 通过xlrd 1.2.0 读取xls,xlsx文件,获取表头字典,表头+数据,表头+类型+数据 """ import xlrd, os from xlrd import xldate_as_tuple from datetime import datetime,time # from openpyxl import load_workbook import re # import ctypetotbcolstype as ctotb #import is_int, is_float, is_dateordatetime, is_intorfloat, is_intphone def is_dateordatetime(value): if not isinstance(value, str): return 'err' value =value.strip() try: date_object = datetime.strptime(value, '%Y-%m-%d') return 'date' except ValueError: try: date_object = datetime.strptime(value, '%Y-%m-%d %H:%M:%S') return 'datetime' except ValueError: try: date_object = datetime.strptime(value, '%H:%M:%S') return 'time' except ValueError: return 'err' return 'err' def is_intphone(value): # 参考 Python-输入一串字符,判断是否为手机号码 https://blog.csdn.net/weixin_57255032/article/details/128620752 # hmd = [134, 135, 136, 137, 138, 139, 150, 151, 152, 157, 158, 159, 182, 183, 184, 187, 188, 147, 178, # 130, 131, 132, 155, 156, 185, 186, 145, 176, 179, # 133, 153, 180, 181, 189, 177] # 列表 # -----排除手机号------ phone = str.strip(value) if phone.isnumeric(): # 判断Phone是否全部都是数字字符 if len(phone) == 11: # 判断手机号是否为11位 # if int(phone[0:3]) in hmd: # 如果输入的手机号前三位数字在列表中,则输出"是一个有效号码" # print(f'是电话:{phone}') return 'phone' else: return 'err' return 'err' # def is_int(value): # if isinstance(value, int): # return 'int' # if isinstance(value, str): # try: # int_number = int(value) # return 'int' # except ValueError: # return 'err' # else: # return 'err' # # def is_float(value): # if isinstance(value, float): # return 'float' # if isinstance(value, str): # try: # float_number = int(value) #---字符串如果是int也会被判断为float,所以在此先判断是否为int # return 'int' # except ValueError: # try: # float_number = float(value) # return 'float' # except ValueError: # return 'err' # else: # return 'err' #--------------判断是数值型,包括 int,float def is_intorfloat(value): # print('2024-03-01:',value) if isinstance(value, int): return 'int' if isinstance(value, float): return 'float' if isinstance(value, str): try: int_number = int(value) return 'int' except ValueError: try: float_number = float(value) return 'float' except ValueError: return 'err' return 'err' class ExcelUtil: def __init__(self, excel_path, sheet_name=None): # print("---------excel_path=",excel_path) self.excel_path = excel_path # self.wb = load_workbook(excel_path, data_only=True) self.data = xlrd.open_workbook(excel_path) # 如果sheet_name传入值了并且名字在表格的sheet表名里就用这个名的表,如果没有就默认选择第一个表格 if sheet_name != None: # and sheet_name in self.wb.sheetnames: self.table = self.data.sheet_by_name(sheet_name) # self.ws = self.wb[sheet_name] else: self.table = self.data.sheets()[0] # print("-------self.table=",type(self.table),self.table) # self.ws = self.wb.worksheets[0] try: # 获取第一行作为key值 self.keys = self.table.row_values(0) except: print() # 获取总行数 self.rowNum = self.table.nrows # 获取总列数 self.colNum = self.table.ncols self.ctypeDice={0: "empty",1: "string", 2: "number", 3: "date", 4: "boolean", 5: "error"} def getKeys(self): return self.keys def getRowNum(self): return self.rowNum def getColNum(self): return self.colNum # 获取表格的表头+数据字典 def dict_data(self): if self.rowNum <= 1: print("总行数小于1,请核实表格数据!") os._exit(0) else: r = [] # 行数,从第2行取数据,第一行为表头,如果从第一行取数据,1改为0或不写 for row in range(1, self.rowNum): s = {} # 列数 for col in range(self.colNum): ctype = self.table.cell(row, col).ctype cell = self.table.cell_value(row, col) print(ctype,cell) # 如果表格中是日期,那么要进行转化 if ctype == 3: # print(f'excel中date型内容:{cell}') aa =xldate_as_tuple(cell,0) # print(f"元组{aa}")#返回的是一个元组(2023, 6, 26, 18, 35, 45) if aa[0] == 0: time_value = time(*aa[3:]) cell = time_value.strftime('%H:%M:%S') #时间型 else: date = datetime(*xldate_as_tuple(cell, 0)) cell = date.strftime('%Y-%m-%d %H:%M:%S') # print(f"转换的日期时间:{cell}") # s[self.keys[col]] = cell # 如果是整型 elif ctype == 2 and cell % 1 == 0: s[self.keys[col]] = int(cell) else: s[self.keys[col]] = cell r.append(s) # j=1代表第二行 # j = 1 # i控制循环次数,也就是取多少行数据 # for i in range(self.rowNum - 1): # s = {} # # 从第二行取对应values值 # values = self.table.row_values(j) # # 列数 # for x in range(self.colNum): # # 如果表格中是日期,那么要进行转化 # ctype = self.table.cell(j, x).ctype # cell = self.table.cell_value(j, x) # if ctype == 3: # date = datetime(*xldate_as_tuple(cell, 0)) # cell = date.strftime('%Y-%m-%d %H:%M') # s[self.keys[x]] = cell # # 如果是整型 # elif ctype == 2 and cell % 1 ==0: # s[self.keys[x]] = int(cell) # else: # s[self.keys[x]] = values[x] # r.append(s) # j += 1 return r # 获取表格的表头+数据字典 def dict_sheet0(self): if self.rowNum <= 1: print("总行数小于1,请核实表格数据!") os._exit(0) else: r = [] # 行数,从第2行取数据,第一行为表头,如果从第一行取数据,1改为0或不写 for row in range(0, self.rowNum): s = {} # 列数 for col in range(self.colNum): ctype = self.table.cell(row, col).ctype cell = self.table.cell_value(row, col) # 如果表格中是日期,那么要进行转化 if ctype == 3:

资源文件列表:

301-e001.zip 大约有27个文件
  1. 301-e001/
  2. 301-e001/apps/
  3. 301-e001/apps/dataeshows/
  4. 301-e001/apps/dataeshows/__init__.py 38B
  5. 301-e001/apps/dataeshows/__pycache__/
  6. 301-e001/apps/dataeshows/__pycache__/__init__.cpython-37.pyc 174B
  7. 301-e001/apps/dataeshows/__pycache__/views.cpython-37.pyc 718B
  8. 301-e001/apps/dataeshows/e001/
  9. 301-e001/apps/dataeshows/e001/__init__.py
  10. 301-e001/apps/dataeshows/e001/__pycache__/
  11. 301-e001/apps/dataeshows/e001/__pycache__/__init__.cpython-37.pyc 147B
  12. 301-e001/apps/dataeshows/e001/__pycache__/flask_show_matplot.cpython-37.pyc 3.08KB
  13. 301-e001/apps/dataeshows/e001/flask_show_matplot.py 3.5KB
  14. 301-e001/apps/dataeshows/views.py 734B
  15. 301-e001/static/
  16. 301-e001/static/datafiles/
  17. 301-e001/static/datafiles/301/
  18. 301-e001/static/datafiles/301/001/
  19. 301-e001/static/datafiles/301/001/学生基本信息表.xls 26KB
  20. 301-e001/static/datafiles/301/001/学生期末考试成绩排名表.xls 9.5KB
  21. 301-e001/static/datafiles/301/001/期末考试成绩表.xls 28.5KB
  22. 301-e001/templates/
  23. 301-e001/templates/301/
  24. 301-e001/templates/301/001/
  25. 301-e001/templates/301/001/show_matplotlib.html 320B
  26. 301-e001/utils/
  27. 301-e001/utils/xlrd_ExcelUtil.py 25.68KB
0评论
提交 加载更多评论
其他资源 echarts笔记资源代码
柱状图、折线图、饼图、散点图、直角坐标系配置等,有清晰的注释和效果图
WPF程序开发-MVVM架构、单列模式、窗口切换
WPF程序开发-MVVM架构、单列模式、窗口切换
数据加密-AES数据加密WPF程序
AES(Advanced Encryption Standard)是一种广泛使用的对称密钥加密算法,由美国国家标准与技术研究院(NIST)于2001年发布。AES以其高效、安全的特点,在数据加密领域占据了重要地位。
“Simple Allow Copy”一款可以帮助用户突破网页复制限制的浏览器扩展
“Simple Allow Copy”是一款可以帮助用户突破网页复制限制的浏览器扩展。它特别适用于那些禁止复制粘贴的网站,如百度文库、豆丁文库等。使用这款插件,用户可以轻松复制网页上的内容,无需手动输入或使用OCR工具。 使用教程在:https://blog.csdn.net/m0_62153576/article/details/139151863
Android ndk string处理:ndk-string-test
Android ndk string处理:ndk-string-test
最新手机号号段+手机号归属地数据库
最新手机号号段+手机号归属地数据库,数据截止202406
深信服的CVE-2024-38077检测工具
这个工具是来自于深信服的检测工具
C# 使用线程调用方法的便捷方式
帖子地址: https://blog.csdn.net/qq_38693757/article/details/140284722?spm=1001.2014.3001.5502