💻 Week 01, Day 01 - Lab
Python Foundations Practice
By the end of this lab, you should be able to: i) Navigate VS Code and the Jupyter environment in Nuvolos, ii) Create and use Python variables to store data, iii) Use lists to handle multiple values, iv) Write basic control flow statements (if/else
), v) Print formatted strings to present results.
⏰ Monday, 14 July 2025 | Either 2:00-3.30pm or 3.30-5:00pm 📍 Check your timetable for the location of your class
While in the morning, we would have discussed the “why” of data engineering (thinking about how data is structured and moved), we will eventually need to work on the “how”. Today, we start by ensuring that we all have the same tools and environment, and that we can run some Python code.
The goal today isn’t to learn everything at once. It’s to make sure we’re all starting from the same place, comfortable with our tools, and ready to build our skills together. We’ll start with the absolute basics, the building blocks you would have seen in your pre-course reading, and apply them to a simple, real-world task: working with weather data.
🛣️ Lab Roadmap
This lab document is your guide. It’s designed to be read alongside the ME204_W01D01_Lab.ipynb
Jupyter Notebook. The roadmap will explain the concepts and set up the tasks that you will then complete in the notebook.
Part I: Your First Python Steps (30 min)
First things first: let’s get you set up and running your first lines of code. The goal of this section is to ensure everyone can access the tools and understands the basic workflow.
Getting Started in the Lab Environment
Your class teacher will start by demonstrating how to:
- Log into Nuvolos and launch the VS Code application.
- Navigate the file explorer to find and open the lab notebook:
lab-notebooks/ME204_W01D01_Lab.ipynb
. - Explain the Jupyter Notebook interface: Markdown cells vs. Code cells.
- Run a code cell and explain how variables work in Python.
🎯 ACTION POINTS
Now it’s your turn. Follow the instructions in Part I of the Jupyter Notebook (ME204_W01D01_Lab.ipynb
).
Warm Up.
In section 1.1 of the notebook, you’ll see a code cell. Find today’s temperature for London (a quick web search will do!), then store it in the
london_current_temp
variable. Run the cell to print it.Controlling the Flow.
In section 1.2, you need to decide on your personal threshold for what you consider “too hot”. Set the
too_hot_threshold
variable to this number. Then, complete theif/else
statement to print a different message depending on whether the current temperature is above or below your threshold.
⚠️ Unable to access Nuvolos? Use this fallback plan
If you have any trouble logging into Nuvolos, don’t worry! You can use the local computers in the lab, which have all the necessary software installed.
Follow these steps:
Create Folders:
- Open the File Explorer.
- Navigate to a sensible place, like your
Documents
folder. - Create a new folder named
ME204
. - Inside
ME204
, create another folder namedlab-notebooks
.
Open in VS Code:
- Open the VS Code application.
- Go to the File menu and select Open Folder.
- Navigate to and select the
ME204/lab-notebooks
folder you just created.
Download the Notebook:
- Download the lab notebook file from the link below this section.
- Save or move the downloaded
ME204_W01D01_Lab.ipynb
file into yourME204/lab-notebooks
folder.
You are now set up to work locally!
If nececessary, you can also download the notebook from the link below:
Part II: Building a Forecast with Lists (30 min)
In data work, we rarely deal with single values. We need a way to store collections of data. In Python, the most fundamental way to do this is with a list.
Using Lists to Store Data
Your class teacher will explain:
- What a Python list is and why it’s useful for holding sequential data.
- How to create a list using square brackets
[]
. - How to access specific items in a list using their index (e.g.,
my_list[0]
for the first item).
🎯 ACTION POINTS
Head over to Part II in the notebook and complete the exercises to create your first lists.
Daily Max Temperatures.
In section 2.1, create a list containing the maximum temperatures for the next 7 days. Print the forecast for today (the first element) and tomorrow (the second element).
Daily Min Temperatures.
In section 2.2, do the same for the week’s minimum temperatures.
Daily Conditions.
In section 2.3, create a list of strings describing the week’s weather conditions (e.g.,
'Sunny'
,'Cloudy'
,'Rain'
).
Part III: Summarising the Data (30 min)
Now that you have your data organised in lists, let’s put it all together to create a readable forecast. This task simulates a common data engineering challenge: taking raw data from different sources and transforming it into a useful, human-readable report.
Combining and Presenting Data
Your class teacher will demonstrate:
- How to combine data from multiple lists by accessing elements with the same index.
- How to use f-strings (
f"..."
) to create formatted strings that mix text and variables.
🎯 ACTION POINTS
In Part III of the notebook, complete the summary tasks.
Day-by-Day Summary.
In section 3.1, use the lists you created to print a daily forecast summary for each day of the week. The notebook provides an example for the first day. You will need to replicate this for the other days, combining elements from your different lists.
Weekly Summary.
In a new code cell under section 3.2, it’s time for some analysis. Write the code to calculate:
- The average high temperature for the week.
- The average low temperature for the week.
- The total temperature range for the entire week (the difference between the highest high and the lowest low).
✨ Wrap-up
Great work! You’ve successfully set up your environment, worked with fundamental Python data structures, and produced a simple data summary. You now have the foundation you need to start working with more complex data.
Tomorrow, we’ll see how we can get this kind of data automatically from a web API instead of typing it in by hand.
🚀 Bonus Task: From Python Lists to pandas
DataFrames
This section is for students who are already comfortable with the basics and want a challenge.
In the lab, you worked with several lists to manage weather data. That works, but it can get complicated to keep everything in sync. Let’s see a more powerful and standard way to work with tabular data using the pandas
library.
🎯 ACTION POINTS
In the final section of your notebook, follow these steps:
Create a new section header.
At the very bottom of your notebook, click the
+ Markdown
button to create a new Markdown cell. In the new cell, type:## Bonus: Using Pandas
and then run the cell.Restructure the data.
Click the
+ Code
button to create a new code cell below your new header. In this new cell, define a single list of dictionaries. This is a very common data structure, similar to what you might get from a web API. The notebook provides the code for this.Create a DataFrame.
In the same code cell, add the lines to import the
pandas
library and usepd.DataFrame()
to convert your list of dictionaries into a DataFrame. Thedf.head()
command will display the first 5 rows of your new, structured object.Save your work to a CSV file.
Create one last code cell. Add the code
df.to_csv('london_weather.csv', index=False)
to save your DataFrame as a Comma-Separated Values (CSV) file. Theindex=False
part is important to avoid writing the DataFrame’s row numbers into the file.Check your work!
In the file explorer on the left of your screen, you should now see a new file:
london_weather.csv
. Double-click it. VS Code will open it right there, and you’ll see your data perfectly organised in a spreadsheet. You’ve just created a file that almost anyone can open and understand!
Ask the lecturer or the class teacher (via Slack is fine!) if you have any questions about this bonus task.