Python generates an HTML table

Source: Internet
Author: User

Recently made a gadget that needs to generate HTML tables for the statistics. After a round of online discovery, it is very useful to generate forms using pandas. The code is as follows:

1 ImportPandas as PD2 defConverttohtml (Result,title):#The structure #title that converts the data to HTML Table#result is List[list1,list2] is a list structure and corresponds to result one by one. TITLELIST[0] corresponds to a column in an HTML table that corresponds to resultlist[0]3D = {}4index = 0 forTinchTitle:5d[t]=Result[index]6index = index+17DF =PD. DataFrame (d)8DF =Df[title]9h = df.to_html (index=False)Ten     returnh One  A  if __name__=='__main__': -result = [[u'2016-08-25', u'2016-08-26', u'2016-08-27'],[u'Zhang San', u'John Doe', u'Wang er']] -title = [u'Date', u'name'] the     Print(Converttohtml (Result,title))

The results of the run are displayed in HTML as follows:

Dataframe has many ways of initializing it; it's not just the way the dictionary works; it's written in a post. In addition to say a pandas to deal with the data is really too convenient, interested friends can do a good study ~

Source: Http://blog.csdn.net/duyisen/article/details/52315844?utm_source=itdadao&utm_medium=referral



From for notes (Wiz)



Python generates an HTML table

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.