[IPython-dev] How to display markdown text in DataFrame in Notebook

Anton Akhmerov anton.akhmerov at gmail.com
Sat May 30 06:59:52 EDT 2015


Dear Dong Ta,

On Sat, May 30, 2015, 07:58 Dong Ta <dongta.hds at gmail.com> wrote:
>
> I have DataFrames with url fields.
>
> Can I easily tweak IPython Notebook so that it displays hyperlink markdowns? Meaning it renders clickable title?


Somewhat paradoxically, there's no easy way to display markdown
programmatically in ipython. You can manually create HTML out of
markdown by using markdown2html filters from
IPython.nbconvert.filters.

Now, the problem is that pandas doesn't use markdown at all, instead
it has a _repr_html_ method used to show the dataframes. By default it
sanitizes html, but you can turn it off by using e.g. this:

IPython.display.HTML(dataframe.to_html(escape=False))

Of course this means you need to make the fields with html-formed URLs
on your own.
If you want a more systematic solution, I believe you could subclass
the DataFrame and teach it to transform some columns before printing.

Best,
Anton



More information about the IPython-dev mailing list