Skip to content
Project: What's in an Avocado Toast: A Supply Chain Analysis
  • AI Chat
  • Code
  • Report
  • What's in an Avocado Toast: A Supply Chain Analysis

    You find yourself in London, crafting a delectable avocado toast, a dish that has risen dramatically in popularity on breakfast menus since the 2010s. This straightforward recipe requires just five ingredients: a ripe avocado, half a lemon, a generous pinch of salt flakes, two slices of sourdough bread, and a good drizzle of extra virgin olive oil. Most of these ingredients are now staples in grocery stores, and as you will find with this project, that is no small feat!

    In this project, you'll conduct a supply chain analysis of three ingredients used in avocado toast using the Open Food Facts database. This database contains extensive, openly-sourced information on various foods, including their origins. Through this analysis, you will gain an in-depth understanding of the complex supply chain involved in producing a single dish.

    Three pairs of files are provided in the data folder:

    • A CSV file for each ingredient, such as avocado.csv, with data about each food item and countries of origin.
    • A TXT file for each ingredient, such as relevant_avocado_categories, containing only the category tags of interest for that food.

    Here are some other key points about these files:

    • Some of the rows of data in each of the three CSV files do not contain relevant data for your investigation. In each dataset, you will need to filter out rows with irrelevant data, based on values in the categories_tags column. Examples of categories are fruits, vegetables, and fruit-based oils. Filter the DataFrame to include only rows where categories_tags contains one of the tags in the relevant categories for that ingredient.
    • Each row of data usually has multiple category tags in the categories_tags column. There is a column in each CSV file called origins_tags, which contains strings for the country of origin of each item.

    After completing this project, you'll be armed with a list of ingredients and their countries of origin and be well-positioned to launch into other analyses that explore how long, on average, these ingredients spend at sea.

    Open Food Facts database

    import pandas as pd
    
    avocado_df = pd.read_csv("./data/avocado.csv", sep="\t")
    
    relevant_columns = ['code', 'lc', 'product_name_en', 'quantity', 'serving_size', 'packaging_tags', 'brands', 'brands_tags', 'categories_tags', 'labels_tags', 'countries', 'countries_tags', 'origins','origins_tags']
    
    avocado_df_filtered = avocado_df[relevant_columns]
    with open("data/relevant_avocado_categories.txt", "r") as file:
        relevant_categories_avocado = file.read().splitlines()
        file.close()
        
    avocado_df_filtered["categories_tags"] = avocado_df_filtered["categories_tags"].str.split(',')
    
    avocado_df_filtered = avocado_df_filtered.dropna(subset = 'categories_tags')
    
    avocado_df_filtered = avocado_df_filtered[avocado_df_filtered['categories_tags'].apply(lambda x: any([i for i in x if i in relevant_categories_avocado]))]
    # Filter DataFrame for UK data
    avocados_uk = avocado_df_filtered[(avocado_df_filtered['countries']=='United Kingdom')]
    
    # Find most common country for avocado origin
    top_avocado_origin = (avocados_uk['origins_tags'].value_counts().index[0])
    top_avocado_origin = avocado_origin.lstrip("en:")
    # Define a function ro repeat the data filtering process
    def read_filter_data(filepath, relevant_categories):
        avocado_df = pd.read_csv(filepath, sep="\t")
    
        relevant_columns = ['code', 'lc', 'product_name_en', 'quantity', 'serving_size', 'packaging_tags', 'brands', 'brands_tags', 'categories_tags', 'labels_tags', 'countries', 'countries_tags', 'origins','origins_tags']
    
        avocado_df_filtered = avocado_df[relevant_columns]
        
        avocado_df_filtered["categories_tags"] = avocado_df_filtered["categories_tags"].str.split(',')
    
        avocado_df_filtered = avocado_df_filtered.dropna(subset = 'categories_tags')
    
        df_filtered = avocado_df_filtered[avocado_df_filtered['categories_tags'].apply(lambda x: any([i for i in x if i in relevant_categories]))]
        
        return df_filtered
    # Retrieve relevant categories for olive oil and sourdough
    
    with open("data/relevant_olive_oil_categories.txt", "r") as file:
        relevant_categories_olive_oil = file.read().splitlines()
        file.close()
        
    with open("data/relevant_sourdough_categories.txt", "r") as file:
        relevant_categories_sourdough = file.read().splitlines()
        file.close()
    # Filter data for each dataset
    
    olive_oil_df_filtered = read_filter_data("data/olive_oil.csv", relevant_categories_olive_oil)
    sourdough_df_filtered = read_filter_data("data/sourdough.csv", relevant_categories_sourdough)
    # Filter DataFrame for UK data about olive oil
    olive_oil_uk = olive_oil_df_filtered[(olive_oil_df_filtered['countries']=='United Kingdom')]
    
    # Find most common country for avocado origin
    top_olive_oil_origin = (olive_oil_uk['origins_tags'].value_counts().index[0])
    top_olive_oil_origin = top_olive_oil_origin.lstrip("en:")
    
    # Filter DataFrame for UK data about sourdough
    sourdough_uk = sourdough_df_filtered[(sourdough_df_filtered['countries']=='United Kingdom')]
    
    # Find most common country for avocado origin
    top_sourdough_origin = (sourdough_uk['origins_tags'].value_counts().index[0])
    top_sourdough_origin = top_sourdough_origin.lstrip("en:").replace('-', ' ')