Pandas 在jupyterlab中呈现熊猫df中的超链接

Pandas 在jupyterlab中呈现熊猫df中的超链接,pandas,formatting,amazon-sagemaker,Pandas,Formatting,Amazon Sagemaker,我试图在数据帧输出中呈现url。我遵循了其他一些示例,下面是我的实现: def create_url(product_name): search = 'http://www.example.com/search' url = 'http://www.example.com/search/'+product_name return url def make_clickable(url): return '<a target="_blank" href="{}

我试图在数据帧输出中呈现url。我遵循了其他一些示例,下面是我的实现:

def create_url(product_name):
    search = 'http://www.example.com/search'
    url = 'http://www.example.com/search/'+product_name
    return url

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

...

df['url'] = df['product_name'].apply(format_url)
df.style.format({'url': make_clickable})
def创建url(产品名称):
搜寻http://www.example.com/search'
url='1〕http://www.example.com/search/“+产品名称”
返回url
def使_可点击(url):
返回“”。格式(url,url)
...
df['url']=df['product\u name'].应用(格式\u url)
format({'url':使_可点击})
这会生成格式正确的原始文本超链接,但在输出中无法单击


我应该补充一点,我在AWS sagemaker jupyterlab笔记本中这样做,这可能会禁用输出中的超链接。但我不知道该如何检查。

如果这不起作用,我猜这是AWS的问题

  • IPython.display.HTML
  • pandas.DataFrame.to_html
    带有
    escape=False
  • pandas.set\u选项('display.max\u colwidth',2000)
    必须是一个大数字,以适应链接标记的长度。我会说我认为这是坏的。无需设置
    “display.max\u colwidth”
    以确保
    正确输出html。但事实是:-/


  • 你能详细介绍一下这项技术的作用和工作原理吗?我在文章顶部的3个要点中已经提到了。但有一件事我本来打算说的,我要补充一点。
    from IPython import display
    
    pd.set_option('display.max_colwidth', 2000)
    
    display.HTML(df.assign(url=[*map(make_clickable, df.url)]).to_html(escape=False))