zoukankan      html  css  js  c++  java
  • python 生成html文件(表格)

    import pandas as pd
    def convert_to_html(result,title):
        d = {}
        index = 0
        for t in title:
            d[] = result[index]
            index +=1
        df = pd.DataFrame(d)
        #如数据过长,可能在表格中无法显示,加上pd.set_option语句可以避免这一情况
        pd.set_option('max_colwidth',200)
        df = df [title]
        h =df.to_html(index=False)
        return h

      result=[list1,list2,list3...],title=[name1,name2,name3..]。result保存多个list,title为表格的各项属性(名称)。name1对应list1,生成1列表格,name2对应name2生成1列表格。。。。

         若想保存h为本地html文件,可以遍历保存。代码如下

    f = open("11.html","w")
    for eachline in h:
         f.write(each)
    f.close()

      

  • 相关阅读:
    Redis Cluter
    数据库设计范式
    kvm虚拟化
    架构前端
    集群架构
    初识shell编程
    网络知识
    Linux三剑客
    Linux磁盘管理
    高性能异步爬虫
  • 原文地址:https://www.cnblogs.com/ilovena/p/7519772.html
Copyright © 2011-2022 走看看