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.

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.