DS205 2025-2026 Winter Term Icon

πŸ’» Week 01 Lab

Exploring the Open Food Facts API

Author

Dr Jon Cardoso-Silva

Published

17 January 2026

Modified

02 February 2026

πŸ₯… Learning Goals

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

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

Slack 5 Slack conversations

πŸ“‹ Preparation

πŸ›£οΈ Lab Roadmap

How the W01 Lab will be structured
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.ipynb in 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:

  1. Familiarise yourself with the website: Visit the Open Food Facts website and search for a product you recognise. Note what information is displayed.

  2. 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.

  3. 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

  1. Run all code cells in Section 3
  2. Explore the DataFrame using the methods demonstrated
  3. Understand how the nutriments column (nested dictionaries) is expanded into multiple columns
  4. 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

  1. Run the visualisation code in Section 4
  2. Examine the histograms showing nutritional data distributions
  3. Review the NOVA classification donut chart
  4. 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

  1. What’s the relationship between sugar content and energy?
  2. Which product has the highest protein content?
  3. πŸ† 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?