Mathew K Analytics

Lesson 3 · Data visualisation in python

How to Set Up Python and Jupyter Notebook for Data Visualization Beginners

Welcome! This lesson will guide you through setting up a Jupyter Notebook to visualize data using Python. No experience needed. You will learn how to: Run…

⬇ Download notebookOpen in Colab ↗

What you'll learn

Data

No separate download needed — the notebook creates or downloads everything it uses.

📓 Full notebook

Download .ipynb

Python Jupyter Notebook Setup for Data Visualization#

Welcome! This lesson will guide you through setting up a Jupyter Notebook to visualize data using Python. No experience needed.

You will learn how to:

  • Run Python code cells in Jupyter
  • Import popular data visualization libraries
  • Download and preview real-world datasets
  • Make your first plot of real data
import warnings
warnings.filterwarnings("ignore")

What is a Jupyter Notebook?#

A Jupyter Notebook lets you run and test Python code in small, easy blocks called cells.

  • You can mix code and text to organize your work
  • All your work appears in one place
# This is a comment. It will not run.

print("Hello, data world!")
Hello, data world!
name = input("What is your name? ")
print("Welcome, " + name + "!")
Welcome, Alex!

Setting Up for Data Visualization#

Data visualization is a way to make numbers and patterns easier to see.

We will use two popular Python libraries:

  • pandas (reads and works with data tables)
  • matplotlib (makes charts and plots)
import pandas as pd
import matplotlib.pyplot as plt
# Data setup

url = "https://raw.githubusercontent.com/jbrownlee/Datasets/master/airline-passengers.csv"
df = pd.read_csv(url)
print("Data shape:", df.shape)
df.head()
Data shape: (144, 2)
Month Passengers
0 1949-01 112
1 1949-02 118
2 1949-03 132
3 1949-04 129
4 1949-05 121

What is in this Data?#

This table has two columns:

  • Month: The year and month.
  • Passengers: The number of airline passengers in that month.
plt.figure(figsize=(10,5))
plt.plot(df["Month"], df["Passengers"])
plt.title("Airline Passengers Over Time")
plt.xlabel("Month")
plt.ylabel("Number of Passengers")
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()
No description has been provided for this image
# What if you want just one column?

months = df["Month"]
months.head()
0    1949-01
1    1949-02
2    1949-03
3    1949-04
4    1949-05
Name: Month, dtype: object
# Checking for missing values

missing = df.isnull().sum()
print("Missing values per column:")
print(missing)
Missing values per column:
Month         0
Passengers    0
dtype: int64
# Quick column stats

print(df["Passengers"].describe())
count    144.000000
mean     280.298611
std      119.966317
min      104.000000
25%      180.000000
50%      265.500000
75%      360.500000
max      622.000000
Name: Passengers, dtype: float64
# Adding a new column

df["Year"] = df["Month"].apply(lambda x: x.split("-")[0])
df.head()
Month Passengers Year
0 1949-01 112 1949
1 1949-02 118 1949
2 1949-03 132 1949
3 1949-04 129 1949
4 1949-05 121 1949
# Group by year

yearly = df.groupby("Year")["Passengers"].sum()
print(yearly)
Year
1949    1520
1950    1676
1951    2042
1952    2364
1953    2700
1954    2867
1955    3408
1956    3939
1957    4421
1958    4572
1959    5140
1960    5714
Name: Passengers, dtype: int64
# Bar chart of total passengers per year

yearly.plot(kind="bar", figsize=(8,4), color="skyblue")
plt.title("Total Passengers Each Year")
plt.ylabel("Passengers")
plt.xlabel("Year")
plt.show()
No description has been provided for this image
# Safe access: What if column does not exist?

try:
    print(df["NotARealColumn"])
except KeyError:
    print("Column not found!")
    
Column not found!
# Mini-project: Find the month with most passengers

max_row = df.loc[df["Passengers"].idxmax()]
print("Month with most passengers:")
print(max_row)
Month with most passengers:
Month         1960-07
Passengers        622
Year             1960
Name: 138, dtype: object
# Extra: Save a plot as a file

plt.figure(figsize=(6,3))
plt.plot(df["Month"], df["Passengers"], color="green")
plt.title("Monthly Air Passengers")
plt.tight_layout()
plt.savefig("airline_passengers_plot.png")
print("Plot saved as airline_passengers_plot.png")
Plot saved as airline_passengers_plot.png
No description has been provided for this image
# Practice: Try your own data

custom_url = input("Enter a CSV URL for another time series dataset, or press Enter to use the same one: ")
if not custom_url:
    custom_url = "https://raw.githubusercontent.com/jbrownlee/Datasets/master/shampoo.csv"
custom_df = pd.read_csv(custom_url)
print("Preview of your chosen dataset:")
print(custom_df.head())
Preview of your chosen dataset:
  Month  Sales
0  1-01  266.0
1  1-02  145.9
2  1-03  183.1
3  1-04  119.3
4  1-05  180.3

Challenge: Explore and Plot Another Dataset#

Can you find the biggest value in a new column?

  • Try using describe() and idxmax() on your practice dataset.
  • Make a line plot of any numerical data.

Remember, experiment and see what happens!

Recap#

Great job! Here is what you have done:

  • Learned to run Python cells in Jupyter
  • Loaded real data with pandas
  • Made and customized several charts
  • Practiced exploring new datasets

Keep trying new datasets and plots to build your skills.

Thanks and Next Steps#

Practicing with your own data is the fastest way to learn.

Try a challenge from this lesson, or check out more tutorials on our channel.

Please like, subscribe, or leave a comment if this helped you!

Found this useful?

All lessons, notebooks and datasets here are free. If they helped you, a coffee keeps new lessons coming.