Assignment 4

In this assignment, you'll combine the assignment 3 data set with nutrition data from the USDA Food Composition Databases. The CSV file fresh.csv contains the fresh fruits and vegetables data you extracted in assignment 3.

The USDA Food Composition Databases have a documented web API that returns data in JSON format . You need a key in order to use the API. Only 1000 requests are allowed per hour, so it would be a good idea to use caching.

Sign up for an API key here. The key will work with any Data.gov API. You may need the key again later in the quarter, so make sure you save it.

These modules may be useful:

In [1]:
import pandas as pd
fresh = pd.read_csv("fresh.csv")
fresh
Out[1]:
form price_per_lb yield lb_per_cup price_per_cup food type
0 Fresh1 0.333412 0.520000 0.330693 0.212033 watermelon fruit
1 Fresh1 0.535874 0.510000 0.374786 0.393800 cantaloupe fruit
2 Fresh1 1.377962 0.740000 0.407855 0.759471 tangerines fruit
3 Fresh1 2.358808 0.940000 0.319670 0.802171 strawberries fruit
4 Fresh1 1.827416 0.940000 0.363763 0.707176 plums fruit
5 Fresh1 1.035173 0.730000 0.407855 0.578357 oranges fruit
6 Fresh1 6.975811 0.960000 0.319670 2.322874 raspberries fruit
7 Fresh1 2.173590 0.560000 0.341717 1.326342 pomegranate fruit
8 Fresh1 0.627662 0.510000 0.363763 0.447686 pineapple fruit
9 Fresh1 3.040072 0.930000 0.363763 1.189102 apricots fruit
10 Fresh1 0.796656 0.460000 0.374786 0.649077 honeydew fruit
11 Fresh1 1.298012 0.620000 0.308647 0.646174 papaya fruit
12 Fresh1 2.044683 0.760000 0.385809 1.037970 kiwi fruit
13 Fresh1 3.592990 0.920000 0.341717 1.334548 cherries fruit
14 Fresh1 0.566983 0.640000 0.330693 0.292965 bananas fruit
15 Fresh1 1.567515 0.900000 0.242508 0.422373 apples fruit
16 Fresh1 1.591187 0.960000 0.341717 0.566390 peaches fruit
17 Fresh1 1.761148 0.910000 0.319670 0.618667 nectarines fruit
18 Fresh1 1.461575 0.900000 0.363763 0.590740 pears fruit
19 Fresh1 0.897802 0.490000 0.462971 0.848278 grapefruit fruit
20 Fresh1 5.774708 0.960000 0.319670 1.922919 blackberries fruit
21 Fresh1 2.093827 0.960000 0.330693 0.721266 grapes fruit
22 Fresh1 4.734622 0.950000 0.319670 1.593177 blueberries fruit
23 Fresh1 1.377563 0.710000 0.363763 0.705783 mangoes fruit
24 Fresh1 3.213494 0.493835 0.396832 2.582272 asparagus vegetables
25 Fresh, consumed with peel1 1.295931 0.970000 0.264555 0.353448 cucumbers vegetables
26 Fresh, peeled1 1.295931 0.730000 0.264555 0.469650 cucumbers vegetables
27 Fresh1 1.213039 0.950000 0.242508 0.309655 lettuce_iceberg vegetables
28 Fresh1 1.038107 0.900000 0.352740 0.406868 onions vegetables
29 Fresh1 2.471749 0.750000 0.319670 1.053526 turnip_greens vegetables
30 Fresh1 2.569235 0.840000 0.308647 0.944032 mustard_greens vegetables
31 Fresh1 0.564320 0.811301 0.264555 0.184017 potatoes vegetables
32 Fresh1 2.630838 1.160000 0.286601 0.650001 collard_greens vegetables
33 Fresh1 2.139972 0.846575 0.275578 0.696606 green_beans vegetables
34 Fresh1 1.172248 0.458554 0.451948 1.155360 acorn_squash vegetables
35 Fresh1 2.277940 0.820000 0.264555 0.734926 red_peppers vegetables
36 Fresh green cabbage1 0.579208 0.778797 0.330693 0.245944 cabbage vegetables
37 Fresh red cabbage1 1.056450 0.779107 0.330693 0.448412 cabbage vegetables
38 Fresh1 0.918897 0.811301 0.440925 0.499400 sweet_potatoes vegetables
39 Fresh1 1.639477 0.769500 0.396832 0.845480 summer_squash vegetables
40 Fresh1 1.311629 0.900000 0.275578 0.401618 radish vegetables
41 Fresh1 1.244737 0.714000 0.451948 0.787893 butternut_squash vegetables
42 Fresh1 2.235874 0.740753 0.319670 0.964886 avocados vegetables
43 Fresh1 2.807302 1.050000 0.286601 0.766262 kale vegetables
44 Fresh1 2.213050 0.375309 0.385809 2.274967 artichoke vegetables
45 Fresh1 3.213552 0.769474 0.352740 1.473146 okra vegetables
46 Fresh1 1.410363 0.820000 0.264555 0.455022 green_peppers vegetables
47 Fresh1 2.763553 1.060000 0.341717 0.890898 brussels_sprouts vegetables
48 Fresh1 2.690623 0.540000 0.363763 1.812497 corn_sweet vegetables
In [2]:
fresh.loc[fresh.form == 'Fresh red cabbage1', 'food'] = 'cabbage_red'
fresh.loc[fresh.form == 'Fresh, consumed with peel1', 'food'] = 'cucumber_with_peel'
fresh.loc[fresh.form == 'Fresh, peeled1', 'food'] = 'cucumber_peeled'
In [3]:
fresh
Out[3]:
form price_per_lb yield lb_per_cup price_per_cup food type
0 Fresh1 0.333412 0.520000 0.330693 0.212033 watermelon fruit
1 Fresh1 0.535874 0.510000 0.374786 0.393800 cantaloupe fruit
2 Fresh1 1.377962 0.740000 0.407855 0.759471 tangerines fruit
3 Fresh1 2.358808 0.940000 0.319670 0.802171 strawberries fruit
4 Fresh1 1.827416 0.940000 0.363763 0.707176 plums fruit
5 Fresh1 1.035173 0.730000 0.407855 0.578357 oranges fruit
6 Fresh1 6.975811 0.960000 0.319670 2.322874 raspberries fruit
7 Fresh1 2.173590 0.560000 0.341717 1.326342 pomegranate fruit
8 Fresh1 0.627662 0.510000 0.363763 0.447686 pineapple fruit
9 Fresh1 3.040072 0.930000 0.363763 1.189102 apricots fruit
10 Fresh1 0.796656 0.460000 0.374786 0.649077 honeydew fruit
11 Fresh1 1.298012 0.620000 0.308647 0.646174 papaya fruit
12 Fresh1 2.044683 0.760000 0.385809 1.037970 kiwi fruit
13 Fresh1 3.592990 0.920000 0.341717 1.334548 cherries fruit
14 Fresh1 0.566983 0.640000 0.330693 0.292965 bananas fruit
15 Fresh1 1.567515 0.900000 0.242508 0.422373 apples fruit
16 Fresh1 1.591187 0.960000 0.341717 0.566390 peaches fruit
17 Fresh1 1.761148 0.910000 0.319670 0.618667 nectarines fruit
18 Fresh1 1.461575 0.900000 0.363763 0.590740 pears fruit
19 Fresh1 0.897802 0.490000 0.462971 0.848278 grapefruit fruit
20 Fresh1 5.774708 0.960000 0.319670 1.922919 blackberries fruit
21 Fresh1 2.093827 0.960000 0.330693 0.721266 grapes fruit
22 Fresh1 4.734622 0.950000 0.319670 1.593177 blueberries fruit
23 Fresh1 1.377563 0.710000 0.363763 0.705783 mangoes fruit
24 Fresh1 3.213494 0.493835 0.396832 2.582272 asparagus vegetables
25 Fresh, consumed with peel1 1.295931 0.970000 0.264555 0.353448 cucumber_with_peel vegetables
26 Fresh, peeled1 1.295931 0.730000 0.264555 0.469650 cucumber_peeled vegetables
27 Fresh1 1.213039 0.950000 0.242508 0.309655 lettuce_iceberg vegetables
28 Fresh1 1.038107 0.900000 0.352740 0.406868 onions vegetables
29 Fresh1 2.471749 0.750000 0.319670 1.053526 turnip_greens vegetables
30 Fresh1 2.569235 0.840000 0.308647 0.944032 mustard_greens vegetables
31 Fresh1 0.564320 0.811301 0.264555 0.184017 potatoes vegetables
32 Fresh1 2.630838 1.160000 0.286601 0.650001 collard_greens vegetables
33 Fresh1 2.139972 0.846575 0.275578 0.696606 green_beans vegetables
34 Fresh1 1.172248 0.458554 0.451948 1.155360 acorn_squash vegetables
35 Fresh1 2.277940 0.820000 0.264555 0.734926 red_peppers vegetables
36 Fresh green cabbage1 0.579208 0.778797 0.330693 0.245944 cabbage vegetables
37 Fresh red cabbage1 1.056450 0.779107 0.330693 0.448412 cabbage_red vegetables
38 Fresh1 0.918897 0.811301 0.440925 0.499400 sweet_potatoes vegetables
39 Fresh1 1.639477 0.769500 0.396832 0.845480 summer_squash vegetables
40 Fresh1 1.311629 0.900000 0.275578 0.401618 radish vegetables
41 Fresh1 1.244737 0.714000 0.451948 0.787893 butternut_squash vegetables
42 Fresh1 2.235874 0.740753 0.319670 0.964886 avocados vegetables
43 Fresh1 2.807302 1.050000 0.286601 0.766262 kale vegetables
44 Fresh1 2.213050 0.375309 0.385809 2.274967 artichoke vegetables
45 Fresh1 3.213552 0.769474 0.352740 1.473146 okra vegetables
46 Fresh1 1.410363 0.820000 0.264555 0.455022 green_peppers vegetables
47 Fresh1 2.763553 1.060000 0.341717 0.890898 brussels_sprouts vegetables
48 Fresh1 2.690623 0.540000 0.363763 1.812497 corn_sweet vegetables

