Search code examples
pythonpandasjupyter-notebookjupyterpandas-styles

How to set the default Styler for a pandas DataFrame's _repr_html method?


I've got a pandas DataFrame with a column that's a url, and I've written the following formatter to present it in my notebook as a link:

def make_clickable(val):
    # target _blank to open new window
    return '<a target="_blank" href="{}">{}</a>'.format(val, val)
all_data.style.format({'url': make_clickable})

This nicely prints out my table with the urls made clickable, but what I'd really like to do is to make this style persist as the default for that frame, so that it's used for the _repr_html of my dataframe (and slices of it) throughout the same notebook.

Does anyone know if that's possible?


Solution

  • As far as I know it's not possible to register a default style. We overrode _repr_html_ instead, replacing clickable_urls argument.

                table_id=None,
                render_links=render_links,
            )
    

    https://github.com/pandas-dev/pandas/blob/c23649143781c658f792e8f7a5b4368ed01f719c/pandas/core/frame.py