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

前端 未结 4 1613
北荒
北荒 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:11

    from IPython.core.display import display, HTML
    import pandas as pd
    
    # create a table with a url column
    df = pd.DataFrame({"url": ["http://google.com", "http://duckduckgo.com"]})
    
    # create the column clickable_url based on the url column
    df["clickable_url"] = df.apply(lambda row: "{}".format(row.url, row.url.split("/")[2]), axis=1)
    
    # display the table as HTML. Note, only the clickable_url is being selected here
    display(HTML(df[["clickable_url"]].to_html(escape=False)))
    

提交回复
热议问题