Exercise 1.1. Read the search request documentation, then write a function called ndb_search() that makes a search request. The function should accept the search term as an argument. The function should return the search result items as a list (for 0 items, return an empty list).

Note that the search url is: https://api.nal.usda.gov/ndb/search

As an example, a search for "quail eggs" should return this list:

[{u'ds': u'BL',
  u'group': u'Branded Food Products Database',
  u'name': u'CHAOKOH, QUAIL EGG IN BRINE, UPC: 044738074186',
  u'ndbno': u'45094707',
  u'offset': 0},
 {u'ds': u'BL',
  u'group': u'Branded Food Products Database',
  u'name': u'L&W, QUAIL EGGS, UPC: 024072000256',
  u'ndbno': u'45094890',
  u'offset': 1},
 {u'ds': u'BL',
  u'group': u'Branded Food Products Database',
  u'name': u'BUDDHA, QUAIL EGGS IN BRINE, UPC: 761934535098',
  u'ndbno': u'45099560',
  u'offset': 2},
 {u'ds': u'BL',
  u'group': u'Branded Food Products Database',
  u'name': u'GRAN SABANA, QUAIL EGGS, UPC: 819140010103',
  u'ndbno': u'45169279',
  u'offset': 3},
 {u'ds': u'BL',
  u'group': u'Branded Food Products Database',
  u'name': u"D'ARTAGNAN, QUAIL EGGS, UPC: 736622102630",
  u'ndbno': u'45178254',
  u'offset': 4},
 {u'ds': u'SR',
  u'group': u'Dairy and Egg Products',
  u'name': u'Egg, quail, whole, fresh, raw',
  u'ndbno': u'01140',
  u'offset': 5}]

As usual, make sure you document and test your function.

In [4]:
from urllib2 import Request, urlopen
import json
# Gets search URL and gets request function
def ndb_search(key, search):
    search = list(search)
    for i in range (0, len(search)):
        if search[i] == ' ':
            search[i] = '_'
    search = "".join(search)
    search = str(search)
    searchurl = 'https://api.nal.usda.gov/ndb/search?format=json&q=' + search + '&sort=n&max=25&offset=0&api_key=' + key
    request = Request(searchurl)
    response = urlopen(request)
    rr = response.read()
    js = json.loads(rr)
    return js[u'list']
In [5]:
results = ndb_search('A8tjHzrA9pJQTudS94B6XSGMB3BzXeSSwrgUGlix', 'quail eggs')
In [6]:
results
Out[6]:
{u'ds': u'any',
 u'end': 5,
 u'group': u'',
 u'item': [{u'ds': u'BL',
   u'group': u'Branded Food Products Database',
   u'name': u'BUDDHA, QUAIL EGGS IN BRINE, UPC: 761934535098',
   u'ndbno': u'45099560',
   u'offset': 0},
  {u'ds': u'BL',
   u'group': u'Branded Food Products Database',
   u'name': u'CHAOKOH, QUAIL EGG IN BRINE, UPC: 044738074186',
   u'ndbno': u'45094707',
   u'offset': 1},
  {u'ds': u'BL',
   u'group': u'Branded Food Products Database',
   u'name': u"D'ARTAGNAN, QUAIL EGGS, UPC: 736622102630",
   u'ndbno': u'45178254',
   u'offset': 2},
  {u'ds': u'BL',
   u'group': u'Branded Food Products Database',
   u'name': u'GRAN SABANA, QUAIL EGGS, UPC: 819140010103',
   u'ndbno': u'45169279',
   u'offset': 3},
  {u'ds': u'BL',
   u'group': u'Branded Food Products Database',
   u'name': u'L&W, QUAIL EGGS, UPC: 024072000256',
   u'ndbno': u'45094890',
   u'offset': 4}],
 u'q': u'quail_eggs',
 u'sort': u'n',
 u'sr': u'28',
 u'start': 0,
 u'total': 5}

