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()

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM