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 wherecategories_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 calledorigins_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.
import pandas as pd
avocado = pd.read_csv('data/avocado.csv', sep='\t')
relevant_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[relevant_cols]
avocado['categories_tags'] = avocado['categories_tags'].str.split(',')
avocado = avocado.dropna(subset=['categories_tags'])
categories_list = []
with open('data/relevant_avocado_categories.txt', 'r') as file:
for category in file:
categories_list.append(category.strip('\n'))
categories_list
avocado = avocado[avocado['categories_tags'].apply(lambda x: any([i for i in x if i in categories_list]))]
uk_df = avocado[(avocado['countries'] == 'United Kingdom')]
origins_tags = uk_df['origins_tags'].value_counts()
top_avocado_origin = origins_tags.index[0].lstrip('en:')
def load_csv(path, cols):
"""Load and subset dataframe."""
df = pd.read_csv(path, sep='\t')
df = df[cols]
df = clean_df(df)
return df
def clean_df(df):
"""Split categories_tags column and drop null values"""
df['categories_tags'] = df['categories_tags'].str.split(',')
df = df.dropna(subset='categories_tags')
return df
import re
def filter_categories(df, categories_list):
df = df[df['categories_tags'].apply(lambda x: any([i for i in x if i in categories_list]))]
return df
def create_category_list(filepath):
categories_list = []
with open(filepath, 'r') as f:
for category in f:
categories_list.append(category.strip('\n'))
return categories_list
def origin_country(df, country):
df = df[(df['countries'] == country)]
ingredient_origin = re.sub('^.{2}:', '', df['origins_tags'].value_counts().index[0]).replace('-', ' ')
return ingredient_origin
olive_oil = load_csv('data/olive_oil.csv', relevant_cols)
olive_categories = create_category_list('data/relevant_olive_oil_categories.txt')
olive_categories
olive_oil = filter_categories(olive_oil, olive_categories)
olive_oil
top_olive_oil_origin = origin_country(olive_oil, 'United Kingdom')
top_olive_oil_origin
sourdough = load_csv('data/sourdough.csv', relevant_cols)
sourdough_categories = create_category_list('data/relevant_sourdough_categories.txt')
sourdough = filter_categories(sourdough, sourdough_categories)
top_sourdough_origin = origin_country(sourdough, 'United Kingdom')
top_sourdough_origin