pandas clickable links not working after download

Viewed 59

So I am trying to populate an xls sheet with clickable links. When I do df.head() it shows me clickable links but when I export df as excel, these links are not clickable anymore.

def make_clickable(val):
    return '<a href="{}">{}</a>'.format(val,val)

df = pd.DataFrame(['http://google.com', 'http://duckduckgo.com'])
df.style.format(make_clickable)
df.to_excel("j.xls")

How can I resolve such issues? Or pandas does not support clickable links after download?

1 Answers

Use the extension .xlsx instead of .xls since this will be depreciated in the future.

And you should set the line df.style.format(make_clickable) to df else Python will be exporting the "non-clickable" dataframe to Excel.

df = pd.DataFrame(['http://google.com', 'http://duckduckgo.com'])

def make_clickable(val):
    return '<a href="{}">{}</a>'.format(val,val)

df = df.style.format(make_clickable)
df.to_excel('j.xlsx')
Related