omid5's picture
Update README.md
245392a verified
metadata
license: cc0-1.0
tags:
  - nutrition
  - ingredients
  - food
  - usda
  - tabular
  - cleaned
  - analysis-ready
language:
  - en
pretty_name: Comprehensive & Cleaned USDA Foods Nutrition Dataset
size_categories:
  - 100K<n<1M

Comprehensive & Cleaned USDA Foods Nutrition Dataset

Dataset Summary

This dataset is a cleaned, de-duplicated, and enhanced version of the USDA's FoodData Central (FDC) database, combining Branded Foods, Foundation Foods (generic), and SR Legacy data into a single, analysis-ready file. It is designed to be a robust resource for nutritional analysis, machine learning, and food-related applications.

The raw USDA data is spread across dozens of CSV files, contains numerous duplicates, and has inconsistent data formats. This dataset solves these issues, providing a de-normalized, wide-format Parquet file that is fast and easy to use.

Dataset Statistics

  • Unique Food Products: ~500,000+
  • Data Format: Single Parquet file
  • Release Version: Based on the USDA's April 2024 data dump.

Key Enhancements and Cleaning Process

The value of this dataset comes from the robust processing pipeline applied to the raw source files.

💡 Key Improvements

  1. Comprehensive Scope: Combines three key USDA data types (branded_food, foundation_food, sr_legacy_food) into one unified dataset.
  2. Rigorous De-duplication: The original data contains multiple entries for the same product. This dataset was de-duplicated by creating a canonical name for each product and then selecting only the single most recently published entry, ensuring an authoritative record.
  3. Analysis-Ready "Wide" Format: The nutrient data has been pivoted into a "wide" format. Instead of multiple rows per food (one for each nutrient), there is one row per food with each of the 15 curated nutrients in its own column. This is vastly more convenient for use in pandas, R, and machine learning.
  4. Standardized Serving Size: The raw data often lacks serving size information for branded products. This dataset ensures every food has a defined serving size. If a specific portion (e.g., "1 cup") was available, it was used. Otherwise, a fallback "Standard 100g serving" was applied, which aligns with the "per 100g" nutrient values.

Data Quality & Important Considerations

This dataset is a faithful but cleaned representation of the source data. Users should be aware of the following characteristics:

  • Nutrient Null Values: A NULL (or NaN) value in a nutrient column (e.g., Caffeine) means the value was not reported for that food in the source data. It does not necessarily mean the value is zero.
  • Outliers: The source data contains extreme, likely erroneous values for some nutrients (e.g., Sodium, Na values that are physically impossible). These outliers have been intentionally preserved to maintain the integrity of the source data. Users should consider applying their own filtering, capping, or removal of these outliers before conducting statistical analysis or training models.
  • Ingredients: The ingredients column is NULL for foundation_food and sr_legacy_food types, as these are generic items without a commercial ingredients list.

Nutrient Selection

This dataset includes a curated selection of 15 key nutrients. All values are standardized per 100g, but are also representative of the provided serving_gram_weight.

  • Core Macronutrients: Energy, Protein, Total lipid (fat), Carbohydrate
  • Fat & Fiber Breakdown: Saturated Fat, Trans Fat, Cholesterol, Fiber, Sugars
  • Key Minerals & Vitamins: Sodium, Calcium, Iron, Potassium, Vitamin D
  • Other: Caffeine

How to Use

You can easily load and work with this single-file dataset using pandas.

# First, make sure you have the necessary libraries
!pip install pandas pyarrow

import pandas as pd

# Load the dataset from the local file
# Or directly from Hugging Face after downloading
file_path = "data.parquet" # Assuming you downloaded the file as data.parquet
df = pd.read_parquet(file_path)

# Explore the data
print(f"Dataset loaded with {len(df)} rows.")
print("Sample of the data:")
display(df.head())

Example: Find foods high in protein, filtering out potential outliers

high_protein_foods = df[df['Protein'] > 20].sort_values(by='Protein', ascending=False)
print("\nHigh-protein foods:")
display(high_protein_foods[['food_item', 'Protein', 'serving_description']].head(10))

Schema

The dataset consists of a single table with the following columns:

Column Type Description
fdc_id VARCHAR The original unique ID from the USDA FDC database for traceability.
food_item VARCHAR The cleaned, canonical name of the food product.
data_type VARCHAR The source data type (branded_food, foundation_food, sr_legacy_food).
ingredients VARCHAR The full ingredients list as a single text string (if available).
serving_description VARCHAR The description of the serving size (e.g., "1 cup" or "Standard 100g serving").
serving_amount DOUBLE The quantity of the serving (e.g., 1.0).
serving_unit VARCHAR The unit for the serving amount (e.g., "cup" or "g").
serving_gram_weight DOUBLE The weight of the serving size in grams.
Nutrient Columns DOUBLE Columns for each of the 15 nutrients (e.g., Protein, Sodium, Na, etc.).

Source Data & Citation

This dataset was derived from the public domain FoodData Central database provided by the U.S. Department of Agriculture (USDA).

If you use this cleaned dataset in your work, please credit the original USDA source and consider linking back to this Hugging Face repository.