我有一个熊猫数据框,其中存储了两个图像网址及其注释详细信息(x,y坐标,高度和宽度)。我想以python显示图像。我应该首先将数据帧转换为numpy数组(以最终使用matplotlib imshow来显示图像)。还是可以使用matplotlib从数据框中提取数据以显示图像?哪个更容易?
import pandas as pd
import requests
df = pd.DataFrame({'image_url':['https://dcist.com/wp-content/uploads/sites/3/2020/02/wilford_newsletter.jpg'], 'about':['a cat']})
# Use df.iloc[0] to pull the first image url, and requests to download the data for the image
a = plt.imread(requests.get(df.iloc[0]['image_url'], stream=True).raw, format='jpeg')
plt.imshow(a)
plt.show()