Example: fruit images from urls#
This example shows how a Trelliscope can be created to view images of fruit and their attributes.
We create a dataset of fruit with images and 4 meta attributes: [name, size, weight, color].
Fruit data#
[1]:
import pandas as pd
from trelliscope import Trelliscope
df = pd.DataFrame([
{
"name": "apple",
"size": 1,
"weight": 3,
"color": "red",
"img": "https://upload.wikimedia.org/wikipedia/commons/1/15/Red_Apple.jpg"
},
{
"name": "banana",
"size": 3,
"weight": 2,
"color": "yellow",
"img": "https://upload.wikimedia.org/wikipedia/commons/4/44/Bananas_white_background_DS.jpg"
},
{
"name": "pineapple",
"size": 5,
"weight": 6,
"color": "brown",
"img": "https://upload.wikimedia.org/wikipedia/commons/2/20/Ananas_01.JPG"
}
])
df
[1]:
| name | size | weight | color | img | |
|---|---|---|---|---|---|
| 0 | apple | 1 | 3 | red | https://upload.wikimedia.org/wikipedia/commons... |
| 1 | banana | 3 | 2 | yellow | https://upload.wikimedia.org/wikipedia/commons... |
| 2 | pineapple | 5 | 6 | brown | https://upload.wikimedia.org/wikipedia/commons... |
Create Trelliscope#
Create a Trelliscope object by passing a dataframe and a display name.
Trelliscope will be able to infer what column contains the image, and which columns contain attributes.
[2]:
display_name = "Fruit"
tr = Trelliscope(df, display_name).write_display()
tr
INFO:root:Using ['name'] to uniquely identify each row of the data.
INFO:root:Saving to /tmp/tmp5hn6n742/fruit
INFO:root:No layout definition supplied. Using Default.
INFO:root:No labels definition supplied. Using Default.
INFO:root:Trelliscope written to `/tmp/tmp5hn6n742/fruit`
[2]:
A trelliscope display
* Name: Fruit
* Description: Fruit
* Tags: None
* Key columns: ['name']
---
* Path: /tmp/tmp5hn6n742
* Number of panels: 1
---
* Meta Info:
View output#
The output can be shown by opening a new browser tab.
[3]:
tr.view_trelliscope() # Opens browser tab
[3]:
A trelliscope display
* Name: Fruit
* Description: Fruit
* Tags: None
* Key columns: ['name']
---
* Path: /tmp/tmp5hn6n742
* Number of panels: 1
---
* Meta Info:
Or you can go to the output directory and open the index.html file. You can configure the output directory by passing Trelliscope(..., path="my-trelliscope/")