nvim - portfolio/src/blog-posts/halloween-candy-food-allergies.mdx
portfolio > src > blog-posts/halloween-candy-food-allergies.mdx
← Back to blog
Fun-size Halloween candy, allergen warnings and all (photo from Pexels)

Which Popular Halloween Candies Can Kids With Food Allergies Eat?

I combined an online candy vote with real ingredient labels on Databricks to find the most popular candies kids with food allergies can still eat, then checked the answer against this year's labels

Anirudh Konidala

If you went trick-or-treating as a kid, chances are you came home with a lot of Reese’s Peanut Butter Cups. They are pretty much everywhere. An Instacart report on its 2025 orders found that Reese’s was the No. 1 candy sold in 40 of the 50 states, plus Washington, D.C.

That is a problem for kids with a peanut allergy, because the most popular candy in the bowl is the one they cannot eat.

I was curious what the best Halloween bowl looks like when it has to be safe for every kid, and how much popularity a household gives up by skipping certain candies.

So I built candyops, a data pipeline that answers one question: for each common food allergy, which 10 popular candies can you still hand out, and how much less popular is that bowl than one with no allergy restrictions? It also asks what a household can do about it.

Why this matters

Food allergies are common in children. The CDC found that 5.8% of US children had a diagnosed food allergy in 2021, about 1 in 17, according to its National Health Interview Survey data brief. Halloween is the one night of the year when those kids collect food from strangers.

Candy labels do not make this easy. US law requires packaged food to name the major allergens it contains, but many “may contain” warnings are voluntary and vary from one manufacturer to the next, as the National Agricultural Law Center explains. The nonprofit Food Allergy Research & Education (FARE) runs the Teal Pumpkin Project so families can signal that they offer non-food treats instead. That works, but plenty of households would rather hand out candy every kid can eat.

A lot of the candy you eat comes from three big companies.

The Hershey Company makes Hershey’s, Reese’s, Hershey’s Kisses, Jolly Rancher and Kit Kat. Reese’s Peanut Butter Cups, the bestseller from the start of this post, are built around peanut butter.

Mars makes Snickers, M&M’s, Twix, 3 Musketeers, Milky Way, Skittles and Starburst. Its lineup covers both kinds of candy in a Halloween bowl: chocolate bars like Snickers and Twix, made with milk chocolate, and fruit candies like Skittles and Starburst, made without chocolate or nuts. The fruit candies come up again later, because they are what remains once the common allergens are removed.

Ferrero makes Ferrero Rocher, Nutella and Kinder Joy. It also owns Halloween staples like Butterfinger, Baby Ruth, 100 Grand and Nerds, which came with Nestlé’s US candy business when Ferrero bought it in 2018. Butterfinger turned out to be the biggest risk in this project: the data nearly labeled it peanut-free, even though it is made with peanuts.

The data

I combined two public datasets from Kaggle, a website where people share free datasets. They were collected separately and share no common ID. A third, live source keeps the results up to date.

Table 1.1 lists the three sources, what each one holds, and its size.

Source What it holds Size
FiveThirtyEight’s Ultimate Halloween Candy Power Ranking How often each candy won a head-to-head vote 85 entries from about 269,000 matchups
Open Food Facts (world-food-facts) Ingredients, allergens, sugar and serving size of packaged foods 356,001 products x 163 columns, about 1 GB
Open Food Facts daily change feed Every product edited each day 98,694 edits in its first two weeks

Table 1.1: The three data sources candyops combines, what each one holds, and its size.

FiveThirtyEight was a data journalism site. Its writer Walt Hickey built the ranking in 2017 by asking readers to pick between two random candies, again and again. Besides each candy’s win rate, the dataset tags every candy with yes-or-no traits (chocolate, fruity, caramel, peanut or almond, nougat, crisped rice or wafer, hard candy, bar, and many pieces per bag) and ranks how sugary and how expensive it is compared with the others.

Open Food Facts is a nonprofit, crowdsourced database of food labels that anyone can edit. Both Kaggle files are 2017 snapshots, and the pipeline pins their versions, so every run downloads and reads exactly the same data.

This is one real row from Open Food Facts, a US pack of Reese’s Peanut Butter Cups:

