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…
- CoursePython for Data Science
- Lesson44 of 38
- Video12 min
- FormatJupyter notebook · 29 code cells
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!')
# Let us ask the user for their name.
user_name = input('What is your name? ')
print('Welcome,', user_name, '! 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)
# To see just the first day, use an index.
first_day = weather[0]
print('The first day was', first_day)
# To add a new weather report, use append.
weather.append('windy')
print(weather)
# Let us count how many times it was sunny.
sunny_days = weather.count('sunny')
print('Number of sunny days:', sunny_days)
# Sometimes we make mistakes. Here is how to safely get an item.
try:
print(weather[10])
except IndexError:
print('That day does not exist!')
# What if you want to update a value?
weather[1] = 'foggy'
print(weather)
# To remove a weather type, use remove.
weather.remove('foggy')
print(weather)
# Built-in functions can help! Let us find unique weather days.
unique_weather = set(weather)
print('Unique types:', unique_weather)
# Time to loop through all weather days.
for day in weather:
print('Weather that day was:', day)
# Create a new list based on a condition.
rainy_days = [w for w in weather if w == 'rainy']
print('Rainy days:', rainy_days)
# What about sorting the weather alphabetically?
sorted_weather = sorted(weather)
print(sorted_weather)
# Let us 'join' all weather descriptions into one string.
weather_string = ', '.join(weather)
print('All weather:', weather_string)
# Let us add some temperature data.
temps = [72, 68, 65, 70, 60]
for temp in temps:
print('Recorded temp:', temp, '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)
# Combining weather and temperature for a dashboard.
for i in range(len(weather)):
print('Day', i + 1, ':', weather[i], '-', temps[i], '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)
# 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)
# 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.')
# 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.')
# 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!')
# Advanced tip: Use zip to pair up data.
for kind, temp in zip(weather, temps):
print('Weather:', kind, '| Temp:', temp)
# Challenge: Make a daily summary using input.
summary = input('Describe your week in three words: ')
print('Your weather week:', summary)
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.



