【发布时间】:2021-05-07 14:24:39
【问题描述】:
下午好。
我目前在处理 Panda 的数据框时遇到问题。请考虑以下代码:
import pandas as pd
from IPython.core.display import display,HTML
df = pd.DataFrame([['A231', 'Book', 5, 3, 150],
['M441', 'Magic Staff', 10, 7, 200]],
columns = ['Code', 'Name', 'Price', 'Net', 'Sales'])
# your images
images = ['https://vignette.wikia.nocookie.net/2007scape/images/7/7a/Mage%27s_book_detail.png/revision/latest?cb=20180310083825',
'https://i.pinimg.com/originals/d9/5c/9b/d95c9ba809aa9dd4cb519a225af40f2b.png']
df['image'] = images
# convert your links to html tags
def path_to_image_html(path):
return '<img src="'+ path + '" width="60" >'
pd.set_option('display.max_colwidth', None)
display(HTML(df.to_html(escape=False ,formatters=dict(image=path_to_image_html))))
如何将此特定数据框导入 HTML 文件?
我尝试了以下代码,
df.to_html(open('my_file2.html', 'w'))
效果很好,但是“my_file2.html”显示如下: 如何修改代码,以便在 my_file2.html 中的“图像”列中显示实际图像而不是图像的链接?
感谢您的关注!
【问题讨论】:
标签: python pandas dataframe plot jupyter