从URL读取图像,然后将它们放在带有标签的数据框列上到Python的另一列
我想读取来自URL的图像,并将其放在Pandas DataFrame列中,然后将标签放在另一列。我该怎么做,请帮忙。以下是我阅读的文件中的数据框。有4个标记的URL页面。但是我必须从中排除.svg图像,因为它没有显示任何图片。
因此最终结果将继续 df = {'image':....,'label':['ICON','iCON','iCON']}} 谢谢
import pandas as pd
data={'image_url':['https://www.philips.com/c-dam/b2c/en_US/experience/sound-and-
vision/headphones/fidelio-l3/L3_38_hr_88x88.png'
,'https://www.philips.com/c-dam/b2c/tv/categorypage/us/AndroidTVLP/HDR.png'
,'https://www.philips.com/c-dam/b2c/category-pages/sound-and-
vision/headphones/master/homepage/awaraness-mode-anc.png'],
,'https://https://www.philips.com/c-dam/b2c/master/experience/pe/shavers/360-d.svg'
'label':['icon','icon','icon','icon']}
df=pd.DataFrame(data)
#Below is what I tried so far with no success
img=[]
image=df['image_url']
for i in image:
if not i.endswith('.svg'):
response = requests.get(i)
img1 = Image.open(BytesIO(response.content))
img.extend(img1)
I would like to read images from url and place them on a pandas dataframe column and place label to another another column. How can I do that please help. Below is the dataframe from the file I read. There 4 url pages with the 4 labeled.But I have to exclude .svg images from it since it does not display any pictures.
So final outcome will be on
df={'image':....,'label':['icon','icon','icon']}
Thank you
import pandas as pd
data={'image_url':['https://www.philips.com/c-dam/b2c/en_US/experience/sound-and-
vision/headphones/fidelio-l3/L3_38_hr_88x88.png'
,'https://www.philips.com/c-dam/b2c/tv/categorypage/us/AndroidTVLP/HDR.png'
,'https://www.philips.com/c-dam/b2c/category-pages/sound-and-
vision/headphones/master/homepage/awaraness-mode-anc.png'],
,'https://https://www.philips.com/c-dam/b2c/master/experience/pe/shavers/360-d.svg'
'label':['icon','icon','icon','icon']}
df=pd.DataFrame(data)
#Below is what I tried so far with no success
img=[]
image=df['image_url']
for i in image:
if not i.endswith('.svg'):
response = requests.get(i)
img1 = Image.open(BytesIO(response.content))
img.extend(img1)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是您想要的吗?
Is this what you were looking for?