Exercise 1.2. Use your search function to get NDB numbers for the foods in the fresh.csv file. It's okay if you don't get an NDB number for every food, but try to come up with a strategy that gets most of them. Discuss your strategy in a short paragraph.

Hints:

  • The foods are all raw and unbranded.
  • You can test search terms with the online search page.
  • You can convert the output of ndb_search() to a data frame with pd.DataFrame().
  • The string methods for Python and Pandas are useful here. It's okay if you use simple regular expressions in the Pandas methods, although this exercise can be solved without them.
  • You can merge data frames that have a column in common with pd.merge().
In [7]:
# Get list of foods and appends raw next the them
foods = (fresh[['food']])
len(foods.index)
foodlist = []
for i in range(0, len(foods.index)):
    foodlist.append(foods.iloc[i]['food'])
    foodlist[i] = foodlist[i] + ' raw'
foodlist[0:4]
Out[7]:
['watermelon raw', 'cantaloupe raw', 'tangerines raw', 'strawberries raw']
In [8]:
# Gets list of observations
observations = []
for i in range(0, len(foodlist)):
    try:
        observations.append(ndb_search('A8tjHzrA9pJQTudS94B6XSGMB3BzXeSSwrgUGlix', foodlist[i]))
    except KeyError:
        continue
In [9]:
numbers = pd.DataFrame(observations)
In [10]:
numbers.head()
Out[10]:
ds end group item q sort sr start total
0 any 1 [{u'ndbno': u'09326', u'group': u'Fruits and F... watermelon_raw n 28 0 1
1 any 1 [{u'ndbno': u'09181', u'group': u'Fruits and F... cantaloupe_raw n 28 0 1
2 any 2 [{u'ndbno': u'09140', u'group': u'Fruits and F... strawberries_raw n 28 0 2
3 any 2 [{u'ndbno': u'09061', u'group': u'Fruits and F... plums_raw n 28 0 2
4 any 8 [{u'ndbno': u'15073', u'group': u'Finfish and ... oranges_raw n 28 0 8
In [11]:
# Delete raw and make new dataframe
freshfood = (numbers[['q']])
len(freshfood.index)
freshlist = []
for i in range(0, len(freshfood.index)):
    freshlist.append(str(freshfood.iloc[i]['q']))
    freshlist[i] = freshlist[i].rstrip('_raw')
freshlist[0:4]
Out[11]:
['watermelon', 'cantaloupe', 'strawberries', 'plums']
In [12]:
# Get numbers in dataframe
num = (numbers[['item']])
len(freshfood.index)
# The [14:19] of the string returns the number for each observation so I get that into a list
str(num.iloc[0]['item'])[14:19]
numlist = []
for i in range(0, len(num.index)):
    numlist.append(str(num.iloc[i]['item'])[14:19])
numlist[0:4]
Out[12]:
['09326', '09181', '09140', '09061']
In [13]:
# Make new dataframe with only the numbers and foods
numdf = pd.DataFrame({'food': freshlist, 'number': numlist}, index = range(0, len(numlist)))
numdf.head()
Out[13]:
food number
0 watermelon 09326
1 cantaloupe 09181
2 strawberries 09140
3 plums 09061
4 oranges 15073
In [14]:
# Merge the two dataframes together
newdf = pd.merge(fresh, numdf, on = 'food')
newdf.head()
Out[14]:
form price_per_lb yield lb_per_cup price_per_cup food type number
0 Fresh1 0.333412 0.52 0.330693 0.212033 watermelon fruit 09326
1 Fresh1 0.535874 0.51 0.374786 0.393800 cantaloupe fruit 09181
2 Fresh1 2.358808 0.94 0.319670 0.802171 strawberries fruit 09140
3 Fresh1 1.827416 0.94 0.363763 0.707176 plums fruit 09061
4 Fresh1 1.035173 0.73 0.407855 0.578357 oranges fruit 15073

For this exercise, I first extracted the foods from the fresh dataframe and appended the string ' raw' to them so that I could use them for my search. I searched through the whole list of values and got the item object which contains the number in them in a new data frame. I extracted the numbers and foods and stripped the raw from them back so that I can make a new dataframe with only the foods and numbers. Then I merged the two dataframes together using the food as my key. I also converted some of the duplicate foods such as cucumbers and cabbage to their specific names to make this more accurate.

Exercise 1.3. Read the food reports V2 documentation, then write a function called ndb_report() that requests a basic food report. The function should accept the NDB number as an argument and return the list of nutrients for the food.

Note that the report url is: https://api.nal.usda.gov/ndb/V2/reports

For example, for "09279" (raw plums) the first element of the returned list should be:

{u'group': u'Proximates',
 u'measures': [{u'eqv': 165.0,
   u'eunit': u'g',
   u'label': u'cup, sliced',
   u'qty': 1.0,
   u'value': u'143.93'},
  {u'eqv': 66.0,
   u'eunit': u'g',
   u'label': u'fruit (2-1/8" dia)',
   u'qty': 1.0,
   u'value': u'57.57'},
  {u'eqv': 151.0,
   u'eunit': u'g',
   u'label': u'NLEA serving',
   u'qty': 1.0,
   u'value': u'131.72'}],
 u'name': u'Water',
 u'nutrient_id': u'255',
 u'unit': u'g',
 u'value': u'87.23'}

Be sure to document and test your function.

In [15]:
# Gets search URL and gets request function
def ndb_report(key, search):
    searchurl = 'https://api.nal.usda.gov/ndb/V2/reports?ndbno=' + search + '&type=f&format=json&api_key=' + key
    request = Request(searchurl)
    response = urlopen(request)
    rr = response.read()
    js = json.loads(rr)
    return js[u'foods'][0][u'food'][u'nutrients'][0]
In [16]:
report = ndb_report('A8tjHzrA9pJQTudS94B6XSGMB3BzXeSSwrgUGlix', '09279')
In [17]:
report
Out[17]:
{u'dp': 10,
 u'group': u'Proximates',
 u'measures': [{u'eqv': 165.0,
   u'eunit': u'g',
   u'label': u'cup, sliced',
   u'qty': 1.0,
   u'value': 143.93},
  {u'eqv': 66.0,
   u'eunit': u'g',
   u'label': u'fruit (2-1/8" dia)',
   u'qty': 1.0,
   u'value': 57.57},
  {u'eqv': 151.0,
   u'eunit': u'g',
   u'label': u'NLEA serving',
   u'qty': 1.0,
   u'value': 131.72}],
 u'name': u'Water',
 u'nutrient_id': 255,
 u'se': u'0.328',
 u'sourcecode': [1, 2, 3],
 u'unit': u'g',
 u'value': 87.23}

Exercise 1.4. Which foods provide the best combination of price, yield, and nutrition? You can use kilocalories as a measure of "nutrition" here, but more a detailed analysis is better. Use plots to support your analysis.

In [18]:
# Gets nutrients
nutrients = []
for i in range(0, len(newdf.index)):
    try:
        nutrients.append(ndb_report('A8tjHzrA9pJQTudS94B6XSGMB3BzXeSSwrgUGlix', newdf.iloc[i]['number']))
    except KeyError:
        continue
In [19]:
nutrients
Out[19]:
[{u'dp': 14,
  u'group': u'Proximates',
  u'measures': [{u'eqv': 154.0,
    u'eunit': u'g',
    u'label': u'cup, balls',
    u'qty': 1.0,
    u'value': 140.83},
   {u'eqv': 152.0,
    u'eunit': u'g',
    u'label': u'cup, diced',
    u'qty': 1.0,
    u'value': 139.0},
   {u'eqv': 4518.0,
    u'eunit': u'g',
    u'label': u'melon (15" long x 7-1/2" dia)',
    u'qty': 1.0,
    u'value': 4131.71},
   {u'eqv': 286.0,
    u'eunit': u'g',
    u'label': u'wedge (approx 1/16 of melon)',
    u'qty': 1.0,
    u'value': 261.55},
   {u'eqv': 122.0,
    u'eunit': u'g',
    u'label': u'watermelon balls',
    u'qty': 10.0,
    u'value': 111.57},
   {u'eqv': 280.0,
    u'eunit': u'g',
    u'label': u'NLEA serving',
    u'qty': 1.0,
    u'value': 256.06}],
  u'name': u'Water',
  u'nutrient_id': 255,
  u'se': u'0.316',
  u'sourcecode': [1, 2, 3, 4, 5, 6],
  u'unit': u'g',
  u'value': 91.45},
 {u'dp': 30,
  u'group': u'Proximates',
  u'measures': [{u'eqv': 177.0,
    u'eunit': u'g',
    u'label': u'cup, balls',
    u'qty': 1.0,
    u'value': 159.57},
   {u'eqv': 160.0,
    u'eunit': u'g',
    u'label': u'cup, cubes',
    u'qty': 1.0,
    u'value': 144.24},
   {u'eqv': 156.0,
    u'eunit': u'g',
    u'label': u'cup, diced',
    u'qty': 1.0,
    u'value': 140.63},
   {u'eqv': 814.0,
    u'eunit': u'g',
    u'label': u'melon, large (about 6-1/2" dia)',
    u'qty': 1.0,
    u'value': 733.82},
   {u'eqv': 102.0,
    u'eunit': u'g',
    u'label': u'wedge, large (1/8 of large melon)',
    u'qty': 1.0,
    u'value': 91.95},
   {u'eqv': 552.0,
    u'eunit': u'g',
    u'label': u'melon, medium (about 5" dia)',
    u'qty': 1.0,
    u'value': 497.63},
   {u'eqv': 69.0,
    u'eunit': u'g',
    u'label': u'wedge, medium (1/8 of medium melon)',
    u'qty': 1.0,
    u'value': 62.2},
   {u'eqv': 441.0,
    u'eunit': u'g',
    u'label': u'melon, small (about 4-1/4" dia)',
    u'qty': 1.0,
    u'value': 397.56},
   {u'eqv': 55.0,
    u'eunit': u'g',
    u'label': u'wedge, small (1/8 of small melon)',
    u'qty': 1.0,
    u'value': 49.58},
   {u'eqv': 138.0,
    u'eunit': u'g',
    u'label': u'cantaloupe balls',
    u'qty': 10.0,
    u'value': 124.41},
   {u'eqv': 134.0,
    u'eunit': u'g',
    u'label': u'NLEA serving',
    u'qty': 1.0,
    u'value': 120.8}],
  u'name': u'Water',
  u'nutrient_id': 255,
  u'se': u'0.312',
  u'sourcecode': [1, 2, 3, 4, 5, 6, 7],
  u'unit': u'g',
  u'value': 90.15},
 {u'dp': 2,
  u'group': u'Proximates',
  u'measures': [{u'eqv': 244.0,
    u'eunit': u'g',
    u'label': u'cup',
    u'qty': 1.0,
    u'value': 196.81},
   {u'eqv': 6.0,
    u'eunit': u'g',
    u'label': u'fruit without refuse',
    u'qty': 1.0,
    u'value': 4.84}],
  u'name': u'Water',
  u'nutrient_id': 255,
  u'se': u'',
  u'sourcecode': u'',
  u'unit': u'g',
  u'value': 80.66},
 {u'dp': 1,
  u'group': u'Proximates',
  u'measures': [{u'eqv': 150.0,
    u'eunit': u'g',
    u'label': u'cup slices',
    u'qty': 1.0,
    u'value': 126.25},
   {u'eqv': 20.0,
    u'eunit': u'g',
    u'label': u'fruit without skin and seeds',
    u'qty': 1.0,
    u'value': 16.83}],
  u'name': u'Water',
  u'nutrient_id': 255,
  u'se': u'',
  u'sourcecode': u'',
  u'unit': u'g',
  u'value': 84.17},
 {u'dp': 3,
  u'group': u'Proximates',
  u'measures': [{u'eqv': 85.0,
    u'eunit': u'g',
    u'label': u'oz',
    u'qty': 3.0,
    u'value': 64.32}],
  u'name': u'Water',
  u'nutrient_id': 255,
  u'se': u'1.352',
  u'sourcecode': [1],
  u'unit': u'g',
  u'value': 75.67},
 {u'dp': 14,
  u'group': u'Proximates',
  u'measures': [{u'eqv': 123.0,
    u'eunit': u'g',
    u'label': u'cup',
    u'qty': 1.0,
    u'value': 105.47},
   {u'eqv': 312.0,
    u'eunit': u'g',
    u'label': u'pint as purchased, yields',
    u'qty': 1.0,
    u'value': 267.54},
   {u'eqv': 19.0,
    u'eunit': u'g',
    u'label': u'raspberries',
    u'qty': 10.0,
    u'value': 16.29}],
  u'name': u'Water',
  u'nutrient_id': 255,
  u'se': u'0.990',
  u'sourcecode': [1, 2, 3, 4, 5],
  u'unit': u'g',
  u'value': 85.75},
 {u'dp': 3,
  u'group': u'Proximates',
  u'measures': [{u'eqv': 87.0,
    u'eunit': u'g',
    u'label': u'cup arils (seed/juice sacs)',
    u'qty': 0.5,
    u'value': 67.8},
   {u'eqv': 282.0,
    u'eunit': u'g',
    u'label': u'pomegranate (4" dia)',
    u'qty': 1.0,
    u'value': 219.76}],
  u'name': u'Water',
  u'nutrient_id': 255,
  u'se': u'0.033',
  u'sourcecode': [1],
  u'unit': u'g',
  u'value': 77.93},
 {u'dp': 21,
  u'group': u'Proximates',
  u'measures': [{u'eqv': 165.0,
    u'eunit': u'g',
    u'label': u'cup, chunks',
    u'qty': 1.0,
    u'value': 141.9},
   {u'eqv': 905.0,
    u'eunit': u'g',
    u'label': u'fruit',
    u'qty': 1.0,
    u'value': 778.3},
   {u'eqv': 166.0,
    u'eunit': u'g',
    u'label': u'slice (4-2/3" dia x 3/4" thick)',
    u'qty': 1.0,
    u'value': 142.76},
   {u'eqv': 84.0,
    u'eunit': u'g',
    u'label': u'slice (3-1/2" dia x 3/4" thick)',
    u'qty': 1.0,
    u'value': 72.24},
   {u'eqv': 56.0,
    u'eunit': u'g',
    u'label': u'slice, thin (3-1/2" dia x 1/2" thick)',
    u'qty': 1.0,
    u'value': 48.16}],
  u'name': u'Water',
  u'nutrient_id': 255,
  u'se': u'0.506',
  u'sourcecode': [1, 2, 3],
  u'unit': u'g',
  u'value': 86.0},
 {u'dp': 26,
  u'group': u'Proximates',
  u'measures': [{u'eqv': 155.0,
    u'eunit': u'g',
    u'label': u'cup, halves',
    u'qty': 1.0,
    u'value': 133.84},
   {u'eqv': 165.0,
    u'eunit': u'g',
    u'label': u'cup, sliced',
    u'qty': 1.0,
    u'value': 142.48},
   {u'eqv': 35.0,
    u'eunit': u'g',
    u'label': u'apricot',
    u'qty': 1.0,
    u'value': 30.22}],
  u'name': u'Water',
  u'nutrient_id': 255,
  u'se': u'',
  u'sourcecode': u'',
  u'unit': u'g',
  u'value': 86.35},
 {u'dp': 1,
  u'group': u'Proximates',
  u'measures': [{u'eqv': 98.0,
    u'eunit': u'g',
    u'label': u'cup',
    u'qty': 1.0,
    u'value': 89.58},
   {u'eqv': 4.8,
    u'eunit': u'g',
    u'label': u'fruit without refuse',
    u'qty': 1.0,
    u'value': 4.39}],
  u'name': u'Water',
  u'nutrient_id': 255,
  u'se': u'',
  u'sourcecode': u'',
  u'unit': u'g',
  u'value': 91.41},
 {u'dp': 20,
  u'group': u'Proximates',
  u'measures': [{u'eqv': 225.0,
    u'eunit': u'g',
    u'label': u'cup, mashed',
    u'qty': 1.0,
    u'value': 168.55},
   {u'eqv': 150.0,
    u'eunit': u'g',
    u'label': u'cup, sliced',
    u'qty': 1.0,
    u'value': 112.36},
   {u'eqv': 81.0,
    u'eunit': u'g',
    u'label': u'extra small (less than 6" long)',
    u'qty': 1.0,
    u'value': 60.68},
   {u'eqv': 101.0,
    u'eunit': u'g',
    u'label': u'small (6" to 6-7/8" long)',
    u'qty': 1.0,
    u'value': 75.66},
   {u'eqv': 118.0,
    u'eunit': u'g',
    u'label': u'medium (7" to 7-7/8" long)',
    u'qty': 1.0,
    u'value': 88.39},
   {u'eqv': 136.0,
    u'eunit': u'g',
    u'label': u'large (8" to 8-7/8" long)',
    u'qty': 1.0,
    u'value': 101.88},
   {u'eqv': 152.0,
    u'eunit': u'g',
    u'label': u'extra large (9" or longer)',
    u'qty': 1.0,
    u'value': 113.86},
   {u'eqv': 126.0,
    u'eunit': u'g',
    u'label': u'NLEA serving',
    u'qty': 1.0,
    u'value': 94.39}],
  u'name': u'Water',
  u'nutrient_id': 255,
  u'se': u'0.286',
  u'sourcecode': [1, 2, 3, 4, 5, 6],
  u'unit': u'g',
  u'value': 74.91},
 {u'dp': 4,
  u'group': u'Proximates',
  u'measures': [{u'eqv': 109.0,
    u'eunit': u'g',
    u'label': u'cup, sliced',
    u'qty': 1.0,
    u'value': 91.73},
   {u'eqv': 236.0,
    u'eunit': u'g',
    u'label': u'large',
    u'qty': 1.0,
    u'value': 198.62},
   {u'eqv': 192.0,
    u'eunit': u'g',
    u'label': u'medium',
    u'qty': 1.0,
    u'value': 161.59},
   {u'eqv': 158.0,
    u'eunit': u'g',
    u'label': u'small',
    u'qty': 1.0,
    u'value': 132.97}],
  u'name': u'Water',
  u'nutrient_id': 255,
  u'se': u'0.473',
  u'sourcecode': [1, 2],
  u'unit': u'g',
  u'value': 84.16},
 {u'dp': 17,
  u'group': u'Proximates',
  u'measures': [{u'eqv': 143.0,
    u'eunit': u'g',
    u'label': u'cup slices',
    u'qty': 1.0,
    u'value': 125.25},
   {u'eqv': 129.0,
    u'eunit': u'g',
    u'label': u'small (2-1/3" dia)',
    u'qty': 1.0,
    u'value': 112.99},
   {u'eqv': 142.0,
    u'eunit': u'g',
    u'label': u'medium (2-1/2" dia)',
    u'qty': 1.0,
    u'value': 124.38},
   {u'eqv': 156.0,
    u'eunit': u'g',
    u'label': u'large (2-3/4" dia)',
    u'qty': 1.0,
    u'value': 136.64},
   {u'eqv': 140.0,
    u'eunit': u'g',
    u'label': u'NLEA serving',
    u'qty': 1.0,
    u'value': 122.63}],
  u'name': u'Water',
  u'nutrient_id': 255,
  u'se': u'0.651',
  u'sourcecode': [1, 2, 3, 4, 5, 6, 7],
  u'unit': u'g',
  u'value': 87.59},
 {u'dp': 32,
  u'group': u'Proximates',
  u'measures': [{u'eqv': 140.0,
    u'eunit': u'g',
    u'label': u'cup, slices',
    u'qty': 1.0,
    u'value': 117.54},
   {u'eqv': 161.0,
    u'eunit': u'g',
    u'label': u'cup, cubes',
    u'qty': 1.0,
    u'value': 135.18},
   {u'eqv': 148.0,
    u'eunit': u'g',
    u'label': u'small',
    u'qty': 1.0,
    u'value': 124.26},
   {u'eqv': 178.0,
    u'eunit': u'g',
    u'label': u'medium',
    u'qty': 1.0,
    u'value': 149.45},
   {u'eqv': 230.0,
    u'eunit': u'g',
    u'label': u'large',
    u'qty': 1.0,
    u'value': 193.11},
   {u'eqv': 166.0,
    u'eunit': u'g',
    u'label': u'NLEA serving',
    u'qty': 1.0,
    u'value': 139.37}],
  u'name': u'Water',
  u'nutrient_id': 255,
  u'se': u'0.111',
  u'sourcecode': [1, 2],
  u'unit': u'g',
  u'value': 83.96},
 {u'dp': 9,
  u'group': u'Proximates',
  u'measures': [{u'eqv': 230.0,
    u'eunit': u'g',
    u'label': u'cup sections, with juice',
    u'qty': 1.0,
    u'value': 202.54},
   {u'eqv': 123.0,
    u'eunit': u'g',
    u'label': u'fruit (3-3/4" dia)',
    u'qty': 0.5,
    u'value': 108.31},
   {u'eqv': 154.0,
    u'eunit': u'g',
    u'label': u'NLEA serving',
    u'qty': 1.0,
    u'value': 135.61}],
  u'name': u'Water',
  u'nutrient_id': 255,
  u'se': u'0.761',
  u'sourcecode': [1, 2, 3],
  u'unit': u'g',
  u'value': 88.06},
 {u'dp': 5,
  u'group': u'Proximates',
  u'measures': [{u'eqv': 144.0,
    u'eunit': u'g',
    u'label': u'cup',
    u'qty': 1.0,
    u'value': 126.94}],
  u'name': u'Water',
  u'nutrient_id': 255,
  u'se': u'0.776',
  u'sourcecode': [1, 2],
  u'unit': u'g',
  u'value': 88.15},
 {u'dp': 12,
  u'group': u'Proximates',
  u'measures': [{u'eqv': 148.0,
    u'eunit': u'g',
    u'label': u'cup',
    u'qty': 1.0,
    u'value': 124.63},
   {u'eqv': 68.0,
    u'eunit': u'g',
    u'label': u'berries',
    u'qty': 50.0,
    u'value': 57.26}],
  u'name': u'Water',
  u'nutrient_id': 255,
  u'se': u'0.672',
  u'sourcecode': [1, 2, 3],
  u'unit': u'g',
  u'value': 84.21},
 {u'dp': 299,
  u'group': u'Proximates',
  u'measures': [{u'eqv': 165.0,
    u'eunit': u'g',
    u'label': u'cup pieces',
    u'qty': 1.0,
    u'value': 137.71},
   {u'eqv': 336.0,
    u'eunit': u'g',
    u'label': u'fruit without refuse',
    u'qty': 1.0,
    u'value': 280.43}],
  u'name': u'Water',
  u'nutrient_id': 255,
  u'se': u'0.478',
  u'sourcecode': [1, 2, 3, 4, 5],
  u'unit': u'g',
  u'value': 83.46},
 {u'dp': 1,
  u'group': u'Proximates',
  u'measures': [{u'eqv': 134.0,
    u'eunit': u'g',
    u'label': u'cup',
    u'qty': 1.0,
    u'value': 124.91},
   {u'eqv': 12.0,
    u'eunit': u'g',
    u'label': u'spear, small (5" long or less)',
    u'qty': 1.0,
    u'value': 11.19},
   {u'eqv': 16.0,
    u'eunit': u'g',
    u'label': u'spear, medium (5-1/4" to 7" long)',
    u'qty': 1.0,
    u'value': 14.92},
   {u'eqv': 20.0,
    u'eunit': u'g',
    u'label': u'spear, large (7-1/4" to 8-1/2")',
    u'qty': 1.0,
    u'value': 18.64},
   {u'eqv': 24.0,
    u'eunit': u'g',
    u'label': u'spear, extra large (8-3/4" to 10" long)',
    u'qty': 1.0,
    u'value': 22.37},
   {u'eqv': 3.5,
    u'eunit': u'g',
    u'label': u'spear tip (2" long or less)',
    u'qty': 1.0,
    u'value': 3.26}],
  u'name': u'Water',
  u'nutrient_id': 255,
  u'se': u'',
  u'sourcecode': [1],
  u'unit': u'g',
  u'value': 93.22},
 {u'dp': 2,
  u'group': u'Proximates',
  u'measures': [{u'eqv': 52.0,
    u'eunit': u'g',
    u'label': u'cup slices',
    u'qty': 0.5,
    u'value': 49.52},
   {u'eqv': 301.0,
    u'eunit': u'g',
    u'label': u'cucumber (8-1/4")',
    u'qty': 1.0,
    u'value': 286.64}],
  u'name': u'Water',
  u'nutrient_id': 255,
  u'se': u'',
  u'sourcecode': [1],
  u'unit': u'g',
  u'value': 95.23},
 {u'dp': 7,
  u'group': u'Proximates',
  u'measures': [{u'eqv': 133.0,
    u'eunit': u'g',
    u'label': u'cup, pared, chopped',
    u'qty': 1.0,
    u'value': 128.65},
   {u'eqv': 119.0,
    u'eunit': u'g',
    u'label': u'cup, sliced',
    u'qty': 1.0,
    u'value': 115.11},
   {u'eqv': 280.0,
    u'eunit': u'g',
    u'label': u'large (8-1/4" long)',
    u'qty': 1.0,
    u'value': 270.84},
   {u'eqv': 201.0,
    u'eunit': u'g',
    u'label': u'medium',
    u'qty': 1.0,
    u'value': 194.43},
   {u'eqv': 7.0,
    u'eunit': u'g',
    u'label': u'slice',
    u'qty': 1.0,
    u'value': 6.77},
   {u'eqv': 158.0,
    u'eunit': u'g',
    u'label': u'small (6-3/8" long)',
    u'qty': 1.0,
    u'value': 152.83},
   {u'eqv': 9.0,
    u'eunit': u'g',
    u'label': u'stick (4" long)',
    u'qty': 1.0,
    u'value': 8.71}],
  u'name': u'Water',
  u'nutrient_id': 255,
  u'se': u'0.286',
  u'sourcecode': [1],
  u'unit': u'g',
  u'value': 96.73},
 {u'dp': 34,
  u'group': u'Proximates',
  u'measures': [{u'eqv': 160.0,
    u'eunit': u'g',
    u'label': u'cup, chopped',
    u'qty': 1.0,
    u'value': 142.58},
   {u'eqv': 115.0,
    u'eunit': u'g',
    u'label': u'cup, sliced',
    u'qty': 1.0,
    u'value': 102.48},
   {u'eqv': 10.0,
    u'eunit': u'g',
    u'label': u'tbsp chopped',
    u'qty': 1.0,
    u'value': 8.91},
   {u'eqv': 150.0,
    u'eunit': u'g',
    u'label': u'large',
    u'qty': 1.0,
    u'value': 133.66},
   {u'eqv': 38.0,
    u'eunit': u'g',
    u'label': u'slice, large (1/4" thick)',
    u'qty': 1.0,
    u'value': 33.86},
   {u'eqv': 110.0,
    u'eunit': u'g',
    u'label': u'medium (2-1/2" dia)',
    u'qty': 1.0,
    u'value': 98.02},
   {u'eqv': 14.0,
    u'eunit': u'g',
    u'label': u'slice, medium (1/8" thick)',
    u'qty': 1.0,
    u'value': 12.48},
   {u'eqv': 70.0,
    u'eunit': u'g',
    u'label': u'small',
    u'qty': 1.0,
    u'value': 62.38},
   {u'eqv': 9.0,
    u'eunit': u'g',
    u'label': u'slice, thin',
    u'qty': 1.0,
    u'value': 8.02},
   {u'eqv': 60.0,
    u'eunit': u'g',
    u'label': u'rings',
    u'qty': 10.0,
    u'value': 53.47}],
  u'name': u'Water',
  u'nutrient_id': 255,
  u'se': u'0.248',
  u'sourcecode': [1],
  u'unit': u'g',
  u'value': 89.11},
 {u'dp': 3,
  u'group': u'Proximates',
  u'measures': [{u'eqv': 55.0,
    u'eunit': u'g',
    u'label': u'cup, chopped',
    u'qty': 1.0,
    u'value': 49.32}],
  u'name': u'Water',
  u'nutrient_id': 255,
  u'se': u'0.467',
  u'sourcecode': u'',
  u'unit': u'g',
  u'value': 89.67},
 {u'dp': 10,
  u'group': u'Proximates',
  u'measures': [{u'eqv': 56.0,
    u'eunit': u'g',
    u'label': u'cup, chopped',
    u'qty': 1.0,
    u'value': 50.79}],
  u'name': u'Water',
  u'nutrient_id': 255,
  u'se': u'0.904',
  u'sourcecode': [1],
  u'unit': u'g',
  u'value': 90.7},
 {u'dp': 6,
  u'group': u'Proximates',
  u'measures': [{u'eqv': 38.0,
    u'eunit': u'g',
    u'label': u'skin',
    u'qty': 1.0,
    u'value': 31.65}],
  u'name': u'Water',
  u'nutrient_id': 255,
  u'se': u'0.366',
  u'sourcecode': u'',
  u'unit': u'g',
  u'value': 83.29},
 {u'dp': 20,
  u'group': u'Proximates',
  u'measures': [{u'eqv': 89.0,
    u'eunit': u'g',
    u'label': u'cup, chopped',
    u'qty': 1.0,
    u'value': 82.04},
   {u'eqv': 70.0,
    u'eunit': u'g',
    u'label': u'cup, shredded',
    u'qty': 1.0,
    u'value': 64.53},
   {u'eqv': 1248.0,
    u'eunit': u'g',
    u'label': u'head, large (about 7" dia)',
    u'qty': 1.0,
    u'value': 1150.41},
   {u'eqv': 33.0,
    u'eunit': u'g',
    u'label': u'leaf, large',
    u'qty': 1.0,
    u'value': 30.42},
   {u'eqv': 908.0,
    u'eunit': u'g',
    u'label': u'head, medium (about 5-3/4" dia)',
    u'qty': 1.0,
    u'value': 836.99},
   {u'eqv': 23.0,
    u'eunit': u'g',
    u'label': u'leaf, medium',
    u'qty': 1.0,
    u'value': 21.2},
   {u'eqv': 714.0,
    u'eunit': u'g',
    u'label': u'head, small (about 4-1/2" dia)',
    u'qty': 1.0,
    u'value': 658.17},
   {u'eqv': 15.0,
    u'eunit': u'g',
    u'label': u'leaf',
    u'qty': 1.0,
    u'value': 13.83}],
  u'name': u'Water',
  u'nutrient_id': 255,
  u'se': u'0.128',
  u'sourcecode': [1],
  u'unit': u'g',
  u'value': 92.18},
 {u'dp': 5,
  u'group': u'Proximates',
  u'measures': [{u'eqv': 89.0,
    u'eunit': u'g',
    u'label': u'cup, chopped',
    u'qty': 1.0,
    u'value': 80.45},
   {u'eqv': 70.0,
    u'eunit': u'g',
    u'label': u'cup, shredded',
    u'qty': 1.0,
    u'value': 63.27},
   {u'eqv': 1134.0,
    u'eunit': u'g',
    u'label': u'head, large (about 5-1/2" dia)',
    u'qty': 1.0,
    u'value': 1025.02},
   {u'eqv': 23.0,
    u'eunit': u'g',
    u'label': u'leaf',
    u'qty': 1.0,
    u'value': 20.79},
   {u'eqv': 839.0,
    u'eunit': u'g',
    u'label': u'head, medium (about 5" dia)',
    u'qty': 1.0,
    u'value': 758.37},
   {u'eqv': 567.0,
    u'eunit': u'g',
    u'label': u'head, small (4" dia)',
    u'qty': 1.0,
    u'value': 512.51}],
  u'name': u'Water',
  u'nutrient_id': 255,
  u'se': u'0.325',
  u'sourcecode': [1],
  u'unit': u'g',
  u'value': 90.39},
 {u'dp': 7,
  u'group': u'Proximates',
  u'measures': [{u'eqv': 133.0,
    u'eunit': u'g',
    u'label': u'cup, cubes',
    u'qty': 1.0,
    u'value': 102.78},
   {u'eqv': 130.0,
    u'eunit': u'g',
    u'label': u'sweetpotato, 5" long',
    u'qty': 1.0,
    u'value': 100.46}],
  u'name': u'Water',
  u'nutrient_id': 255,
  u'se': u'0.650',
  u'sourcecode': [1],
  u'unit': u'g',
  u'value': 77.28},
 {u'dp': 21,
  u'group': u'Proximates',
  u'measures': [{u'eqv': 116.0,
    u'eunit': u'g',
    u'label': u'cup slices',
    u'qty': 1.0,
    u'value': 110.51},
   {u'eqv': 9.0,
    u'eunit': u'g',
    u'label': u'large (1" to 1-1/4" dia)',
    u'qty': 1.0,
    u'value': 8.57},
   {u'eqv': 4.5,
    u'eunit': u'g',
    u'label': u'medium (3/4" to 1" dia)',
    u'qty': 1.0,
    u'value': 4.29},
   {u'eqv': 1.0,
    u'eunit': u'g',
    u'label': u'slice',
    u'qty': 1.0,
    u'value': 0.95},
   {u'eqv': 2.0,
    u'eunit': u'g',
    u'label': u'small',
    u'qty': 1.0,
    u'value': 1.91},
   {u'eqv': 58.0,
    u'eunit': u'g',
    u'label': u'cup slices',
    u'qty': 0.5,
    u'value': 55.26}],
  u'name': u'Water',
  u'nutrient_id': 255,
  u'se': u'0.227',
  u'sourcecode': [1, 2],
  u'unit': u'g',
  u'value': 95.27},
 {u'dp': 40,
  u'group': u'Proximates',
  u'measures': [{u'eqv': 150.0,
    u'eunit': u'g',
    u'label': u'cup, cubes',
    u'qty': 1.0,
    u'value': 109.84},
   {u'eqv': 230.0,
    u'eunit': u'g',
    u'label': u'cup, pureed',
    u'qty': 1.0,
    u'value': 168.43},
   {u'eqv': 146.0,
    u'eunit': u'g',
    u'label': u'cup, sliced',
    u'qty': 1.0,
    u'value': 106.92},
   {u'eqv': 201.0,
    u'eunit': u'g',
    u'label': u'avocado, NS as to Florida or California',
    u'qty': 1.0,
    u'value': 147.19}],
  u'name': u'Water',
  u'nutrient_id': 255,
  u'se': u'1.898',
  u'sourcecode': [1, 2, 3, 4, 5, 6, 7, 8],
  u'unit': u'g',
  u'value': 73.23},
 {u'dp': 6,
  u'group': u'Proximates',
  u'measures': [{u'eqv': 16.0,
    u'eunit': u'g',
    u'label': u'cup 1" pieces, loosely packed',
    u'qty': 1.0,
    u'value': 13.45}],
  u'name': u'Water',
  u'nutrient_id': 255,
  u'se': u'0.443',
  u'sourcecode': [1],
  u'unit': u'g',
  u'value': 84.04},
 {u'dp': 3,
  u'group': u'Proximates',
  u'measures': [{u'eqv': 150.0,
    u'eunit': u'g',
    u'label': u'cup slices',
    u'qty': 1.0,
    u'value': 117.02}],
  u'name': u'Water',
  u'nutrient_id': 255,
  u'se': u'0.640',
  u'sourcecode': u'',
  u'unit': u'g',
  u'value': 78.01},
 {u'dp': 8,
  u'group': u'Proximates',
  u'measures': [{u'eqv': 88.0,
    u'eunit': u'g',
    u'label': u'cup',
    u'qty': 1.0,
    u'value': 75.68},
   {u'eqv': 19.0,
    u'eunit': u'g',
    u'label': u'sprout',
    u'qty': 1.0,
    u'value': 16.34}],
  u'name': u'Water',
  u'nutrient_id': 255,
  u'se': u'0.435',
  u'sourcecode': u'',
  u'unit': u'g',
  u'value': 86.0}]
In [20]:
nutdf = pd.DataFrame(nutrients)
In [21]:
nutdf.head()
Out[21]:
dp group measures name nutrient_id se sourcecode unit value
0 14 Proximates [{u'eunit': u'g', u'eqv': 154.0, u'qty': 1.0, ... Water 255 0.316 [1, 2, 3, 4, 5, 6] g 91.45
1 30 Proximates [{u'eunit': u'g', u'eqv': 177.0, u'qty': 1.0, ... Water 255 0.312 [1, 2, 3, 4, 5, 6, 7] g 90.15
2 2 Proximates [{u'eunit': u'g', u'eqv': 244.0, u'qty': 1.0, ... Water 255 g 80.66
3 1 Proximates [{u'eunit': u'g', u'eqv': 150.0, u'qty': 1.0, ... Water 255 g 84.17
4 3 Proximates [{u'eunit': u'g', u'eqv': 85.0, u'qty': 3.0, u... Water 255 1.352 [1] g 75.67
In [22]:
# Get water values in dataframe
nutvalue = (nutdf[['value']])
nutvalue.head()
Out[22]:
value
0 91.45
1 90.15
2 80.66
3 84.17
4 75.67
In [23]:
# Since I ran the basic report function from the foods I originally got, the each value should correspond with the correct food
newdf = newdf.join(nutvalue)
In [24]:
newdf.head()
Out[24]:
form price_per_lb yield lb_per_cup price_per_cup food type number value
0 Fresh1 0.333412 0.52 0.330693 0.212033 watermelon fruit 09326 91.45
1 Fresh1 0.535874 0.51 0.374786 0.393800 cantaloupe fruit 09181 90.15
2 Fresh1 2.358808 0.94 0.319670 0.802171 strawberries fruit 09140 80.66
3 Fresh1 1.827416 0.94 0.363763 0.707176 plums fruit 09061 84.17
4 Fresh1 1.035173 0.73 0.407855 0.578357 oranges fruit 15073 75.67
In [25]:
price_per_lb = newdf[['price_per_lb']]
price_per_lb.head()
Out[25]:
price_per_lb
0 0.333412
1 0.535874
2 2.358808
3 1.827416
4 1.035173
In [26]:
yields = newdf[['yield']]
yields.head()
Out[26]:
yield
0 0.52
1 0.51
2 0.94
3 0.94
4 0.73
In [27]:
water = newdf[['value']]
water.head()
Out[27]:
value
0 91.45
1 90.15
2 80.66
3 84.17
4 75.67
In [28]:
from matplotlib import pyplot as plt
plt.style.use('ggplot')
In [34]:
plt.hist(price_per_lb['price_per_lb'], label = "Price")
plt.show()
In [33]:
plt.hist(yields['yield'], label = "Yield")
plt.show()
In [35]:
plt.hist(water['value'], label = "Water Value")
plt.show()
In [59]:
ratio = price_per_lb['price_per_lb']/yields['yield']
newdf['ratio'] = ratio
ratio = newdf[['ratio']]
plt.hist(ratio['ratio'], label = "Price and Yield Ratio")
plt.show()
In [73]:
cheapfoods = newdf.loc[newdf['price_per_lb'] < 1]
highyields = newdf.loc[newdf['yield'] > 0.9]
highratio = newdf.loc[newdf['ratio'] > 5]
highwater = newdf.loc[newdf['value'] > 90]
print cheapfoods.iloc[0:len(cheapfoods.index)]['food']
print highyields.iloc[0:len(highyields.index)]['food']
print highwater.iloc[0:len(highwater.index)]['food']
print highratio.iloc[0:len(highratio.index)]['food']
0         watermelon
1         cantaloupe
7          pineapple
10           bananas
14        grapefruit
24          potatoes
25           cabbage
27    sweet_potatoes
Name: food, dtype: object
2           strawberries
3                  plums
5            raspberries
8               apricots
9               cherries
12            nectarines
15          blackberries
16           blueberries
19    cucumber_with_peel
30                  kale
32      brussels_sprouts
Name: food, dtype: object
0             watermelon
1             cantaloupe
9               cherries
18             asparagus
19    cucumber_with_peel
20       cucumber_peeled
23        mustard_greens
25               cabbage
26           cabbage_red
28                radish
Name: food, dtype: object
5      raspberries
15    blackberries
18       asparagus
31       artichoke
Name: food, dtype: object

Based on the foods I found with the cheapest prices, high yields, and high nutrition value based on water value, I think that the foods with the best value are watermelons, cantaloupes, nectarines, red cabbages, cucumbers with peels, and asparagus. This may not be accurate since I'm only basing it off of the water value instead of kilocalories. I chose water level instead of kilocalories because having too much kilocalorie in one food may not be beneficial to the body. This could be more accurate if other foods and other nutrients were taken into account but having too much of one nutrients is not beneficial to the body so this could be found by perhaps setting a healthy range of nutrients in order to analyze this. I interpreted "best value" as having a good amount of all of these things so I found the prices, yields, and ratio of price and yields along with the chosen nutrient value in and found a list of commonly shared items in the list. I used a histogram in order to find the ranges of the prices, yield, ratios, and nutrition value but I think in this case, a 3D plot would be better to show which foods have a lower price, high yield and high nutrition value in order to find the points that fit in those area. Another thing that would be better if I could find a list of foods using an and statement that fit all the criteria where I got a value error when I tried comparing in multiple columns.