0

I have created a Pandas dataframe with 8 columns and 75 rows and exported into html using dataframe.to_html. And things are fine. I would like to add some formatting/style to the html file. e.g either have the Python program insert

... link href="stylesheet.css" rel="stylesheet">

after the Pandas export or some other method to add formatting changes to the html file i.e. without manually adding etc. I am using iPython. Open to any ideas and suggestions. I have also tried the Python module docx(0.2.4), but wasn't able to immediately figure out how to add in my list of lists. And there is ReportLab, but I haven't spent too much time in that either. I have found Pandas quite user-friendly so far, despite the 1689 page documentation :P. I also see there is a formatters=None parameter in the pandas.Dataframe.to_html, but unsure what I can link to that or how to use it.. Again, open to suggestions to polish the Pandas html output file up a bit.

Thank you.

R. Yora
  • 31
  • 9

2 Answers2

1

check out my answer here JS dataTables from pandas.

In short, you can use,

df.to_html().replace('<thead>','<thead class="myStyle">')

or, use regex to match and replace a complex part as it is just a normal python string

Community
  • 1
  • 1
Chandan Purohit
  • 2,283
  • 1
  • 17
  • 16
0

It does not support this. One hack I found somewhere is this. You could probably use the same method to add a style sheet.

.to_html(classes='display stripe compact" id = "example '))

JS dataTables from pandas

Community
  • 1
  • 1