code             0768395475482
product_name     Peanut Butter Cups
brands           Reese's
countries_tags   en:united-states
ingredients      Milk chocolate (sugar; cocoa butter; chocolate; nonfat milk; milk fat; lactose;
                 soy lecithin; pgpr, emulsifier); peanuts; sugar; dextrose; salt; tbhq (preservative)
allergens        (empty)
traces           (empty)
serving_size     42 g (1 PACKAGE)
sugars_100g      50

The allergen field is empty, even though the ingredients list milk, soy and peanuts. Only 37,177 of the 356,001 products fill it in. Most of the allergen information is only in the ingredient text, so the pipeline has to read each ingredient list to find allergens.

The raw files are messier than they look. The candy ranking stores apostrophes as HersheyÕs and includes two coins (a dime and a quarter) as joke entries. The Open Food Facts file has 26 rows with a stray carriage return inside a field; pandas and most CSV readers treat it as a line break and report 356,027 rows instead of 356,001. A test pins the correct count, so a reader that splits on the wrong character fails with an error instead of producing extra rows.

How the pipeline works

Kaggle2 pinned datasets Unity Catalog volumeraw files + feed archive Open Food Factsdaily change feed bronzeraw strings silvercleaned products,candy matches, allergen flags goldcandy profiles, bowls,warning cost, safe swaps,2017 vs now street bowl optimizerPython, logged to MLflow dashboard

The pipeline runs on Databricks, a cloud platform for processing large datasets with Spark and SQL. Raw files land in a Unity Catalog volume, which is Databricks’ managed storage for files, so the downloads are kept between runs. I set up a Databricks job that runs every day and stores the data in a medallion architecture, which organizes it into three layers: bronze pulls in the raw data from the sources unchanged, silver cleans it and reads the allergens from each ingredient list, and gold turns it into the results this post reports, such as each candy’s allergen status and the allergy-safe bowls.

The job starts by downloading the Kaggle datasets into two bronze tables, with every value kept as text: bronze_candy_ranking, with one row for each of the 85 candies in the vote, and bronze_off_products, with all 356,001 Open Food Facts products and their 163 columns.

A second notebook then archives each new change-feed file and loads it with Auto Loader, which remembers which files it has already read, so each day’s edits are loaded exactly once. Open Food Facts keeps only about two weeks of those files, so the archive is the only copy once they expire.

From there, dbt (data build tool) builds everything in SQL: each table is a SQL file called a model, and dbt runs the models in the right order and checks each one with tests. The silver models clean data types and whitespace, parse serving sizes like 1.55 oz into grams, match products to candies, and turn ingredient text into allergen flags for peanut, tree nut, milk, gluten, soy and egg. The parser splits “may contain” warnings away from real ingredients and ignores lookalikes such as “cocoa butter” (not dairy) and “peanut-free”. The gold models give each candy a status per allergen (contains, varies, may_contain, not_listed or unknown) and pick the bowls. dbt runs 51 tests on every build, including one that fails if any candy in a peanut-free bowl is not peanut-free.

The last step turns the gold tables into decisions. Two more dbt models rebuild every bowl with and without accepting “may contain” warnings, and find the most similar safe candy for each favorite. A Python step then runs a small optimization that picks the one bowl that gives the most trick-or-treaters a favorite they can eat, and logs each run’s inputs and results to MLflow, a tool for recording experiments, so runs can be compared over time.

The results

How to read the results

Every allergy-safe bowl is compared with the same baseline, the unrestricted bowl: the 10 most popular candies overall, which is the bowl a household would put out without thinking about allergies. It starts with Reese’s Peanut Butter Cups, Reese’s Miniatures and Twix, so it is the opposite of allergen-free: almost every candy in it contains peanuts, milk or both.

Table 1.2 defines the four measures the results use, each with a worked example from the data.

