Skip to content
0

Finding the best chocolate bars

Now let's now move on to the competition and challenge.

๐Ÿ“– Background

You work at a specialty foods import company that wants to expand into gourmet chocolate bars. Your boss needs your team to research this market to inform your initial approach to potential suppliers.

After finding valuable chocolate bar ratings online, you need to explore if the chocolate bars with the highest ratings share any characteristics that could help you narrow your search for suppliers (e.g., cacao percentage, bean country of origin, etc.)

๐Ÿ’พ The data

Your team created a file with the following information (source):
  • "id" - id number of the review
  • "manufacturer" - Name of the bar manufacturer
  • "company_location" - Location of the manufacturer
  • "year_reviewed" - From 2006 to 2021
  • "bean_origin" - Country of origin of the cacao beans
  • "bar_name" - Name of the chocolate bar
  • "cocoa_percent" - Cocoa content of the bar (%)
  • "num_ingredients" - Number of ingredients
  • "ingredients" - B (Beans), S (Sugar), S* (Sweetener other than sugar or beet sugar), C (Cocoa Butter), (V) Vanilla, (L) Lecithin, (Sa) Salt
  • "review" - Summary of most memorable characteristics of the chocolate bar
  • "rating" - 1.0-1.9 Unpleasant, 2.0-2.9 Disappointing, 3.0-3.49 Recommended, 3.5-3.9 Highly Recommended, 4.0-5.0 Oustanding

Acknowledgments: Brady Brelinski, Manhattan Chocolate Society

๐Ÿ’ช Challenge

Create a report to summarize your research. Include:

  1. What is the average rating by country of origin?
  2. How many bars were reviewed for each of those countries?
  3. Create plots to visualize findings for questions 1 and 2.
  4. Is the cacao bean's origin an indicator of quality?
  5. [Optional] How does cocoa content relate to rating? What is the average cocoa content for bars with higher ratings (above 3.5)?
  6. [Optional 2] Your research indicates that some consumers want to avoid bars with lecithin. Compare the average rating of bars with and without lecithin (L in the ingredients).
  7. Summarize your findings.

โœ… Checklist before publishing

  • Rename your workspace to make it descriptive of your work. N.B. you should leave the notebook name as notebook.ipynb.
  • Remove redundant cells like the introduction to data science notebooks, so the workbook is focused on your story.
  • Check that all the cells run without error.

โŒ›๏ธ Time is ticking. Good luck!

# Import necessary libraies
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
plt.style.use('ggplot')
plt.figure(figsize=(20,5))

# Read the CSV files
df = pd.read_csv('data/chocolate_bars.csv')

# Explore head of the datasets

df.head()
df.shape
df.info()
df.duplicated().sum()
df.isna().sum()
df['ingredients'].fillna(method = 'ffill', inplace=True)
df['num_ingredients'] = df['num_ingredients'].fillna(df['num_ingredients'].mean())
df.isna().sum()
df.describe()

DATA ANYALYSIS

# (1). What is the average rating by country of origin?

avg_rating = df.groupby('bean_origin')['rating'].mean().reset_index().sort_values('rating', ascending=False)
avg_rating
# Average rating visualisation
plt.figure(figsize=(20,5))
sns.barplot(data=avg_rating[0:10], x='bean_origin', y='rating')
plt.ylabel('Average rating', size=16, alpha=0.9)
plt.xlabel('Bean_origin', size=16, alpha=0.9)
plt.title('Average bean rating by country of origin (top 10)', fontsize=20, fontweight='bold')
plt.show()
โ€Œ
โ€Œ
โ€Œ