python - Writing full contents of Pandas dataframe to HTML table -
I am putting links in a column of a panda dataframe (table below), and writing the data frame in HMTL .
The link in the dataframe table is formatted as shown (index the first link in the table):
In : table.loc [0, 'link' ] Out: u '& lt; A href = "http://xxx.xx.xxx.xxx/browser/I6.html" & gt; I6 & lt; / A & gt; '
If I look at dataframes (instead of a specific line index), the link text is cut off:
& lt ; A href = "http: //xxx.xx.xxx.xxx/browser/I6.html ...
I write html datafrom:
< Code> table_1 = Table.to_html (classes = 'table', index = False, escape = false)
However, the cut link (instead of full text) is written on the HTML table:
& lt; td> & lt; a href = "http: //xxx.xx.xxx.xxx/browser/I6.html...</td> N
I probably need an extra parameter for to_html ().
Now look at the document, but appreciate the advice:
Thank you!
So possibly a panda is specific, but you can also work around the problem (a ), Replace the link with a significant value, (b) writing the HTML table string, and then by changing the (c) key from the appropriate link
For example, replace each link with one key, one Store keys to be made in the dictionary:
map = {} i in df.index: counter = 0 if df .ix [i] ['link'] In map: df.ix [I, 'ltd Ink '[df.ix [i] [' link ']] and: map [df.ix [i,' link ']] =' href '+ str (counter) counter + = 1 df.ix [ I, 'link'] = map [df.ix [i] ['link']]
table:
table_1 = df.to_html (Classes = 'table', index = False, escape = false)
rewrite link:
for key, value in map.iteritems (): Table_1 = table_1.replace (value, key)
Comments
Post a Comment