6

How can I include HTML in the table produced by a DataFrame in an IPython notebook?

For example, I'd like to be able to do something like:

pd.DataFrame({
    "text": ["Hello <strong>world</strong>"],
})

To produce a table something like:

<table>
  <tr><th></th><th>text</th></tr>
  <tr><th>0</th><td>Hello <strong>world</strong></tr>
</table>
1
  • I don't think the pandas notebook display is really meant for that kind of thing. Commented Mar 3, 2014 at 6:11

1 Answer 1

4

Have you tried pandas.DataFrame.to_html See here for more info. For fantastic examples on using IPython Notebook to display html, svg, image etc see here

Works like this on IPython Notebook;

from IPython.display import HTML
data = pd.DataFrame({'A':[1,2,3,4,5],'B':[6,7,8,9,10]})
h = HTML(data.to_html());h
Sign up to request clarification or add additional context in comments.

3 Comments

looks like you might want to try escape=False
What is escape=False?
Yes, this solved my issue (wanting to embed a button). "escape=False" will tell pandas to render the content as is e.g. without adding escape characters to your html.

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.