Pratham Rathi
Pratham Rathi

Reputation: 11

How do I turn a link to an image in a Python DataFrame column?

I have the links in the column but I am trying to convert them to images

thumbnails = []
for index,row in pdr.iterrows():
    s = row['videoId']
    thumbnail_url = f"https://i.ytimg.com/vi/{s}/maxresdefault.jpg"
    thumbnails.append(thumbnail_url)
pdr['thumbnail'] = thumbnails

Output: Code Output

This is the output. I am trying to fill the 'thumbnail' column with images as opposed to linked text.

Upvotes: 1

Views: 1376

Answers (2)

jeffasante
jeffasante

Reputation: 3289

from IPython.display import Image


Image(url= "http://my_site.com/my_picture.jpg")

Upvotes: 0

imxitiz
imxitiz

Reputation: 3987

Try this:

thumbnails = []
for index,row in pdr.iterrows():
    s = row['videoId']
    thumbnail_url = f"<img src='https://i.ytimg.com/vi/{s}/maxresdefault.jpg' width='100px'>"
    thumbnails.append(thumbnail_url)
pdr['thumbnail'] = thumbnails

We have created the DataFrame, now we have to show it:

from IPython.display import Image, HTML

HTML(df.to_html(escape=False))

This will show you the DataFrame with real image rather then only link.

Learn more from here:

Upvotes: 1

Related Questions