alyssaq / usda-sqlite

USDA food files SR28 to SQLite
119 stars 27 forks source link

How does one extract data so it emulates a typical Nutrition Label? #6

Open yosun opened 6 years ago

yosun commented 6 years ago

Playing around with some queries, but not versed enough in Nutrition to figure out how to structure it so it looks like a typical nutrition table (seems that ignoring certain nutrients in the listing is a step - lots of things labeled as 4:0). Maybe you can help?

SELECT nutrient.name, nutrition.amount FROM nutrition INNER JOIN food ON nutrition.food_id=food.id INNER JOIN nutrient ON nutrition.nutrient_id=nutrient.id WHERE food.id = ( SELECT food.id FROM food WHERE food.short_desc LIKE '%banana%' LIMIT 1 ) AND nutrition.amount>0 AND nutrient.id<607

https://www.fda.gov/food/guidanceregulation/guidancedocumentsregulatoryinformation/labelingnutrition/ucm063113.htm

pierobot commented 6 years ago

You don't have to worry about the nutrients that show as 4:0 and such.

The link you provided shows you what nutrients you need. Just find the nutrient ID for those and add them to your query.

For example, to construct the Fat section of a label

You also want to add the nutrient units to your query.

You will want to read SR 28 if you have not already. https://github.com/alyssaq/usda-sqlite/blob/master/data/sr28_doc.pdf

BradKML commented 3 years ago

I had similar ideas with https://github.com/schirinos/nutrient-db/issues/13 but they used a JSON generator that does not work on Python 3 currently

Since currently I would need a CSV-like data table for certain Data competitions.

And the other table that can be found is one with a naming scheme that is not in long form with https://github.com/buswedg/dataquest/blob/master/Data%20Analysis%20with%20Pandas/Dataframe%20Basics/data/food_info.csv Without using https://raw.githubusercontent.com/spbriggs/USDA-SR26/master/sr26/FOOD_DES.csv