Mathew K Analytics

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…

⬇ 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

Welcome 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
Hello, world! Climate and Python together.
# 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()
Dataset shape: (3650, 2)
Date Temp
0 1981-01-01 20.7
1 1981-01-02 17.9
2 1981-01-03 18.8
3 1981-01-04 14.6
4 1981-01-05 15.8
# 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()
No description has been provided for this image

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)
City: Sydney
Average temperature: 17.5
Days measured: 365

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)
Hello, Alex
You guessed: Sydney
# 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)
Some sample temperatures: [13, 17, 15, 14, 18]
With another temp: [13, 17, 15, 14, 18, 20]
# Step 5: Basic math and statistics
total = sum(temps_sample)
count = len(temps_sample)
average = total / count
print("Average temperature:", average)
Average temperature: 16.166666666666668

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))
First five day's temperatures: [20.7, 17.9, 18.8, 14.6, 15.8]
# 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)
Safely found temperature? True
Safely found Rainfall column? False
# 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)
How many days above 20 degrees? 74
Date Temp
0 1981-01-01 20.7
8 1981-01-09 21.8
13 1981-01-14 21.5
# Step 8: Sorting data
sorted_days = climate_df.sort_values("Temp", ascending=False)
print("Hottest recorded temperatures at the top:")
sorted_days.head()
Hottest recorded temperatures at the top:
Date Temp
410 1982-02-15 26.3
384 1982-01-20 25.2
39 1981-02-09 25.0
14 1981-01-15 25.0
17 1981-01-18 24.8
# 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()
No description has been provided for this image
# 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)
Monthly average temperatures: [15.03032258 15.37375887 14.56548387 12.08833333  9.86645161  7.27833333
  6.69258065  7.89129032  8.97633333 10.30935484 12.47966667 13.85194805]
# 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()
No description has been provided for this image
# 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)
        City  Jan  Jul
0     Sydney   22   13
1  Melbourne   20   10
2   Brisbane   25   15

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()
No description has been provided for this image
# Step 14: Challenge! What city is farthest north?
northern = multi_city.loc[multi_city["Lat"].idxmax()]
print("Farthest north city:", northern["City"])
Farthest north city: Brisbane

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.