Python case study · Original work December 2023

Vitamin C and calories.
What the data reveals.

Which fruit has the most vitamin C? I explored 7,793 foods using Python, from nutrient comparisons and data cleaning to water–energy relationships and calorie modeling. The original 2023 study includes a reproducible 2026 review.

An editorial illustration of acerola and guava on a green plate
Acerola and guava · illustrative cover; findings come from the project dataset.
7,793Food records
25Food categories
3OLS specifications
100 gCommon mass basis

Three findings. Then the detail.

1,677.6

Vitamin C in raw acerola

mg per 100 g. Highest recorded value in the fruit category.

−0.895

Water–calorie correlation

Higher water content is associated with lower energy density in this dataset.

13.55

Held-out test RMSE

kcal per 100 g for the extended model, with evaluation limits documented.

Which fruit has the most vitamin C?

Raw acerola: 1,677.6 mg per 100 g. The ranking uses 349 fruit records with reported vitamin C, out of 355 in the Fruits and Fruit Juices category. Six missing values remain unknown. This is a dataset-specific comparison; fresh, juiced and dried forms are distinct.

Explore the fruit ranking and corrected code →

Top five fruit records by vitamin C; raw acerola leads at 1,677.6 mg per 100 g
Top five records in Fruits and Fruit Juices. Raw, juiced and dried forms remain distinct; the jujube label retains the source wording “fresh, dried”.

The analysis began with a DataCamp learning competition: explore nutrient composition, identify vitamin C sources, inspect water and calorie relationships, and fit linear models to food energy. I extended the baseline to include food categories, interactions, alcohol and fiber.

The source contains nine nutrient and energy fields alongside food identifiers, descriptions and categories. Values are reported per 100 g, so comparisons use a consistent mass rather than unequal portions.

Source: DataCamp’s “What Foods Are the Most Nutritious?” dataset, modified from USDA FoodData Central. My publication is dated 11 December 2023. This was an unjudged learning competition; participation does not imply an award.

Preparing the data

I converted strings such as “5.88 g” and “307.0 kcal” into numeric values, explored missingness, summarized food categories and plotted nutrient relationships.

The review retains missing values until an analysis needs them. Alcohol is missing in 2,394 records; replacing those values with zero would make an unsupported assumption.

Observed association: water and calories have Pearson r = −0.895 in this dataset. Foods with greater water content generally have lower energy density per 100 g.

Water and calories for 7,793 food records; Pearson correlation minus 0.895
A descriptive relationship across food items, not a health-outcome analysis.

A transparent starting point

The first specification regressed calories on protein, fat and carbohydrate without an intercept. Recalculation reproduced the saved coefficients: 4.137 for protein, 8.844 for fat and 3.854 for carbohydrate, in kcal per gram.

The original notebook then added category effects and interactions, followed by alcohol and fiber. Its saved residual standard errors were 16.68, 13.89 and 8.14 kcal. These are training-fit statistics; they do not measure prediction performance on unseen foods.

Comparing on held-out rows

The review uses the same 5,334 positive-calorie, complete-model-input rows for all three specifications. A deterministic split within each food category gives 4,278 training rows and 1,056 test rows. Missing cholesterol or vitamin C does not exclude a row because neither is a model input.

Test RMSE: 15.38 for baseline, 15.71 for category interactions and 13.55 for alcohol and fiber
Kcal per 100 g, evaluated on the same held-out rows. Lower values mean smaller prediction errors on this split.
SpecificationTest MAE (kcal)Test RMSE (kcal)Rank / columns
Macronutrients6.8615.383 / 3
Category interactions6.0415.71100 / 100
Alcohol and fiber interactions4.7013.55126 / 150

MAE = mean absolute error; RMSE = root mean squared error. Both use kcal per 100 g. Results are from the 2026 review, not the original submission.

The category-only extension slightly increases RMSE on this split. Adding alcohol and fiber lowers it to 13.55 kcal, but the full interaction matrix is rank deficient (126 of 150 columns). Its individual coefficients require caution.

Download model comparison CSV

Model fit needs context

The held-out comparison is an internal reproducibility check. Related products may appear across train and test sets, and complete-case selection can bias results. The work is an exploratory learning study, not a clinical or production prediction system.