Search⌘ K
AI Features

Exercise: Data Types

Explore how to use Python Altair to visualize different data types through line charts. Understand encoding techniques such as using quantities versus ordinals to represent trends and gaps in data accurately. This lesson helps you handle datasets effectively and enhances your data storytelling skills.

We'll cover the following...

Consider the following dataset:

Python 3.10.4
import pandas as pd
import altair as alt
import os
data = [{'Fruit': 'Orange', 'Quantity' : 5 , 'Year' : 1990},
{'Fruit': 'Apple', 'Quantity' : 2 , 'Year' : 1990},
{'Fruit': 'Water Melon', 'Quantity' : 4 , 'Year' : 1990},
{'Fruit': 'Orange', 'Quantity' : 7 , 'Year' : 2020},
{'Fruit': 'Apple', 'Quantity' : 5 , 'Year' : 2020},
{'Fruit': 'Water Melon', 'Quantity' : 6 , 'Year' : 2020},
{'Fruit': 'Orange', 'Quantity' : 10 , 'Year' : 2022},
{'Fruit': 'Apple', 'Quantity' : 3 , 'Year' : 2022},
{'Fruit': 'Water Melon', 'Quantity' : 8 , 'Year' : 2022},
{'Fruit': 'Orange', 'Quantity' : 4 , 'Year' : 2023},
{'Fruit': 'Apple', 'Quantity' : 6 , 'Year' : 2023},
{'Fruit': 'Water Melon', 'Quantity' : 10 , 'Year' : 2023},
]
df = pd.DataFrame(data)
print(df)

The dataset describes the ...