Measure Definition Example
Win rate The percentage of a candy’s head-to-head matchups in which voters picked it. In each matchup, FiveThirtyEight showed a voter two randomly chosen candies and asked which one they would rather receive. The value comes from the dataset’s winpercent column, based on about 269,000 matchups in total. Reese’s Peanut Butter Cups won 84.2% of their matchups, the highest of the 83 candies.
Candies allowed The number of the 83 ranked candies that pass a restriction. A candy passes when every restricted allergen has the status not_listed, based on at least two matched products with an ingredient list. Peanut-free and nut-free restrictions also exclude any candy FiveThirtyEight tags as containing peanuts or almonds. 42 candies pass the peanut-free restriction.
Bowl The 10 candies with the highest win rate among the candies allowed. The unrestricted bowl applies no restriction, so it is simply the 10 candies with the highest win rate overall; its average win rate is 76.3%. The peanut-free bowl starts with Starburst, Rolo, and Skittles.
Popularity kept (popularity score) A restricted bowl’s average win rate divided by the unrestricted bowl’s average win rate. Peanut-free: 59.5% ÷ 76.3% = 78.0%.

Table 1.2: Definitions of the four measures used in the results, each with a worked example from the data.

A popularity score of 78% means the candies in the peanut-free bowl win their matchups, on average, about 22% less often than the candies in the unrestricted bowl. A score of 100% would mean a restriction costs no popularity at all.

Table 1.3 sums up the main results, and the sections below explain each one.

Question Result
How much popularity does a peanut-free bowl keep? A 78.0% popularity score
How much does a bowl free of all six allergens keep? A 68.7% popularity score
How much do “may contain” warnings cost the peanut-free bowl? 7.9 points of popularity score
What is the closest peanut-free swap for Twix? Hershey’s Special Dark, with a 59.2% win rate versus Twix’s 81.6%
What single change covers every kid with a peanut, milk or tree-nut allergy? Swapping Butterfinger for Starburst, which keeps a 99.5% popularity score
How many candies changed allergen status since 2017? 12 of the 19 candies with enough current data

Table 1.3: The main results of the analysis, each explained in the sections below.

The Reese’s problem from the start of this post is not a one-off. Figure 1.1 plots each of the 58 candies with at least two matched products that have an ingredient list (the other 25 candies lack enough label data to judge) by how many of the six allergens its label lists and how often it won its matchups.

The most popular candies list the most allergens
Each dot is one of 58 candies with at least two labeled products. Lines show the average win rate. Hover a dot for details, or click the legend to show or hide a group.

Figure 1.1: Win rate against the number of major allergens each candy’s label lists, including may-contain warnings. Chocolate candies are orange and other candies are blue; lines show the average win rate for each count.

Candies with none of the six allergens average a 45% win rate, while candies with five or more average 66%. Most of that gap comes from chocolate, which almost always contains milk and soy, so the candies voters like best are also the hardest for allergic kids to eat.

Chocolate is not the whole story, though. Among the 22 chocolate candies alone, those listing four or more allergens average a 66.9% win rate, compared with 57.1% for those listing three or fewer. Among the 36 non-chocolate candies, the number of allergens makes almost no difference (a 41.2% win rate with four or more, 43.7% with three or fewer). The best-loved chocolate bars are the ones whose fillings, such as peanuts, nougat or a wafer, put more allergens on the label.

Table 1.4 shows five of the most popular candies and their status for each allergen.

Candy Win rate Peanut Tree nut Milk Gluten Soy Egg
Reese’s Peanut Butter Cup 84.2% contains not listed contains not listed contains not listed
Twix 81.6% varies varies contains contains contains not listed
Kit Kat 76.8% may contain varies contains contains varies not listed
Snickers 76.7% contains varies contains varies contains varies
Milky Way 73.1% may contain may contain contains contains contains varies

Table 1.4: Allergen status of five of the most popular candies, based on their matched Open Food Facts labels.

varies means some matched products list the allergen and others do not, usually because the same bar is made with different recipes in different countries.

What each allergy costs a bowl

Table 1.5 lists the number of candies each allergy restriction allows, the popularity it keeps, and the resulting bowl.

