jack1285
jack1285

Reputation: 55

how to print the image using for loop in python?

I have a data frame which has Book title and Image URL. The total size of the data frame is 10.

Please see the below dataframe. My dataframe name is df. It has two columns called title and url.

Dataframe

I am using requests to read the url. I can able to read the image using for loop. However, it prints only one image. I need to print all 10 images. Any suggestions?


for i in df['url']:
    response = requests.get(i)
    img = Image.open(BytesIO(response.content))
    plt.imshow(img)

Output:

It prints only one image. I wanted to print all 10 images

Upvotes: 1

Views: 3112

Answers (2)

Olric
Olric

Reputation: 338

Just add plt.show() :

for i in df['url']:
    response = requests.get(i)
    img = Image.open(BytesIO(response.content))
    plt.imshow(img)
    plt.show()

Upvotes: 2

Pakium
Pakium

Reputation: 321

i think it opens all of them and you see only the last one, because its in the same opener "img", put a print to check your iteration...

Upvotes: 1

Related Questions