Lesson 44 · Data visualisation in python
Build an Interactive Data Visualization App: Capstone Project Step-by-Step Guide
Welcome! In this project, you will learn how to build a basic interactive data visualization app using Python. You will work with real-world time series…
- CourseData visualisation in python
- Lesson44 of 34
- Video13 min
- FormatJupyter notebook · 16 code cells
What you'll learn
Data
No separate download needed — the notebook creates or downloads everything it uses.
📓 Full notebook
Download .ipynbCapstone Project: Build an Interactive Data Visualization App#
Welcome! In this project, you will learn how to build a basic interactive data visualization app using Python. You will work with real-world time series data, practice loading and plotting data, and create your own mini-app.
By the end, you will have a hands-on introduction to interactive visualizations, and ways to explore datasets on your own.
Let us get started!
What You Need#
- Python (3.7 or newer recommended)
- Packages: pandas, matplotlib, plotly
Do not worry if you have never used these before; we will walk through everything step by step.
# Setup: Install required packages if needed
import warnings; warnings.filterwarnings('ignore')
try:
import pandas as pd
except ImportError:
!pip install pandas
import pandas as pd
try:
import matplotlib.pyplot as plt
except ImportError:
!pip install matplotlib
import matplotlib.pyplot as plt
try:
import plotly.express as px
except ImportError:
!pip install plotly
import plotly.express as px
Data Setup#
We will use real monthly airline passenger data for this capstone.
This dataset is from 1949 to 1960 and is a popular example for time series.
Let us load it and take a peek.
# Data setup: Load the airline passengers dataset
url = "https://raw.githubusercontent.com/jbrownlee/Datasets/master/airline-passengers.csv"
df = pd.read_csv(url)
print('Shape:', df.shape)
df.head()
# Basic data checks
print('Columns:', df.columns.tolist())
print('Missing entries:', df.isnull().sum().sum())
Lets Visualize: Simple Line Plot#
Time series data shows how things change over time.
A line plot helps us see trends and patterns.
Now, let us make our first visualization!
# Plot the data
plt.figure(figsize=(10,4))
plt.plot(df["Month"], df["Passengers"], marker="o")
plt.title("Monthly Airline Passengers (1949-1960)")
plt.xlabel("Month")
plt.ylabel("Passengers")
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()
# Use Plotly for interactive plotting
fig = px.line(df, x="Month", y="Passengers", title="Monthly Airline Passengers (Interactive)")
fig.show()
Exploring Data with Slices#
Sometimes, you want to focus on just part of the data, like a specific year.
Let us see how to select a time range.
# View data for 1955 only
df["Year"] = df["Month"].str[:4]
df_1955 = df[df["Year"] == "1955"]
print(df_1955)
# Input example: Let user pick a year
user_year = input("Enter a year to view (1949-1960): ")
filtered = df[df["Year"] == user_year]
print(filtered)
Keeping Data Safe: What Happens if I Pick a Year That Does Not Exist?#
Real data sometimes does not have records for every input.
Let us see what happens if you ask for a year not in the dataset.
# What if the year is missing?
wrong_year = input("Try entering a missing year, like 2025: ")
result = df[df["Year"] == wrong_year]
if result.empty:
print("No data found for that year!")
else:
print(result)
Mini App: Pick a Year and Plot That Slice#
Let us put what you have learned into an interactive function.
This function will ask for a year and plot just that year.
Ready?
# Function for year plot
def plot_year(year):
slice = df[df["Year"] == year]
if slice.empty:
print("Sorry, no data for that year.")
return
plt.figure(figsize=(7,3))
plt.plot(slice["Month"], slice["Passengers"], marker="o", color="green")
plt.title(f"Airline Passengers in {year}")
plt.xlabel("Month")
plt.ylabel("Passengers")
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()
# Try the mini app
input_year = input("Type a valid year (1949-1960): ")
plot_year(input_year)
# Sorting and filtering: Find years with most growth
yearly_sum = df.groupby("Year")["Passengers"].sum().reset_index()
top = yearly_sum.sort_values("Passengers", ascending=False)
print(top.head())
# Try a bar plot for total passengers by year
plt.figure(figsize=(8,4))
plt.bar(yearly_sum["Year"], yearly_sum["Passengers"], color="skyblue")
plt.title("Total Passengers by Year")
plt.xlabel("Year")
plt.ylabel("Passengers")
plt.tight_layout()
plt.show()
Experiment: Try Filtering Data by Value#
Want to see only months with over 400 passengers?
Let us filter the table to highlight those periods.
# Filter for months with more than 400 passengers
high_months = df[df["Passengers"] > 400]
print(high_months)
# Try a line plot of the filtered months
if not high_months.empty:
plt.figure(figsize=(10,4))
plt.plot(high_months["Month"], high_months["Passengers"], marker="o", color="red")
plt.title("Months with More Than 400 Passengers")
plt.xlabel("Month")
plt.ylabel("Passengers")
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()
else:
print("No months found with that many passengers.")
# Combining filters: Summer months over 400 passengers
summer_high = df[df["Month"].str[5:7].isin(["06", "07", "08"]) & (df["Passengers"] > 400)]
print(summer_high)
Challenge: Try Creating Your Own Filter#
Can you find months where the passenger number is increasing three months in a row?
Try writing code with a friend, or give it a go below!
# Trend finder: Three months up in a row
df['Increase'] = (df['Passengers'] > df['Passengers'].shift(1)) & (df['Passengers'].shift(1) > df['Passengers'].shift(2))
up_streaks = df[df['Increase']]
print(up_streaks[['Month', 'Passengers']])
Recap: What Did We Learn?#
- How to set up Python for data visualization
- How to download, load, and preview real data
- Ways to filter, slice, and visualize time series
- Interactive mini apps for exploring data
- Tips for combining filters and finding patterns
You are ready to try new datasets on your own! Practice and experiment.
Try More, and Subscribe!#
If you enjoyed building this interactive app, please leave a comment below.
Subscribe to our channel for more fun beginner Python projects!
What real world data would you like to explore next? Let us know!
Found this useful?
All lessons, notebooks and datasets here are free. If they helped you, a coffee keeps new lessons coming.