Restriction Candies allowed Popularity kept The bowl, most popular first
None 83 100.0% Reese’s Peanut Butter Cup, Reese’s Miniatures, Twix, Kit Kat, Snickers, Reese’s Pieces, Milky Way, Reese’s Stuffed with Pieces, Peanut Butter M&M’s, Butterfinger
Gluten-free 36 88.2% Reese’s Peanut Butter Cup, Reese’s Miniatures, Reese’s Pieces, Peanut Butter M&M’s, Peanut M&M’s, Skittles, Sour Patch Kids, Junior Mints, Haribo Gold-Bears, Nerds
Peanut-free 42 78.0% Starburst, Rolo, Skittles, Sour Patch Kids, Hershey’s Special Dark, Junior Mints, Haribo Gold-Bears, Nerds, Skittles Wild Berry, Swedish Fish
Nut-free 40 77.1% Starburst, Rolo, Skittles, Sour Patch Kids, Junior Mints, Haribo Gold-Bears, Nerds, Skittles Wild Berry, Swedish Fish, Lifesavers Big Ring Gummies
Milk-free 29 74.6% Starburst, Skittles, Sour Patch Kids, Haribo Gold-Bears, Nerds, Skittles Wild Berry, Swedish Fish, Lifesavers Big Ring Gummies, Airheads, Haribo Sour Bears
Free of all six 18 68.7% Skittles, Sour Patch Kids, Haribo Gold-Bears, Skittles Wild Berry, Swedish Fish, Lifesavers Big Ring Gummies, Haribo Sour Bears, Welch’s Fruit Snacks, Runts, Dots

Table 1.5: The 10-candy bowl for each allergy restriction, with the number of candies allowed and the share of the unrestricted bowl’s popularity it keeps.

Figure 1.2 puts the popularity each bowl keeps side by side, from the unrestricted bowl down to a bowl free of all six allergens.

Every restriction costs popularity
Average win rate of each 10-candy bowl, as a share of the unrestricted bowl. Hover a bar to see the bowl.

Figure 1.2: The share of the unrestricted bowl’s popularity that each allergy-safe bowl keeps, with the number of candies each restriction allows.

Every candy in the unrestricted top 10 is chocolate, and at least five of them are made with peanuts: four Reese’s products and Peanut Butter M&M’s. That is why the peanut-free bowl loses so much. It keeps a 78% popularity score, and none of the 10 candies in the unrestricted bowl make it in.

A gluten-free bowl loses the least popularity. It keeps an 88.2% popularity score and still leads with Reese’s, because Reese’s Peanut Butter Cups list no wheat. A milk-free bowl drops to a 74.6% popularity score, because it excludes every candy made with milk chocolate. Figure 1.3 splits each bowl into chocolate and non-chocolate candies.

Chocolate disappears as restrictions are added
Chocolate and non-chocolate candies in each 10-candy bowl. Hover a segment to see the candies.

Figure 1.3: Chocolate and non-chocolate candies in each 10-candy bowl. The milk-free bowl and the bowl free of all six allergens contain no chocolate at all.

The safest bowl is a bowl of gummies and fruit candy, and it still keeps about two-thirds of the popularity.

Avoiding all six allergens leaves 18 candies and a 68.7% popularity score: Skittles, Sour Patch Kids, Swedish Fish, Haribo Gold-Bears and others. Skittles and Sour Patch Kids still rank in the top third of the vote.

Swapping chocolate for fruit candy also adds sugar. The unrestricted bowl has a median of 51.7 g of sugar per 100 g, while the peanut-free and nut-free bowls reach about 69 g, as shown in Figure 1.4.

Allergy-safe bowls contain more sugar
Median sugar per 100 g in each bowl. Safe bowls rely on fruit candy instead of chocolate.

Figure 1.4: Median sugar per 100 g in each bowl. Allergy-safe bowls rely on fruit candy, which contains more sugar per gram than chocolate.

Part of that cost is a labeling choice

Some candies are excluded only for what they might contain. No US law requires “may contain” warnings or sets rules for when to use them: each candy maker decides on its own whether to print one, so two candies made on similar production lines can carry different warnings. So I rebuilt every bowl a second time, accepting candies whose only problem is a precautionary warning, to see how much of each cost those warnings cause.

"May contain" warnings cost the peanut-free bowl 7.9 points
Popularity kept by each bowl when may-contain warnings exclude a candy, and when they are accepted. Hover a dot to see which candies come back.

Figure 1.5: Popularity kept by each bowl when may-contain warnings exclude a candy, and when they are accepted.

