我有一个数据框,其中一列包含 495 行 URL。我想在 jupyter notebook 中将这些 URL 显示为图像网格。数据框的第一行显示在这里。任何帮助表示赞赏。
id latitude longitude owner title url
23969985288 37.721238 -123.071023 7679729@N07 There she blows! https://farm5.staticflickr.com/4491/2396998528...
我试过下面的方法,
from IPython.core.display import display, HTML
for index, row in data1.iterrows():
display(HTML("<img src='%s'>"%(i["url"])))
但是,上面代码的运行会显示消息
> TypeError Traceback (most recent call last)
<ipython-input-117-4c2081563c17> in <module>()
1 from IPython.core.display import display, HTML
2 for index, row in data1.iterrows():
----> 3 display(HTML("<img src='%s'>"%(i["url"])))
TypeError: string indices must be integers
最佳答案
您将 IPython.core.display
与 HTML 一起使用的想法是恕我直言,是完成此类任务的最佳方法。 matplotlib
在绘制如此大量的图像时效率极低(尤其是当您将它们作为 URL 时)。
我根据这个概念构建了一个小包 - 它叫做 ipyplot
import ipyplot
images = data1['url'].values
labels = data1['id'].values
ipyplot.plot_images(images, labels, img_width=150)
关于python - 在 jupyter 笔记本中显示图像网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47508168/