Lesson 43 · Data visualisation in python
Climate Data Analysis & Geospatial Visualization: Expert Case Study Techniques
In this lesson, you will learn Python basics while exploring climate data and maps. We will cover Python syntax step by step with real-world weather and…
- CourseData visualisation in python
- Lesson43 of 34
- Video9 min
- FormatJupyter notebook · 18 code cells
What you'll learn
Data
No separate download needed — the notebook creates or downloads everything it uses.
📓 Full notebook
Download .ipynbWelcome to Python: Climate and Geospatial Visualization Case Study#
In this lesson, you will learn Python basics while exploring climate data and maps.
We will cover Python syntax step by step with real-world weather and geospatial datasets.
# Let us start by suppressing warnings to keep output clean
import warnings
warnings.filterwarnings("ignore")
Step 1: Basic Printing and Comments#
Python uses print() to display messages. Comments with # help explain code.
# Print a welcome message
print("Hello, world! Climate and Python together.")
# This is a comment: Comments never run as code
# Data setup
import pandas as pd
url = "https://raw.githubusercontent.com/jbrownlee/Datasets/master/daily-min-temperatures.csv"
climate_df = pd.read_csv(url)
print("Dataset shape:", climate_df.shape)
climate_df.head()
# Simple plot: temperature over time
import matplotlib.pyplot as plt
plt.figure(figsize=(10,4))
plt.plot(climate_df["Date"], climate_df["Temp"])
plt.xlabel("Date")
plt.ylabel("Daily Min Temperature")
plt.title("Daily Minimum Temperatures - Sydney")
plt.xticks([])
plt.show()
Step 2: Variables & Types#
Variables store values. You pick the name.
city = "Sydney"
average_temp = 17.5
days_measured = 365
print("City:", city)
print("Average temperature:", average_temp)
print("Days measured:", days_measured)
Step 3: User Input#
You can ask users to type values into your code using input().
user_name = input("What is your name? ")
city_guess = input("What city do you think this weather data is from? ")
print("Hello,", user_name)
print("You guessed:", city_guess)
# Step 4: Lists for Sequences
temps_sample = [13, 17, 15, 14, 18]
print("Some sample temperatures:", temps_sample)
# Add a new temperature
temps_sample.append(20)
print("With another temp:", temps_sample)
# Step 5: Basic math and statistics
total = sum(temps_sample)
count = len(temps_sample)
average = total / count
print("Average temperature:", average)
Step 6: Working with DataFrames#
A pandas DataFrame is like a table or a spreadsheet.
# Select first 5 temperature values
five_days = climate_df["Temp"].iloc[:5]
print("First five day's temperatures:", list(five_days))
# Safe column access with get
safe_temp = climate_df.get("Temp", None)
safe_notfound = climate_df.get("Rainfall", None)
print("Safely found temperature?", safe_temp is not None)
print("Safely found Rainfall column?", safe_notfound is not None)
# Step 7: Filtering data by condition
hot_days = climate_df[climate_df["Temp"] > 20]
print("How many days above 20 degrees?", len(hot_days))
hot_days.head(3)
# Step 8: Sorting data
sorted_days = climate_df.sort_values("Temp", ascending=False)
print("Hottest recorded temperatures at the top:")
sorted_days.head()
# Step 9: Simple line plot for filtered data
plt.figure(figsize=(8,3))
plt.plot(hot_days["Date"], hot_days["Temp"], color="red")
plt.title("Hot Days Only")
plt.ylabel("Temperature")
plt.xlabel("Date")
plt.xticks([])
plt.show()
# Step 10: Grouping data - monthly average
climate_df["Date"] = pd.to_datetime(climate_df["Date"])
climate_df["Month"] = climate_df["Date"].dt.month
monthly_avg = climate_df.groupby("Month")["Temp"].mean()
print("Monthly average temperatures:", monthly_avg.values)
# Step 11: Quick bar chart - average temperature by month
plt.figure(figsize=(8,3))
plt.bar(monthly_avg.index, monthly_avg.values, color="cornflowerblue")
plt.xlabel("Month")
plt.ylabel("Average Temp")
plt.title("Average Temperature by Month")
plt.show()
# Step 12: Combine data - make a DataFrame from scratch
import numpy as np
cities = ["Sydney", "Melbourne", "Brisbane"]
jan_avg = [22, 20, 25]
jul_avg = [13, 10, 15]
multi_city = pd.DataFrame({"City": cities, "Jan": jan_avg, "Jul": jul_avg})
print(multi_city)
Mini-project: Map visualization!#
Now let us map our cities using latitude and longitude.
# Step 13: Quick scatter plot for city coordinates
lat = [-33.8688, -37.8136, -27.4698]
lon = [151.2093, 144.9631, 153.0251]
multi_city["Lat"] = lat
multi_city["Lon"] = lon
plt.figure(figsize=(6,6))
plt.scatter(multi_city["Lon"], multi_city["Lat"], color="lawngreen", s=200)
for i, row in multi_city.iterrows():
plt.text(row["Lon"]+0.2, row["Lat"], row["City"], fontsize=12)
plt.xlabel("Longitude")
plt.ylabel("Latitude")
plt.title("Major Australian Cities - Location Map")
plt.show()
# Step 14: Challenge! What city is farthest north?
northern = multi_city.loc[multi_city["Lat"].idxmax()]
print("Farthest north city:", northern["City"])
Congrats: You combined climate and mapping in Python.#
You can now load data, do simple math, plot, and map real places.
What next? Practice and share!#
- Try plotting rainfall data if you can find it.
- Add more cities and markers!
- Tweak colors, chart labels, and styles.
For updates, like and subscribe to our channel. See you next lesson!
Found this useful?
All lessons, notebooks and datasets here are free. If they helped you, a coffee keeps new lessons coming.