“May contain” warnings cost the peanut-free bowl 7.9 points of popularity score, as shown in Figure 1.5. Kit Kat, Milky Way, M&M’s and Nestle Crunch list no peanuts, yet each carries a peanut warning on at least one label, which keeps all four out. Accepting the warnings would lift the peanut-free bowl’s popularity score from 78.0% to 85.9%. The nut-free bowl loses 4.2 points of popularity score the same way, and the gluten-free bowl loses 1.4 points to a single warning on Rolo.

Families should still take the warnings seriously: for a kid with a severe allergy, a shared production line is a real risk. But a meaningful share of what allergic kids give up comes from how candy makers label, rather than from what is in the candy.

The closest safe swap for each favorite

A household that wants a peanut-free bowl still needs to know what to buy instead. For each candy in the unrestricted top 10, the pipeline finds the most similar peanut-free candy using FiveThirtyEight’s candy traits (chocolate, caramel, nougat, crisped rice, bar and others), plus how sugary and how expensive each candy is.

The closest safe swap for each favorite
Most similar safe candy by FiveThirtyEight's traits, sugar and price. Pick an allergy to switch the swaps.

Figure 1.6: The most similar safe candy for each favorite in the unrestricted bowl, with the win rate of each. Peanut-free is shown first; the buttons switch to the other allergies.

The closest swaps are familiar candies. Twix, Butterfinger and Reese’s Peanut Butter Cups point to Hershey’s Special Dark, Kit Kat to Mounds, Snickers and Milky Way to Charleston Chew, and Reese’s Pieces to Junior Mints, as shown in Figure 1.6. The catch is popularity. The best swap, Hershey’s Special Dark, has a 59.2% win rate, more than 20 points below Twix’s 81.6% and 25 points below Reese’s Peanut Butter Cups’ 84.2%.

For a bowl free of all six allergens, the same search finds nothing similar. Every favorite maps to an unrelated gummy, because no chocolate candy passes all six restrictions.

One bowl for the whole street

Households handing out candy don’t know which trick-or-treaters at their door have which allergies. So the last question is: which single bowl gives the most trick-or-treaters a favorite they can eat?

The pipeline answers it with a small optimization. About 2.2% of US children are allergic to peanuts, 1.9% to milk and 1.2% to tree nuts, according to a national survey of 38,408 children published in Pediatrics. The pipeline weights each group of kids by those rates and picks, one candy at a time, the 10 candies that maximize the average win rate of the best candy each kid can eat, counting zero for a kid with nothing safe in the bowl.

One swap gives every allergic kid something to eat
The regular top 10 with its least popular candies swapped for the most popular candies safe for peanut, milk and tree-nut allergies. Slide to add more safe candies and watch the popularity score.

Figure 1.7: The bowl with a chosen number of candies that are safe for peanut, milk and tree-nut allergies. The optimization picks one, Starburst; the slider shows what each extra safe candy costs.

One swap is enough. The best bowl for a whole street is the regular top 10 with Butterfinger replaced by Starburst, as shown in Figure 1.7. Starburst is the most popular candy that is safe for all three allergies, so that single change gives every kid with a peanut, milk or tree-nut allergy something to eat, no matter how common each allergy is. The bowl’s average win rate drops only from 76.3% to 75.9%, a 99.5% popularity score.

Each safe candy after the first costs more than the one before it: two safe candies keep a 98.4% popularity score, three keep 96.7%, five keep 92.2%, and a bowl of ten keeps 74.6%. The optimization stops at one safe candy because allergic kids are a small share of the street, so each extra safe candy adds less than the chocolate it replaces. It also treats each allergy separately, and I could not confirm the survey rates for egg, wheat and soy, so those allergies are left out.

Matching candy names to products

Every result above depends on linking each candy in the vote to the right products in Open Food Facts, so this is where most of the work went.

The ranking says “Snickers”. Open Food Facts has hundreds of products with “Snickers” in the name, including ice cream bars, protein bars and almond variants. Joining the two datasets is the riskiest step in the whole pipeline, because a wrong match can change a candy’s allergy status without causing any error.

I compared two approaches: matching on the candy’s name alone, and hand-written matching rules stored as a dbt seed, a small CSV file that lives in the repository, so the rules are reviewed like code. Name matching found 53 of the 83 candies and pulled in 80 products that are not candy at all, such as an Almond Joy coffee creamer and a Hershey’s ice cream bar. The hand-written rules found 67 candies with no non-candy matches, because they handle spellings like “KitKat” and “Mike and Ike” and exclude variants like Snickers Almond.

