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