Lesson 42 · Data visualisation in python
2 - Case Study Project - Sales and Marketing Dashboard
Welcome! In this lesson, we will build a simple sales and marketing dashboard using Python. You will learn how to load data, explore patterns, and gain…
- CourseData visualisation in python
- Lesson42 of 34
- Video10 min
- FormatJupyter notebook · 17 code cells
What you'll learn
Data
No separate download needed — the notebook creates or downloads everything it uses.
📓 Full notebook
Download .ipynbCase Study Project: Sales and Marketing Dashboard#
Welcome! In this lesson, we will build a simple sales and marketing dashboard using Python.
You will learn how to load data, explore patterns, and gain meaningful insights.
Perfect for beginners. Let us dive in!
Step 1: Getting Python Ready#
First, let us set up our notebook.
We will import the tools we need, and make sure our notebook is neat.
# Import key libraries
import warnings; warnings.filterwarnings("ignore")
import pandas as pd
import matplotlib.pyplot as plt
# Our dashboard will use pandas for data and matplotlib for charts
# Data setup
url = "https://raw.githubusercontent.com/jbrownlee/Datasets/master/airline-passengers.csv"
df = pd.read_csv(url)
print("Shape:", df.shape)
df.head()
# First look at the data
df.info()
print("\nMissing values per column:")
print(df.isnull().sum())
# Preview a simple time series plot
plt.figure(figsize=(10,5))
plt.plot(df["Month"], df["Passengers"])
plt.title("Monthly Airline Passengers Over Time")
plt.xlabel("Month")
plt.ylabel("Passengers")
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()
Step 2: Exploring the Data#
It is vital to look at data from different angles.
Let us explore summary numbers and spot trends.
# Basic summary statistics
df["Passengers"].describe()
# Convert Month to a real date
df["Month"] = pd.to_datetime(df["Month"])
df = df.set_index("Month")
df.head(3)
# Drill down: Which months have the highest sales?
top_months = df.sort_values("Passengers", ascending=False).head(5)
print(top_months)
Step 3: Avoiding Common Errors#
It is natural to make mistakes.
Let us see how to safely access data and handle errors as you go.
# What if we look for a month that is not there?
try:
print(df.loc["2050-01"])
except KeyError:
print("Month not found!")
# Let us fill missing data, just in case
df_fixed = df.copy()
df_fixed["Passengers"] = df_fixed["Passengers"].fillna(method="ffill")
Step 4: Making Changes and Updates#
Good dashboards let you update or add to your data easily.
Let us practice adding, editing, and deleting values.
# Editing a passenger total
df_copy = df.copy()
the_month = df_copy.index[0]
df_copy.at[the_month, "Passengers"] = 999
df_copy.head(1)
# Add a new summary row for all data
summary = pd.DataFrame({"Passengers": [df_copy["Passengers"].sum()]}, index=["Total"])
df_summary = pd.concat([df_copy, summary])
df_summary.tail()
# Remove the last row in the summary table
df_summary = df_summary.iloc[:-1]
df_summary.tail()
Step 5: Grouping and Aggregation#
Big datasets have repeating patterns.
Let us find yearly totals and compare across years.
# Find yearly totals
df["Year"] = df.index.year
yearly = df.groupby("Year")["Passengers"].sum().reset_index()
print(yearly)
# Quick bar chart - yearly totals
plt.bar(yearly["Year"], yearly["Passengers"])
plt.title("Yearly Total Passengers")
plt.xlabel("Year")
plt.ylabel("Passengers")
plt.show()
Step 6: Filtering, Sorting, and Mini-Project Preview#
Sometimes you want to look at just part of your data.
Let us select just the busiest months and preview our dashboard.
# Find all months above the average
avg = df["Passengers"].mean()
busy_months = df[df["Passengers"] > avg]
print(f"Busiest months (>{avg:.2f} passengers): {len(busy_months)} found.")
busy_months.head(3)
# Mini-Project: Simple Sales Dashboard Function
def sales_dashboard(df):
print("Latest month:", df.index.max().strftime("%b %Y"))
print("Total passengers:", df["Passengers"].sum())
print("Mean passengers per month:", int(df["Passengers"].mean()))
print("Best month:", df["Passengers"].idxmax().strftime("%b %Y"), "with", df["Passengers"].max())
sales_dashboard(df)
# Mini-Project Part 2: Year-on-Year Growth Calculation
yearly["Growth"] = yearly["Passengers"].pct_change().fillna(0) * 100
for i, row in yearly.iterrows():
print(f"Year {int(row['Year'])}: {int(row['Passengers'])} passengers, {row['Growth']:.1f}% growth")
Step 7: Best Practices, Troubleshooting, and Extra Tips#
You are doing great! Let us wrap up with tips for real-world use.
- Always check your data for missing or odd values.
- Save your figures and tables for future use.
- Automate everything into functions as much as possible.
Next: Challenge exercises for you.
Challenge: Try These Yourself!#
- Plot only the last 12 months of data.
- Find the average passengers for each quarter of the year.
- Build your own prettier bar chart showing the top 3 years.
Experiment, and share your ideas.
Recap#
Let us review what you have learned:
- How to load, explore, and clean data in Python
- How to make meaningful charts and dashboards
- How to find trends and share insights
Keep practicingthis is just the beginning!
Next Steps & Call To Action#
If you enjoyed building this dashboard, give this video a like and subscribe to our channel.
Comment below: What business question would you answer with your own dashboard?
Happy coding!
Found this useful?
All lessons, notebooks and datasets here are free. If they helped you, a coffee keeps new lessons coming.



