python產生html表格

來源:互聯網
上載者:User

標籤:ott   port   frame   detail   col   方便   title   imp   white   

最近做一個小工具,需要將統計資料產生html表格。在網上搜羅一圈後發現用pandas產生表格非常好用。代碼如下:

 1 import pandas as pd 2 def convertToHtml(result,title):#將資料轉換為html的table#result是list[list1,list2]這樣的結構#title是list結構;和result一一對應。titleList[0]對應resultList[0]這樣的一條資料對應html表格中的一列 3     d = {} 4     index = 0for t in title: 5         d[t]=result[index] 6         index = index+1 7     df = pd.DataFrame(d) 8     df = df[title] 9     h = df.to_html(index=False)10     return h11 12  if __name__ == ‘__main__‘:13     result = [[u‘2016-08-25‘,u‘2016-08-26‘,u‘2016-08-27‘],[u‘張三‘,u‘李四‘,u‘王二‘]]14     title = [u‘日期‘,u‘姓名‘]15     print(convertToHtml(result,title))

 

運行結果放入html中顯示如下: 

DataFrame有很多初始化的方式;不僅僅是這種字典的方式;後面專門寫一篇介紹。另外說一句pandas用來處理資料真的太方便了,有興趣的朋友可以好好研究一下~

 

來源: http://blog.csdn.net/duyisen/article/details/52315844?utm_source=itdadao&utm_medium=referral



來自為知筆記(Wiz)



python產生html表格

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.