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