Figure 1.8 compares how many candies each approach matches and how many non-candy products it pulls in.

Curated matching rules remove every false match
Matching on the name alone pulls in coffee creamer, ice cream and cereal

Figure 1.8: Name-only matching compared with the curated matching rules, by candies matched and non-candy products matched.

How a matching bug put Butterfinger in the peanut-free bowl

Butterfinger is made with peanuts, yet the first version of the peanut-free bowl included it. The 2017 data had only three Butterfinger products. One was the bar itself, with no ingredient list. The other two were a caramel apple and a box of marshmallow squares “made with” Butterfinger, and their ingredient lists never mention peanuts.

The fix has two parts. Products “made with” a candy no longer count as evidence for that candy, and neither do caramel apples or other derived treats. And the ranking itself flags candies made with peanuts or almonds, so the pipeline now keeps every flagged candy out of peanut-free and nut-free bowls, no matter what the labels say. A dbt test enforces it on every run.

The change feed later confirmed that this rule was correct: the current Butterfinger labels list peanuts, milk and soy.

Three more matching bugs

Mixed packs made one candy look like it contained another candy’s allergens. A “Reese’s & Kit Kat Halloween Candy Assortment” made Kit Kat look like it contains peanuts, so the pipeline now excludes assortments and variety packs.

A couple of bad records could override dozens of good ones. The pipeline prefers US labels because US and European recipes differ. With the threshold at two products, Snickers’ only two current US records (a popcorn listing named “Snickers” and a wrapper scan of customer-service text) decided the result over 25 complete labels from other countries and made Snickers look peanut-free. US labels now decide only when there are at least three.

A company name matched the wrong candy. The rule for Tootsie Roll Juniors looked for “Tootsie Roll” and “Junior” anywhere in a product’s name or brand. Junior Mints are made by Tootsie Roll Industries, so all five Junior Mints products counted as Tootsie Roll Juniors, and since Junior Mints list no milk, Tootsie Roll Juniors looked milk-free even though they are made with condensed milk. The rule now excludes Junior Mints, and a test pins it.

Every one of these bugs made a candy look safer than it is, which is the dangerous direction for allergy data.

Is the 2017 answer still true?

Both Kaggle files are from 2017, so the obvious question is whether the labels on shelves today still agree. The daily change feed answers it. Its first two weeks held 98,694 product edits, 348 of them for ranked candies, and 21 candies had at least two current products with ingredient lists.

Figure 1.9 groups the 83 candies by how their allergen status in the 2017 data compares with their current labels.

12 of 19 candies with current data changed allergen status
Each candy's 2017 status compared with products edited since the daily change feed started. Hover a bar to see the candies.

Figure 1.9: How each candy’s allergen status in the 2017 data compares with its current labels from the daily change feed.

Most changes add allergen warnings. Snickers and Milky Way moved from varies to contains for egg, which matches their egg-white nougat. Hershey’s milk chocolate now carries a tree-nut “may contain” warning that the 2017 records did not show. Butterfinger, unknown in 2017, now has labels that list peanuts, milk and soy.

The bowls stay on the pinned 2017 data, so the results above are reproducible. The comparison grows every morning as the job archives another day of the feed, and a dbt test warns if a day is ever missed.

What this means for anyone handing out candy

  • Keep the bowl you were going to buy and swap one candy for Starburst. Every kid with a peanut, milk or tree-nut allergy then has something to eat, and the bowl barely loses any popularity.
  • If you know a peanut-allergic kid is coming, build the bowl around Starburst, Rolo, Skittles and Sour Patch Kids. That bowl keeps a 78% popularity score, so you give up only about a fifth of the popularity.
  • Swap favorites one for one: Hershey’s Special Dark for Twix, Mounds for Kit Kat, Charleston Chew for Snickers, and Junior Mints for Reese’s Pieces.
  • Check the “may contain” line as well as the ingredients. These warnings vary from one candy maker to the next, and they are why Kit Kat and M&M’s drop out of a peanut-free bowl even though neither lists peanuts.

References

NORMAL
master
halloween-candy-food-allergies.mdx
utf-8
mdx
Top
1:1