Mathew K Analytics

Lesson 44 · Python for Data Science

4 - Building a Weather Trends Dashboard in Python with Data Visualization

In this lesson, we will use Python to collect, process, and display weather data. You will learn Python basics while making a mini dashboard. Weather…

⬇ 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: Build a Weather Trends Dashboard!#

In this lesson, we will use Python to collect, process, and display weather data.

You will learn Python basics while making a mini dashboard.

Weather affects our daily life, so these skills are both fun and practical!

# Let us start! First, let us print a welcome message.

print('Hello! Let us explore weather trends with Python!')
Hello! Let us explore weather trends with Python!
# Let us ask the user for their name.
user_name = input('What is your name? ')
print('Welcome,', user_name, '! Let us start learning.')
Welcome, Alex ! Let us start learning.
 

Why learn about weather data?#

  • Weather is everywhere! From rain and snow to sunshine.
  • Knowing how to handle data is a key computer skill.
  • You will use basic and advanced Python ideas to build your dashboard.
# Let us store some sample weather data.
weather = ['sunny', 'rainy', 'cloudy', 'sunny', 'snowy']
print('Weather data:', weather)
Weather data: ['sunny', 'rainy', 'cloudy', 'sunny', 'snowy']
# To see just the first day, use an index.
first_day = weather[0]
print('The first day was', first_day)
The first day was sunny
# To add a new weather report, use append.
weather.append('windy')
print(weather)
['sunny', 'rainy', 'cloudy', 'sunny', 'snowy', 'windy']
# Let us count how many times it was sunny.
sunny_days = weather.count('sunny')
print('Number of sunny days:', sunny_days)
Number of sunny days: 2
# Sometimes we make mistakes. Here is how to safely get an item.
try:
    print(weather[10])
except IndexError:
    print('That day does not exist!')
    
That day does not exist!
# What if you want to update a value?
weather[1] = 'foggy'
print(weather)
['sunny', 'foggy', 'cloudy', 'sunny', 'snowy', 'windy']
# To remove a weather type, use remove.
weather.remove('foggy')
print(weather)
['sunny', 'cloudy', 'sunny', 'snowy', 'windy']
# Built-in functions can help! Let us find unique weather days.
unique_weather = set(weather)
print('Unique types:', unique_weather)
Unique types: {'snowy', 'windy', 'sunny', 'cloudy'}
# Time to loop through all weather days.
for day in weather:
    print('Weather that day was:', day)
    
Weather that day was: sunny
Weather that day was: cloudy
Weather that day was: sunny
Weather that day was: snowy
Weather that day was: windy
# Create a new list based on a condition.
rainy_days = [w for w in weather if w == 'rainy']
print('Rainy days:', rainy_days)
Rainy days: []
# What about sorting the weather alphabetically?
sorted_weather = sorted(weather)
print(sorted_weather)
['cloudy', 'snowy', 'sunny', 'sunny', 'windy']
# Let us 'join' all weather descriptions into one string.
weather_string = ', '.join(weather)
print('All weather:', weather_string)
All weather: sunny, cloudy, sunny, snowy, windy
# Let us add some temperature data.
temps = [72, 68, 65, 70, 60]
for temp in temps:
    print('Recorded temp:', temp, 'degrees')
    
Recorded temp: 72 degrees
Recorded temp: 68 degrees
Recorded temp: 65 degrees
Recorded temp: 70 degrees
Recorded temp: 60 degrees
# What if you want to get only warm days?
warm_days = [t for t in temps if t >= 70]
print('Warm days:', warm_days)
Warm days: [72, 70]
# Combining weather and temperature for a dashboard.
for i in range(len(weather)):
    print('Day', i + 1, ':', weather[i], '-', temps[i], 'degrees')
    
Day 1 : sunny - 72 degrees
Day 2 : cloudy - 68 degrees
Day 3 : sunny - 65 degrees
Day 4 : snowy - 70 degrees
Day 5 : windy - 60 degrees
# Real-world data: ask the user for a new day's weather and temperature.
new_weather = input('Type the weather for today: ')
new_temp = int(input('Temperature for today? '))
weather.append(new_weather)
temps.append(new_temp)
print('Updated lists:')
print(weather)
print(temps)
Updated lists:
['sunny', 'cloudy', 'sunny', 'snowy', 'windy', 'rainy']
[72, 68, 65, 70, 60, 66]
 
# Mini-project time! Let us show average temperature and most common weather.
avg_temp = sum(temps) / len(temps)
from collections import Counter
common_weather = Counter(weather).most_common(1)[0][0]
print('Average temp:', round(avg_temp, 1))
print('Most frequent weather:', common_weather)
Average temp: 66.8
Most frequent weather: sunny
# Mini-project part 2: Make a weather summary for each day.
for i, day in enumerate(weather):
    print(f'Day {i + 1}: {day} and {temps[i]} degrees.')
    
Day 1: sunny and 72 degrees.
Day 2: cloudy and 68 degrees.
Day 3: sunny and 65 degrees.
Day 4: snowy and 70 degrees.
Day 5: windy and 60 degrees.
Day 6: rainy and 66 degrees.
# Practice tip: Double-check your input types.
user_temp = input('Enter a number: ')
try:
    user_temp = int(user_temp)
    print('That is a valid number!')
except ValueError:
    print('That was not a valid number.')
    
That was not a valid number.
 
# Common issue: data lengths must match.
if len(weather) != len(temps):
    print('Warning: Weather and temp data do not match!')
else:
    print('Data is lined up correctly!')
    
Data is lined up correctly!
# Advanced tip: Use zip to pair up data.
for kind, temp in zip(weather, temps):
    print('Weather:', kind, '| Temp:', temp)
    
Weather: sunny | Temp: 72
Weather: cloudy | Temp: 68
Weather: sunny | Temp: 65
Weather: snowy | Temp: 70
Weather: windy | Temp: 60
Weather: rainy | Temp: 66
# Challenge: Make a daily summary using input.
summary = input('Describe your week in three words: ')
print('Your weather week:', summary)
Your weather week: Rainy fun chilly
 

What we learned#

  • How to store, update, and show weather data
  • How to use input, lists, and loops
  • Building up a simple dashboard piece by piece
  • Using Python for practical projects

You did it! Keep exploring Python.#

If you enjoyed this, please like, comment, and subscribe. Share this with a friend who wants to learn Python!


See you in the next lesson for more Python fun!

Found this useful?

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