I wanted to save a test image dataset into a pandas data frame. The Panda data frame contains the input image, input image class, and predicted output class.
Asked
Active
Viewed 286 times
1 Answers
1
Do you need something like this?
import pandas as pd
from IPython.core.display import display,HTML
# empty dataframe
df = pd.DataFrame()
# your images
df['images1'] = ['https://a.cdn-hotels.com/gdcs/production180/d124/9dc35ac0-af3d-4cce-a7cf-02132213f43a.jpg?impolicy=fcrop&w=800&h=533&q=medium',
'https://upload.wikimedia.org/wikipedia/commons/2/2b/NYC_Downtown_Manhattan_Skyline_seen_from_Paulus_Hook_2019-12-20_IMG_7347_FRD_%28cropped%29.jpg']
df['images2'] = ['https://post.medicalnewstoday.com/wp-content/uploads/sites/3/2020/02/322868_1100-800x825.jpg',
'https://i.guim.co.uk/img/media/684c9d087dab923db1ce4057903f03293b07deac/205_132_1915_1150/master/1915.jpg?width=1200&height=1200&quality=85&auto=format&fit=crop&s=14a95b5026c1567b823629ba35c40aa0']
display(df) # <-- At this point you have a dataframe with paths of images
# convert your links to html tags
def path_to_image_html(path):
return '<img src="'+ path + '" width="60" >'
pd.set_option('display.max_colwidth', None)
image_cols = ['images1', 'images2'] # If you have many columns define which columns will be used to convert to html
# Create the dictionariy to be passed as formatters
format_dict = {}
for image_col in image_cols:
format_dict[image_col] = path_to_image_html
display(HTML(df.to_html(escape=False ,formatters=format_dict)))

Kyriakos
- 181
- 1
- 8