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

前端 未结 4 1614
北荒
北荒 2020-11-27 17:19

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

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

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 18:18

    If you want to apply URL formatting only to a single column, you can use:

    data = [dict(name='Google', url='http://www.google.com'),
            dict(name='Stackoverflow', url='http://stackoverflow.com')]
    df = pd.DataFrame(data)
    
    def make_clickable(val):
        # target _blank to open new window
        return '{}'.format(val, val)
    
    df.style.format({'url': make_clickable})
    

    (PS: Unfortunately, I didn't have enough reputation to post this as a comment to @Abdou's post)

提交回复
热议问题