Lesson 68 · Data Science Projects
Building an Interactive Retail Sales Dashboard with Plotly and Streamlit in Python
Welcome! In this course, you will explore essential data mining concepts using Python. What is data mining? Data mining means discovering patterns within…
- CourseData Science Projects
- Lesson68 of 33
- Video15 min
- FormatJupyter notebook · 13 code cells
What you'll learn
Data
No separate download needed — the notebook creates or downloads everything it uses.
📓 Full notebook
Download .ipynbData Mining with Python: Retail Sales Dashboard (Week 12)#
Welcome! In this course, you will explore essential data mining concepts using Python.
What is data mining? Data mining means discovering patterns within data. It is used in business, health, government, and more.
You will learn by working with real datasets, like Retail Supermarket Sales, Titanic survival, and Airbnb listings.
This week: Build foundations for your own interactive sales dashboard.
# Suppress warnings for clean outputs
import warnings; warnings.filterwarnings("ignore")
import numpy as np
np.random.seed(42)
# Data setup (Supermarket Sales Dataset)
import pandas as pd
url = 'https://raw.githubusercontent.com/juarezefren/datasets/main/supermarket_sales.csv'
df = pd.read_csv(url)
print(df.shape)
print(df.head(3))
What is in the Supermarket Sales data?#
Each row is a single transaction at a supermarket.
Columns show information like:
- Branch (store location)
- Date and Time
- Product Line
- Customer Type
- Gender
- Total Sale
We will use this data to practice cleaning and basic analysis.
# See all column names
print(df.columns.tolist())
# Basic data info and types
df.info()
# Look for missing values
print(df.isnull().sum())
# Parse 'Date' as datetime type
df['Date'] = pd.to_datetime(df['Date'])
print(df['Date'].dtype)
# Clean whitespace in column names (if needed)
df.columns = df.columns.str.strip()
# Quick describe of number columns
print(df.describe())
# Find unique values for Branch and Product line
print(df['Branch'].unique())
print(df['Product line'].unique())
Let us make our first sales plot!#
We can quickly see how sales change by day using a line chart.
Charts are great for finding trends you can show others.
import matplotlib.pyplot as plt
# Total sales per day
daily_sales = df.groupby('Date')['Total'].sum()
plt.figure(figsize=(10,4))
daily_sales.plot()
plt.xlabel('Date')
plt.ylabel('Total Sales')
plt.title('Total Sales Per Day')
plt.tight_layout()
plt.show()
# Sales totals by branch bar chart
branch_sales = df.groupby('Branch')['Total'].sum()
branch_sales.plot(kind='bar', color=['orange','blue','green'])
plt.ylabel('Total Sales')
plt.title('Total Sales by Branch')
plt.tight_layout()
plt.show()
# Product line sales breakdown pie chart
product_sales = df.groupby('Product line')['Total'].sum()
product_sales.plot(kind='pie', autopct='%1.1f%%', figsize=(6,6))
plt.title('Sales Share by Product Line')
plt.ylabel('')
plt.tight_layout()
plt.show()
Practice: Explore Data Yourself#
Try creating your own charts.
- Plot sales by Customer Type or Gender.
- Group by month instead of day.
You can use:
- df.groupby(...)
- .sum(), .mean(), .count()
This practice will help you get familiar with Python data tools.
# Example: Group sales by Gender
gender_sales = df.groupby('Gender')['Total'].sum()
gender_sales.plot(kind='bar', color=['pink', 'lightblue'])
plt.title('Total Sales by Gender')
plt.ylabel('Total Sales')
plt.show()
Next Steps: Get Ready for Streaming Dashboards!#
You have learned how to load, explore, and visualize supermarket data.
Coming up: Make interactive dashboards using Plotly and Streamlit.
Next time you will learn to build web apps from this notebook analysis.
If you enjoyed, subscribe to the channel and practice these skills with new datasets.
Found this useful?
All lessons, notebooks and datasets here are free. If they helped you, a coffee keeps new lessons coming.



