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:
- What is the average rating by country of origin?
- How many bars were reviewed for each of those countries?
- Create plots to visualize findings for questions 1 and 2.
- Is the cacao bean's origin an indicator of quality?
- [Optional] How does cocoa content relate to rating? What is the average cocoa content for bars with higher ratings (above 3.5)?
- [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).
- Summarize your findings.
# Importing the pandas module
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns# Reading in the data
df = pd.read_csv('data/chocolate_bars.csv')
# Take a look at the first datapoints
df.head()# information of the data
df.info()There are total number of 2530 of observation and 11 features
# check for missing values
df.isna().sum()The features num_ingredients and ingredients have 87 missing values respectively
df.nunique()# since the number of ingredient has 6 unique number of ingredients,
# repalce missing values with the most occuring number of ingredients
most_occuring_num_ingredients = df.num_ingredients.value_counts().index[0]
df.num_ingredients.fillna(most_occuring_num_ingredients, inplace=True)# replace the ingredient feature missing values with the most occuring ingredient
most_used_ingredients = df.ingredients.value_counts().index[0]
df.ingredients.fillna(most_used_ingredients, inplace=True)# check for missing values for the second time
df.isna().sum()# check for duplicate in the data
sum(df.duplicated())โ
โ