You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在DataSpell的Jupyter Notebook中通过URL显示列内图片?

解决DataSpell Jupyter Notebook中无法通过URL显示DataFrame图片的问题

在Google Colab中可通过URL正常显示DataFrame列内的图片,但在DataSpell的Jupyter Notebook中尝试时,仅返回<img src="url of the image" width="60">标签文本,无法渲染出图片。使用的代码如下:

from IPython.core.display import HTML
#%%
## Converting links to html tags
def path_to_image_html(path):
    return '&lt;img src=&quot;'+ path + '&quot; width=&quot;60&quot; &gt;'
#%%
## Rendering the dataframe as HTML table
df.to_html(escape=False, formatters=dict(image=path_to_image_html))

## Rendering the images in the dataframe using the HTML method.
HTML(df.to_html(escape=False,formatters=dict(image=path_to_image_html)))

解决方案

  • 修正HTML标签转义:原函数中使用了HTML实体转义(&lt;、&quot;),但to_html已设置escape=False,无需额外转义,直接返回原始HTML标签即可:
def path_to_image_html(path):
    return f'<img src="{path}" width="60">'
  • 显式调用渲染函数:在DataSpell中,可通过display()函数强制渲染HTML对象,确保输出生效:
from IPython.display import display, HTML
display(HTML(df.to_html(escape=False, formatters=dict(image=path_to_image_html))))
  • 检查DataSpell配置:进入File > Settings > Languages & Frameworks > Jupyter,确认Jupyter Notebook的HTML内容渲染功能已启用。

内容的提问来源于stack exchange,提问作者maria

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 03:50:41