Good afternoon.
I am currently having trouble with Panda's dataframe. Please consider the code below:
import pandas as pd
from IPython.core.display import display,HTML
df = pd.DataFrame([['A231', 'Book', 5, 3, 150],
['M441', 'Magic Staff', 10, 7, 200]],
columns = ['Code', 'Name', 'Price', 'Net', 'Sales'])
# your images
images = ['https://vignette.wikia.nocookie.net/2007scape/images/7/7a/Mage%27s_book_detail.png/revision/latest?cb=20180310083825',
'https://i.pinimg.com/originals/d9/5c/9b/d95c9ba809aa9dd4cb519a225af40f2b.png']
df['image'] = 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)
display(HTML(df.to_html(escape=False ,formatters=dict(image=path_to_image_html))))
How can I import this specific dataframe to a HTML file?
I tried the following code,
df.to_html(open('my_file2.html', 'w'))
Which works fine, but, "my_file2.html" displays like this:
How can I modify the code so that in my_file2.html, in the column "image", it shows the actual image and not the link to the image?
Thanks for your attention!
