pythonpandasjupyter-notebookpandas-styles

How to create a table with clickable hyperlink in pandas & Jupyter Notebook


print('http://google.com') outputs a clickable url.

How do I get clickable URLs for pd.DataFrame(['http://google.com', 'http://duckduckgo.com']) ?


Solution

  • Try using pd.DataFrame.style.format for this:

    df = pd.DataFrame(['http://google.com', 'http://duckduckgo.com'])
    
    def make_clickable(val):
        return '<a href="{}">{}</a>'.format(val,val)
    
    df.style.format(make_clickable)
    

    I hope this proves useful.