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're in London, making an avocado toast, a quick-to-make dish that has soared in popularity on breakfast menus since the 2010s. A simple smashed avocado toast can be made with five ingredients: one ripe avocado, half a lemon, a big pinch of salt flakes, two slices of sourdough bread and a good drizzle of extra virgin olive oil. It's no small feat that most of these ingredients are readily available in grocery stores.

    In this project, you'll conduct a supply chain analysis of three of these ingredients used in an avocado toast, utilizing 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 categories tags in the categories_tags column.
    • There is a column in each CSV file called origins_tags with strings for country of origin of that 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.

    import pandas as pd
    
    avogado_fich = pd.read_csv("data/avocado.csv", sep='\t')
    list_col = ['code', 'lc', 'product_name_en', 'quantity', 'serving_size', 'packaging_tags', 'brands', 'brands_tags', 'categories_tags', 'labels_tags', 'countries', 'countries_tags', 'origins','origins_tags']
    avogado_fich = avogado_fich[list_col]
    avogado_fich.head()
    with open("data/relevant_avocado_categories.txt") as f:
        relevant_avocado_categories = []
        for l in f:
            relevant_avocado_categories.append(l.strip())
    
    relevant_avocado_categories = pd.DataFrame(relevant_avocado_categories, columns=['category'])
    avogado_fich_UK = avogado_fich[avogado_fich['countries'] == 'United Kingdom']
    avogado_fich_UK
    avogado_fich_UK = avogado_fich_UK[avogado_fich_UK['categories_tags'].notna()]
    avogado_fich_UK['categories_tags']=avogado_fich_UK['categories_tags'].str.split(',')
    avogado_fich_UK['categories_tags']
    avogado_fich_UK = avogado_fich_UK[avogado_fich_UK['categories_tags']
                                      .apply(lambda x: any(i in x for i in relevant_avocado_categories['category']))]
    top_avocado_origin = avogado_fich_UK['origins'].value_counts().index[0]
    top_avocado_origin

    Function to return output

    import os
    
    def most_common(df , relevant_df):
        
        df_UK = df[df['countries'] == 'United Kingdom']
        
        df_UK = df_UK[df_UK['categories_tags'].notna()]
        
        df_UK['categories_tags']=df_UK['categories_tags'].str.split(',')
        
        
        df_UK = df_UK[df_UK['categories_tags'].apply(lambda x: any(i in x for i in relevant_df['category']))]
        
        origin = df_UK['origins'].value_counts().index[0]
        return origin

    Import data/olive_oil.csv

    import pandas as pd
    
    avogado_fich = pd.read_csv("data/olive_oil.csv", sep='\t')
    list_col = ['code', 'lc', 'product_name_en', 'quantity', 'serving_size', 'packaging_tags', 'brands', 'brands_tags', 'categories_tags', 'labels_tags', 'countries', 'countries_tags', 'origins','origins_tags']
    olive_oil_fich = avogado_fich[list_col]
    with open("data/relevant_olive_oil_categories.txt") as f:
        relevant_olive_oil_categories = []
        for l in f:
            relevant_olive_oil_categories.append(l.strip())
    
    relevant_olive_oil_categories = pd.DataFrame(relevant_olive_oil_categories, columns=['category'])