π» Week 01 Lab
Exploring the Open Food Facts API
By the end of this lab, you should be able to: i) Understand what an API is and how to request data from one, ii) Learn the structure of JSON data and how Python represents it, iii) Practise inspecting unfamiliar data systematically, iv) Transform JSON data into a pandas DataFrame for analysis.
This lab points you to resources that will help you review the basics of Jupyter Notebooks, on data manipulation with βpure Pythonβ (exploring JSON data structures) vs the pandas library, and visualisation. We also make the point to discuss how to use libraries like requests to collect data from APIs online.
DS205 Whisperer @DS205 Β· 20 January 2026 3:35am
I got out of bed just to tell you this: just for todayβs lab, avoid using AI tools!!
Use today as a way to establish your own baseline: take note of your knowledge gaps so you can review them later (with the help of AI tools). If you use AI now, you wonβt know what you donβt master yet.
β€οΈ 3 likes
5 Slack conversations
π Preparation
- Review the π£οΈ Week 01 Lecture
- Ensure you can access Nuvolos and launch VS Code:
Nuvolos - First Time - Familiarise yourself with the Open Food Facts website and their API documentation
π£οΈ Lab Roadmap
| Part | Activity Type | Focus | Time | Outcome |
|---|---|---|---|---|
| Introduction | π£οΈ Class Discussion | Lab introductions and setup | 10 min | Get familiar with the lab environment |
| Section 1 | π€ Teaching Moment | Collecting data from APIs | 20 min | Understand API requests and JSON responses |
| Section 2 | π€ Teaching Moment | Making sense of JSON data | 15 min | Systematically inspect nested data structures |
| Section 3 | π€ Teaching Moment | Working with DataFrames | 25 min | Transform JSON to pandas and explore data |
| Section 4 | βΈοΈ Self-paced | Visualising the data | Remaining time | Create visualisations with seaborn |
| Section 5 | βΈοΈ Self-paced | Playground | Take-home | Explore and discover patterns |
π NOTE: Whenever you see a π€ TEACHING MOMENT, this means your class teacher deserves your full attention!
Section 1: Collect data (20 min)
This section is a TEACHING MOMENT
Your class teacher will demonstrate how to request data from the Open Food Facts API using the requests library and explain the structure of API responses.
Follow your class teacher as they:
- Open
notebooks/W01-NB02-Lab-Open-Food-Facts.ipynbin VS Code inside
Nuvolos - Run through the code in Section 1: Collect data
- Explain what an API is and how HTTP requests work
π― ACTION POINT 01
Complete the action points in the notebook:
Familiarise yourself with the website: Visit the Open Food Facts website and search for a product you recognise. Note what information is displayed.
Check out the API documentation: Bookmark the API documentation and API v2 reference pages. You donβt need to understand everything now, but know where to find these resources.
Run the API request code: Execute the cells that make the API request and examine the response structure.
Section 2: Making sense of the data (15 min)
This section is a TEACHING MOMENT
Your class teacher will demonstrate a systematic approach to inspecting unfamiliar JSON data structures.
Follow your class teacher as they:
- Show how to check data types (
type(),isinstance()) - Demonstrate inspecting dictionary keys and list contents
- Walk through the systematic inspection pattern: type β keys/len β nested structures
π― ACTION POINT 02
In the notebook, complete the table describing each key in the API response:
- What is the Python type of each key?
- What does each key represent?
π― ACTION POINT 03
Write Python code to verify your answers about the data types. Use the systematic inspection pattern shown by your instructor.
Section 3: Itβs more productive to work with tables (25 min)
This section is a TEACHING MOMENT
Your class teacher will demonstrate how to transform JSON data into pandas DataFrames and work with nested data structures.
Follow your class teacher as they:
- Convert the list of product dictionaries to a DataFrame
- Explain how
pd.json_normalize()handles nested dictionaries - Show how to concatenate DataFrames to combine data
- Demonstrate basic DataFrame exploration methods (
.head(),.info(),.describe(),.value_counts())
π― ACTION POINTS
- Run all code cells in Section 3
- Explore the DataFrame using the methods demonstrated
- Understand how the
nutrimentscolumn (nested dictionaries) is expanded into multiple columns - Examine the NOVA classification distribution in your data
Section 4: Visualising the data (remaining time / take-home)
βΈοΈ Continue at your own pace
This section introduces data visualisation with seaborn and matplotlib. Work through it during the remaining lab time or complete it as take-home practice.
π― ACTION POINTS
- Run the visualisation code in Section 4
- Examine the histograms showing nutritional data distributions
- Review the NOVA classification donut chart
- Consider what patterns you observe in the visualisations
Section 5: Playground (take-home)
βΈοΈ Continue at your own pace
Now itβs your turn to explore and discover something interesting about the breakfast cereals data.
π― SUGGESTED ACTIVITIES
- Whatβs the relationship between sugar content and energy?
- Which product has the highest protein content?
- π Challenge: Can you collect the next batch of 50 breakfast cereals? (You will need to familiarise yourself with the API documentation to handle pagination)
π Personal Reflection
Complete the reflection section in the notebook:
- What did you find most surprising about the data?
- What questions would you want to answer if you had more time?
Appendix | Resources, links, etc.
Useful Links
Support this week
- Slack: Post questions to
#help - Office Hours: Book via StudentHub