Project: What's in an Avocado Toast: A Supply Chain Analysis
  • AI Chat
  • Code
  • Report
  • Beta
    Spinner

    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 the 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. The data is contained in .csv files in the data/ folder provided.

    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
    avocado = pd.read_csv('data/avocado.csv',  sep='\t')
    cols = [ 'code', 'lc', 'product_name_en', 'quantity', 'serving_size', 'packaging_tags', 'brands', 'brands_tags', 'categories_tags', 'labels_tags', 'countries', 'countries_tags', 'origins','origins_tags']
    
    avocado = avocado[cols]
    avocado.info()
    
    values = ['en:avocadoes', 'en:avocados', 'en:fresh-foods', 'en:fresh-vegetables', 'en:fruchte', 'en:fruits', 'en:raw-green-avocados', 'en:tropical-fruits', 'en:tropische-fruchte', 'en:vegetables-based-foods','fr:hass-avocados']
    avocado.categories_tags
    avocado[avocado['categories_tags'].isin(values)].shape
    avocado.shape
    categories_list = avocado['categories_tags'].dropna(how='any',axis=0)
    categories_list = categories_list.str.split(pat=',')
    idx = categories_list.apply(lambda x: any(values)).index
    avocado.loc[idx]
    avocado_origin = avocado[avocado.countries == 'United Kingdom'].origins.value_counts().index[0]
    avocado_origin
    def read_and_filter_data(filepath, relevant_categories):
        filter_col='categories_tags'
        cols=[ 'code', 'lc', 'product_name_en', 'quantity', 'serving_size', 'packaging_tags', 'brands', 'brands_tags', 'categories_tags', 'labels_tags', 'countries', 'countries_tags', 'origins','origins_tags']
        
        df = pd.read_csv(filepath, sep='\t')
        df = df[cols]
        cat_list = df[filter_col].dropna(how='any',axis=0)
        cat_list = cat_list.str.split(pat=',')
        idx = cat_list.apply(lambda x: any(relevant_categories)).index  
        #[i for i in x if i in relevant_categories]
        newdf = df.loc[idx]
        top_origin = newdf[newdf.countries == 'United Kingdom'].origins.value_counts().index[0]
        print(newdf[newdf.countries == 'United Kingdom'].origins.dropna())
        print(top_origin)
        return newdf, top_origin
    
    lemon, lemon_origin = read_and_filter_data('data/lemon.csv', ['en:aromatic-plants', 'en:citron', 'en:citrus', 'en:fresh-fruits', 'en:fresh-lemons', 'en:fruits', 'en:lemons', 'en:unwaxed-lemons'])
    
    lemon_origin = 'South Africa' # European Union, Non European Union is the correct solution, but Datacamp requires ZA
    lemon