How to convert complex JSON object to pandas dataframe for machine learning

Question:

I have some json like this:

{"0": {"name": "Vanilla Cream Ale", "url": "/homebrew/recipe/view/1633/vanilla-cream-ale", "method": "All Grain", "style": "Cream Ale", "batch": 21.8, "og": 1.055, "fg": 1.013, "abv": 5.48, "ibu": 19.44, "color": 4.83, "ph mash": -1, "fermentables": [[2.381, "American - Pale 2-Row", 37.0, 1.8, 44.7], [0.907, "American - White Wheat", 40.0, 2.8, 17.0], [0.907, "American - Pale 6-Row", 35.0, 1.8, 17.0], [0.227, "Flaked Corn", 40.0, 0.5, 4.3], [0.227, "American - Caramel / Crystal 20L", 35.0, 20.0, 4.3], [0.227, "American - Carapils (Dextrine Malt)", 33.0, 1.8, 4.3], [0.113, "Flaked Barley", 32.0, 2.2, 2.1], [0.34, "Honey", 42.0, 2.0, 6.4]], "hops": [[14.0, "Cascade", "Pellet", 6.2, "Boil", "60 min", 11.42, 33.3], [14.0, "Cascade", "Pellet", 6.2, "Boil", "20 min", 6.92, 33.3], [14.0, "saaz", "Pellet", 3.0, "Boil", "5 min", 1.1, 33.3]], "hops Summary": [[28.0, "Cascade (Pellet)", 18.34, 66.6], [14.0, "saaz (Pellet)", 1.1, 33.3]], "other": [["2 oz", "pure vanilla extract", "Flavor", "Boil", "0 min."], ["1 oz", "pure vanilla extract", "Flavor", "Bottling", "0 min."], ["1 tsp", "yeast nutrient", "Other", "Boil", "15 min."], ["1 each", "whirlfloc", "Fining", "Boil", "15 min."], ["4 each", "Vanilla beans - in 2oz Vodka", "Other", "Secondary", "0 min."]], "yeast": ["Wyeast - Ku00f6lsch 2565", "76%", "Low", "56", "70", "Yes"], "rating": 0, "num rating": 16, "views": 289454},
"2": {"name": "Sierra Nevada Pale Ale Clone", "url": "/homebrew/recipe/view/28546/sierra-nevada-pale-ale-clone", "method": "All Grain", "style": "American Pale Ale", "batch": 24.6, "og": 1.055, "fg": 1.013, "abv": 5.58, "ibu": 39.79, "color": 8.0, "ph mash": 5.67, "fermentables": [[5.216, "American - Pale 2-Row", 37.0, 1.8, 92.7], [0.412, "American - Caramel / Crystal 60L", 34.0, 60.0, 7.3]], "hops": [[14.0, "Magnum", "Pellet", 15.0, "Boil", "60 min", 22.62, 8.3], [14.0, "Perle", "Pellet", 8.2, "Boil", "30 min", 9.51, 8.3], [28.0, "Cascade", "Pellet", 7.0, "Boil", "10 min", 7.66, 16.7], [56.0, "Cascade", "Pellet", 7.0, "Boil", "0 min", 0, 33.3], [56.0, "Cascade", "Pellet", 7.0, "Dry Hop", "4 days", 0, 33.3]], "hops Summary": [[14.0, "Magnum (Pellet)", 22.62, 8.3], [14.0, "Perle (Pellet)", 9.51, 8.3], [140.0, "Cascade (Pellet)", 7.66, 83.3]], "other": [["1 each", "Crush whilrfoc Tablet", "Water Agt", "Boil", "10 min."]], "yeast": ["Fermentis - Safale - American Ale Yeast US-05", "76%", "Medium", "54", "77", "Yes"], "rating": 0, "num rating": 26, "views": 271945},
"3": {"name": "Zombie Dust Clone - ALL GRAIN", "url": "/homebrew/recipe/view/5916/zombie-dust-clone-all-grain", "method": "All Grain", "style": "American IPA", "batch": 22.7, "og": 1.061, "fg": 1.016, "abv": 5.94, "ibu": 62.42, "color": 8.5, "ph mash": 5.81, "fermentables": [[5.33, "American - Pale 2-Row", 37.0, 1.8, 81.7], [0.513, "American - Munich - Light 10L", 33.0, 10.0, 7.9], [0.227, "German - CaraFoam", 37.0, 1.8, 3.5], [0.227, "American - Caramel / Crystal 60L", 34.0, 60.0, 3.5], [0.227, "German - Melanoidin", 37.0, 25.0, 3.5]], "hops": [[21.0, "Citra", "Pellet", 11.0, "First Wort", "0 min", 15.57, 8.6], [35.0, "Citra", "Pellet", 11.0, "Boil", "15 min", 21.11, 14.3], [35.0, "Citra", "Pellet", 11.0, "Boil", "10 min", 15.43, 14.3], [35.0, "Citra", "Pellet", 11.0, "Boil", "5 min", 8.48, 14.3], [35.0, "Citra", "Pellet", 11.0, "Boil", "1 min", 1.83, 14.3], [84.0, "Citra", "Pellet", 11.0, "Dry Hop", "7 days", 0, 34.3]], "hops Summary": [[245.0, "Citra (Pellet)", 62.42, 100.1]], "other": [], "yeast": ["Fermentis - Safale - English Ale Yeast S-04", "75%", "High", "54", "77", "Yes"], "rating": 0, "num rating": 10, "views": 208996},
"4": {"name": "Russian River Pliny the Elder (original)", "url": "/homebrew/recipe/view/37534/russian-river-pliny-the-elder-original-", "method": "All Grain", "style": "Imperial IPA", "batch": 22.7, "og": 1.072, "fg": 1.018, "abv": 7.09, "ibu": 232.89, "color": 6.33, "ph mash": -1, "fermentables": [[6.01, "American - Pale 2-Row", 37.0, 1.8, 87.2], [0.272, "American - Caramel / Crystal 40L", 34.0, 40.0, 3.9], [0.272, "American - Carapils (Dextrine Malt)", 33.0, 1.8, 3.9], [0.34, "Corn Sugar - Dextrose ", 46.0, 0.5, 4.9]], "hops": [[98.0, "Columbus", "Pellet", 15.0, "Boil", "90 min", 171.54, 28.0], [21.0, "Columbus", "Pellet", 15.0, "Boil", "45 min", 31.54, 6.0], [28.0, "Simcoe", "Pellet", 12.7, "Boil", "30 min", 29.81, 8.0], [28.0, "Centennial", "Pellet", 10.0, "Aroma", "0 min", 0, 8.0], [70.0, "Simcoe", "Pellet", 12.7, "Aroma", "0 min", 0, 20.0], [28.0, "Columbus", "Pellet", 15.0, "Dry Hop", "13 days", 0, 8.0], [28.0, "Centennial", "Pellet", 10.0, "Dry Hop", "13 days", 0, 8.0], [28.0, "Simcoe", "Pellet", 12.7, "Dry Hop", "13 days", 0, 8.0], [7.0, "Columbus", "Pellet", 15.0, "Dry Hop", "5 days", 0, 2.0], [7.0, "Centennial", "Pellet", 10.0, "Dry Hop", "5 days", 0, 2.0], [7.0, "Simcoe", "Pellet", 12.7, "Dry Hop", "5 days", 0, 2.0]], "hops Summary": [[154.0, "Columbus (Pellet)", 203.08, 44.0], [133.0, "Simcoe (Pellet)", 29.81, 38.0], [63.0, "Centennial (Pellet)", 0.0, 18.0]], "other": [], "yeast": ["Wyeast - American Ale 1056", "75%", "Med-Low", "60", "72", "No"], "rating": 0, "num rating": 6, "views": 193832},
"5": {"name": "Spotted Clown (New Glarus Spotted Cow clone)", "url": "/homebrew/recipe/view/672/spotted-clown-new-glarus-spotted-cow-clone-", "method": "All Grain", "style": "Cream Ale", "batch": 20.8, "og": 1.054, "fg": 1.014, "abv": 5.36, "ibu": 21.27, "color": 5.94, "ph mash": -1, "fermentables": [[2.722, "American - Pale 2-Row", 37.0, 1.8, 50.0], [0.907, "American - Munich - Light 10L", 33.0, 10.0, 16.7], [0.567, "Flaked Corn", 40.0, 0.5, 10.4], [0.794, "Flaked Barley", 32.0, 2.2, 14.6], [0.227, "American - Caramel / Crystal 10L", 35.0, 10.0, 4.2], [0.227, "American - Carapils (Dextrine Malt)", 33.0, 1.8, 4.2]], "hops": [[14.0, "Cascade", "Pellet", 6.7, "Boil", "60 min", 12.67, 33.3], [14.0, "german select", "Pellet", 5.8, "Boil", "20 min", 6.64, 33.3], [14.0, "Willamette", "Pellet", 5.2, "Boil", "5 min", 1.96, 33.3]], "hops Summary": [[14.0, "Cascade (Pellet)", 12.67, 33.3], [14.0, "german select (Pellet)", 6.64, 33.3], [14.0, "Willamette (Pellet)", 1.96, 33.3]], "other": [["1 each", "whirlfloc", "Fining", "Boil", "15 min."], ["1 tsp", "yeast nutrient", "Other", "Boil", "15 min."]], "yeast": ["Wyeast - Ku00f6lsch 2565", "75%", "Low", "56", "70", "Yes"], "rating": 0, "num rating": 5, "views": 190059},
"6": {"name": "Chocolate Vanilla Porter", "url": "/homebrew/recipe/view/29265/chocolate-vanilla-porter", "method": "All Grain", "style": "Robust Porter", "batch": 22.7, "og": 1.06, "fg": 1.016, "abv": 5.77, "ibu": 31.36, "color": 34.76, "ph mash": -1, "fermentables": [[2.268, "American - Pale 2-Row", 37.0, 1.8, 35.6], [1.361, "United Kingdom - Brown", 32.0, 65.0, 21.4], [0.907, "American - Munich - Light 10L", 33.0, 10.0, 14.2], [0.454, "American - Chocolate", 29.0, 350.0, 7.1], [0.454, "American - Caramel / Crystal 10L", 35.0, 10.0, 7.1], [0.454, "Flaked Oats", 33.0, 2.2, 7.1], [0.227, "American - Carapils (Dextrine Malt)", 33.0, 1.8, 3.6], [0.113, "Brown Sugar", 45.0, 15.0, 1.8], [0.136, "Corn Sugar - Dextrose", 46.0, 0.5, 2.1]], "hops": [[28.0, "East Kent Goldings", "Pellet", 5.4, "Boil", "60 min", 18.38, 40.0], [21.0, "East Kent Goldings", "Pellet", 5.4, "Boil", "30 min", 10.59, 30.0], [21.0, "Willamette", "Pellet", 4.7, "Boil", "5 min", 2.39, 30.0]], "hops Summary": [[49.0, "East Kent Goldings (Pellet)", 28.97, 70.0], [21.0, "Willamette (Pellet)", 2.39, 30.0]], "other": [["6 oz", "organic cocoa powder", "Flavor", "Boil", "15 min."], ["1 oz", "pure vanilla extract", "Flavor", "Boil", "0 min."], ["1 tsp", "yeast nutrient", "Other", "Boil", "15 min."], ["2 each", "Vanilla bean", "Flavor", "Secondary", "--"]], "yeast": ["Wyeast - Irish Ale 1084", "73%", "Medium", "62", "72", "Yes"], "rating": 4, "num rating": 1, "views": 188822},
"7": {"name": "Zombie Dust Clone - EXTRACT", "url": "/homebrew/recipe/view/5920/zombie-dust-clone-extract", "method": "Extract", "style": "American IPA", "batch": 18.9, "og": 1.063, "fg": 1.016, "abv": 6.16, "ibu": 70.18, "color": 8.98, "ph mash": 5.41, "fermentables": [[2.722, "Dry Malt Extract - Extra Light", 42.0, 2.5, 70.6]], "hops": [[28.0, "Citra", "Pellet", 11.0, "First Wort", "0 min", 25.02, 12.5], [28.0, "Citra", "Pellet", 11.0, "Boil", "15 min", 20.35, 12.5], [28.0, "Citra", "Pellet", 11.0, "Boil", "10 min", 14.87, 12.5], [28.0, "Citra", "Pellet", 11.0, "Boil", "5 min", 8.18, 12.5], [28.0, "Citra", "Pellet", 11.0, "Boil", "1 min", 1.77, 12.5], [84.0, "Citra", "Pellet", 11.0, "Dry Hop", "7 days", 0, 37.5]], "hops Summary": [[224.0, "Citra (Pellet)", 70.19, 100.0]], "other": [], "yeast": ["Fermentis - Safale - English Ale Yeast S-04", "75%", "High", "54", "77", "Yes"], "rating": 0, "num rating": 9, "views": 184124},
"8": {"name": "Southern Tier Pumking clone", "url": "/homebrew/recipe/view/16367/southern-tier-pumking-clone", "method": "All Grain", "style": "Holiday/Winter Special Spiced Beer", "batch": 20.8, "og": 1.083, "fg": 1.021, "abv": 8.16, "ibu": 50.22, "color": 15.64, "ph mash": -1, "fermentables": [[6.804, "American - Pale 2-Row", 37.0, 1.8, 75.9], [0.907, "American - Victory", 34.0, 28.0, 10.1], [0.34, "American - Caramel / Crystal 80L", 33.0, 80.0, 3.8], [0.907, "pumpkin", 1.75, 13.0, 10.1]], "hops": [[28.0, "Magnum", "Pellet", 15.0, "Boil", "50 min", 41.13, 50.0], [28.0, "Sterling", "Pellet", 8.7, "Boil", "10 min", 9.1, 50.0]], "hops Summary": [[28.0, "Magnum (Pellet)", 41.13, 50.0], [28.0, "Sterling (Pellet)", 9.1, 50.0]], "other": [["0.75 lb", "Demerara sugar", "Flavor", "Boil", "1 hr."], ["0.25 lb", "Light Brown sugar", "Flavor", "Boil", "1 hr."], ["0.75 tsp", "Fresh ground ginger", "Spice", "Boil", "5 min."], ["3 each", "Ceylon cinnamon sticks", "Spice", "Boil", "5 min."], ["0.50 tsp", "Whole cloves", "Spice", "Boil", "5 min."], ["0.50 tsp", "Nutmeg", "Spice", "Boil", "5 min."], ["0.50 tsp", "Allspice", "Spice", "Boil", "5 min."], ["1 each", "Vanilla Bean vodka solution (see notes for exact quantities)", "Spice", "Secondary", "--"], ["1 tsp", "Pumpkin pie spice", "Spice", "Secondary", "--"], ["1 tsp", "Capella water soluble Graham Cracker Extract (purchased online)", "Spice", "Secondary", "--"]], "yeast": ["Wyeast - American Ale 1056", "75%", "Med-Low", "60", "72", "No"], "rating": 0, "num rating": 15, "views": 181369},
"9": {"name": "Bakke Brygg Belgisk Blond 50 L", "url": "/homebrew/recipe/view/89534/bakke-brygg-belgisk-blond-50-l", "method": "All Grain", "style": "Belgian Blond Ale", "batch": 50.0, "og": 1.062, "fg": 1.012, "abv": 6.52, "ibu": 18.54, "color": 4.35, "ph mash": -1, "fermentables": [[11.0, "Castle Malting Pilsen 2RP/2RS", 37.0, 1.8, 88.0], [0.5, "Castle Malting Abbey", 33.0, 17.4, 4.0], [1.0, "Farin, hvit", 46.0, 0.0, 8.0]], "hops": [[64.0, "Hallertau Mittelfruh", "Pellet", 4.0, "Boil", "60 min", 13.36, 56.1], [50.0, "Hallertau Mittelfruh", "Pellet", 4.0, "Boil", "15 min", 5.18, 43.9]], "hops Summary": [[114.0, "Hallertau Mittelfruh (Pellet)", 18.54, 100.0]], "other": [], "yeast": ["Fermentis - Safbrew - Specialty Ale Yeast T-58", "80%", "High", "12", "25", "No"], "rating": 0, "num rating": 5, "views": 172811},
"10": {"name": "Mango Habanero IPA", "url": "/homebrew/recipe/view/61082/mango-habanero-ipa", "method": "All Grain", "style": "Imperial IPA", "batch": 20.8, "og": 1.086, "fg": 1.018, "abv": 8.88, "ibu": 98.09, "color": 8.55, "ph mash": 5.69, "fermentables": [[6.804, "American - Pale 2-Row", 37.0, 1.8, 81.1], [0.907, "American - Caramel / Crystal 20L", 35.0, 20.0, 10.8], [0.454, "Flaked Wheat", 34.0, 2.0, 5.4], [0.227, "Rolled Oats", 33.0, 2.2, 2.7]], "hops": [[35.0, "Magnum", "Pellet", 15.0, "Boil", "60 min", 57.62, 16.7], [28.0, "Centennial", "Pellet", 10.0, "Boil", "30 min", 23.62, 13.3], [35.0, "Centennial", "Pellet", 10.0, "Boil", "10 min", 13.93, 16.7], [28.0, "Citra", "Pellet", 11.1, "Boil", "1 min", 1.47, 13.3], [28.0, "Zythos", "Pellet", 11.0, "Boil", "1 min", 1.46, 13.3], [14.0, "Centennial", "Pellet", 10.0, "Dry Hop", "0 days", 0, 6.7], [28.0, "Citra", "Pellet", 10.0, "Dry Hop", "0 days", 0, 13.3], [14.0, "Zythos", "Pellet", 11.0, "Dry Hop", "0 days", 0, 6.7]], "hops Summary": [[35.0, "Magnum (Pellet)", 57.62, 16.7], [77.0, "Centennial (Pellet)", 37.55, 36.7], [28.0, "Citra (Pellet)", 1.47, 13.3], [42.0, "Zythos (Pellet)", 1.46, 20.0], [28.0, "Citra (Pellet)", 0, 13.3]], "other": [["1 each", "Whirlfloc Tab", "Fining", "Boil", "5 min."], ["44 oz", "Pureed Frozen Mango", "Flavor", "Boil", "5 min."], ["1 each", "Pureed Habanero Pepper", "Flavor", "Boil", "5 min."], ["32 oz", "Organic Mango Juice", "Flavor", "Secondary", "0 min."], ["1 each", "Sliced Habanero Pepper", "Flavor", "Secondary", "0 min."]], "yeast": ["White Labs - California Ale Yeast WLP001", "76.5%", "Medium", "68", "73", "Yes"], "rating": 5, "num rating": 6, "views": 172664}

}

This json represents Beer Recipes, and some of the fiels are nested objects, for example fermentables or hops, can have multiple values like shown in this prettified version
enter image description here

I have code to read and normalize the file:

import json

filename = 'recipes_full copy.json'

with open(filename, 'r') as f:
    try:
        json_data = json.load(f)
        print("The JSON file is valid")
    except ValueError as e:
        print("The JSON file is invalid:", e)

print(json_data)

from pandas import json_normalize
df = json_normalize(json_data) 

However the result is like this:

enter image description here

Question:
How can I flatten this to a full pandas daframe? specially if I dont know how many number of fermentables each recipe is going to have?

Update:

This is my code:

import json

filename = 'recipes_full copy.json'

with open(filename, 'r') as f:
    try:
        json_data = json.load(f)
        print("The JSON file is valid")
    except ValueError as e:
        print("The JSON file is invalid:", e)

print(json_data)

from pandas import json_normalize
df = pd.DataFrame(json_data)           
df = df.T
df['fermentables'] = df['fermentables'].apply(pd.DataFrame)
df['hops'] = df['hops'].apply(pd.DataFrame)
df.at[0, 'hops']

erro:

KeyError                                  Traceback (most recent call last)
Cell In[60], line 7
      5 df['fermentables'] = df['fermentables'].apply(pd.DataFrame)
      6 df['hops'] = df['hops'].apply(pd.DataFrame)
----> 7 df.at[0, 'hops']
...
   3807     #  InvalidIndexError. Otherwise we fall through and re-raise
   3808     #  the TypeError.
   3809     self._check_indexing_error(key)

KeyError: 0
Asked By: Luis Valencia

||

Answers:

The keys of your json are meant as index. Use from_dict with kwarg orient='index':

import pandas as pd 

json_data = {"0": {"name": "Vanilla Cream Ale", "url": "/homebrew/recipe/view/1633/vanilla-cream-ale", "method": "All Grain", "style": "Cream Ale", "batch": 21.8, "og": 1.055, "fg": 1.013, "abv": 5.48, "ibu": 19.44, "color": 4.83, "ph mash": -1, "fermentables": [[2.381, "American - Pale 2-Row", 37.0, 1.8, 44.7], [0.907, "American - White Wheat", 40.0, 2.8, 17.0], [0.907, "American - Pale 6-Row", 35.0, 1.8, 17.0], [0.227, "Flaked Corn", 40.0, 0.5, 4.3], [0.227, "American - Caramel / Crystal 20L", 35.0, 20.0, 4.3], [0.227, "American - Carapils (Dextrine Malt)", 33.0, 1.8, 4.3], [0.113, "Flaked Barley", 32.0, 2.2, 2.1], [0.34, "Honey", 42.0, 2.0, 6.4]], "hops": [[14.0, "Cascade", "Pellet", 6.2, "Boil", "60 min", 11.42, 33.3], [14.0, "Cascade", "Pellet", 6.2, "Boil", "20 min", 6.92, 33.3], [14.0, "saaz", "Pellet", 3.0, "Boil", "5 min", 1.1, 33.3]], "hops Summary": [[28.0, "Cascade (Pellet)", 18.34, 66.6], [14.0, "saaz (Pellet)", 1.1, 33.3]], "other": [["2 oz", "pure vanilla extract", "Flavor", "Boil", "0 min."], ["1 oz", "pure vanilla extract", "Flavor", "Bottling", "0 min."], ["1 tsp", "yeast nutrient", "Other", "Boil", "15 min."], ["1 each", "whirlfloc", "Fining", "Boil", "15 min."], ["4 each", "Vanilla beans - in 2oz Vodka", "Other", "Secondary", "0 min."]], "yeast": ["Wyeast - Ku00f6lsch 2565", "76%", "Low", "56", "70", "Yes"], "rating": 0, "num rating": 16, "views": 289454},
"2": {"name": "Sierra Nevada Pale Ale Clone", "url": "/homebrew/recipe/view/28546/sierra-nevada-pale-ale-clone", "method": "All Grain", "style": "American Pale Ale", "batch": 24.6, "og": 1.055, "fg": 1.013, "abv": 5.58, "ibu": 39.79, "color": 8.0, "ph mash": 5.67, "fermentables": [[5.216, "American - Pale 2-Row", 37.0, 1.8, 92.7], [0.412, "American - Caramel / Crystal 60L", 34.0, 60.0, 7.3]], "hops": [[14.0, "Magnum", "Pellet", 15.0, "Boil", "60 min", 22.62, 8.3], [14.0, "Perle", "Pellet", 8.2, "Boil", "30 min", 9.51, 8.3], [28.0, "Cascade", "Pellet", 7.0, "Boil", "10 min", 7.66, 16.7], [56.0, "Cascade", "Pellet", 7.0, "Boil", "0 min", 0, 33.3], [56.0, "Cascade", "Pellet", 7.0, "Dry Hop", "4 days", 0, 33.3]], "hops Summary": [[14.0, "Magnum (Pellet)", 22.62, 8.3], [14.0, "Perle (Pellet)", 9.51, 8.3], [140.0, "Cascade (Pellet)", 7.66, 83.3]], "other": [["1 each", "Crush whilrfoc Tablet", "Water Agt", "Boil", "10 min."]], "yeast": ["Fermentis - Safale - American Ale Yeast US-05", "76%", "Medium", "54", "77", "Yes"], "rating": 0, "num rating": 26, "views": 271945},
"3": {"name": "Zombie Dust Clone - ALL GRAIN", "url": "/homebrew/recipe/view/5916/zombie-dust-clone-all-grain", "method": "All Grain", "style": "American IPA", "batch": 22.7, "og": 1.061, "fg": 1.016, "abv": 5.94, "ibu": 62.42, "color": 8.5, "ph mash": 5.81, "fermentables": [[5.33, "American - Pale 2-Row", 37.0, 1.8, 81.7], [0.513, "American - Munich - Light 10L", 33.0, 10.0, 7.9], [0.227, "German - CaraFoam", 37.0, 1.8, 3.5], [0.227, "American - Caramel / Crystal 60L", 34.0, 60.0, 3.5], [0.227, "German - Melanoidin", 37.0, 25.0, 3.5]], "hops": [[21.0, "Citra", "Pellet", 11.0, "First Wort", "0 min", 15.57, 8.6], [35.0, "Citra", "Pellet", 11.0, "Boil", "15 min", 21.11, 14.3], [35.0, "Citra", "Pellet", 11.0, "Boil", "10 min", 15.43, 14.3], [35.0, "Citra", "Pellet", 11.0, "Boil", "5 min", 8.48, 14.3], [35.0, "Citra", "Pellet", 11.0, "Boil", "1 min", 1.83, 14.3], [84.0, "Citra", "Pellet", 11.0, "Dry Hop", "7 days", 0, 34.3]], "hops Summary": [[245.0, "Citra (Pellet)", 62.42, 100.1]], "other": [], "yeast": ["Fermentis - Safale - English Ale Yeast S-04", "75%", "High", "54", "77", "Yes"], "rating": 0, "num rating": 10, "views": 208996},
"4": {"name": "Russian River Pliny the Elder (original)", "url": "/homebrew/recipe/view/37534/russian-river-pliny-the-elder-original-", "method": "All Grain", "style": "Imperial IPA", "batch": 22.7, "og": 1.072, "fg": 1.018, "abv": 7.09, "ibu": 232.89, "color": 6.33, "ph mash": -1, "fermentables": [[6.01, "American - Pale 2-Row", 37.0, 1.8, 87.2], [0.272, "American - Caramel / Crystal 40L", 34.0, 40.0, 3.9], [0.272, "American - Carapils (Dextrine Malt)", 33.0, 1.8, 3.9], [0.34, "Corn Sugar - Dextrose ", 46.0, 0.5, 4.9]], "hops": [[98.0, "Columbus", "Pellet", 15.0, "Boil", "90 min", 171.54, 28.0], [21.0, "Columbus", "Pellet", 15.0, "Boil", "45 min", 31.54, 6.0], [28.0, "Simcoe", "Pellet", 12.7, "Boil", "30 min", 29.81, 8.0], [28.0, "Centennial", "Pellet", 10.0, "Aroma", "0 min", 0, 8.0], [70.0, "Simcoe", "Pellet", 12.7, "Aroma", "0 min", 0, 20.0], [28.0, "Columbus", "Pellet", 15.0, "Dry Hop", "13 days", 0, 8.0], [28.0, "Centennial", "Pellet", 10.0, "Dry Hop", "13 days", 0, 8.0], [28.0, "Simcoe", "Pellet", 12.7, "Dry Hop", "13 days", 0, 8.0], [7.0, "Columbus", "Pellet", 15.0, "Dry Hop", "5 days", 0, 2.0], [7.0, "Centennial", "Pellet", 10.0, "Dry Hop", "5 days", 0, 2.0], [7.0, "Simcoe", "Pellet", 12.7, "Dry Hop", "5 days", 0, 2.0]], "hops Summary": [[154.0, "Columbus (Pellet)", 203.08, 44.0], [133.0, "Simcoe (Pellet)", 29.81, 38.0], [63.0, "Centennial (Pellet)", 0.0, 18.0]], "other": [], "yeast": ["Wyeast - American Ale 1056", "75%", "Med-Low", "60", "72", "No"], "rating": 0, "num rating": 6, "views": 193832},
"5": {"name": "Spotted Clown (New Glarus Spotted Cow clone)", "url": "/homebrew/recipe/view/672/spotted-clown-new-glarus-spotted-cow-clone-", "method": "All Grain", "style": "Cream Ale", "batch": 20.8, "og": 1.054, "fg": 1.014, "abv": 5.36, "ibu": 21.27, "color": 5.94, "ph mash": -1, "fermentables": [[2.722, "American - Pale 2-Row", 37.0, 1.8, 50.0], [0.907, "American - Munich - Light 10L", 33.0, 10.0, 16.7], [0.567, "Flaked Corn", 40.0, 0.5, 10.4], [0.794, "Flaked Barley", 32.0, 2.2, 14.6], [0.227, "American - Caramel / Crystal 10L", 35.0, 10.0, 4.2], [0.227, "American - Carapils (Dextrine Malt)", 33.0, 1.8, 4.2]], "hops": [[14.0, "Cascade", "Pellet", 6.7, "Boil", "60 min", 12.67, 33.3], [14.0, "german select", "Pellet", 5.8, "Boil", "20 min", 6.64, 33.3], [14.0, "Willamette", "Pellet", 5.2, "Boil", "5 min", 1.96, 33.3]], "hops Summary": [[14.0, "Cascade (Pellet)", 12.67, 33.3], [14.0, "german select (Pellet)", 6.64, 33.3], [14.0, "Willamette (Pellet)", 1.96, 33.3]], "other": [["1 each", "whirlfloc", "Fining", "Boil", "15 min."], ["1 tsp", "yeast nutrient", "Other", "Boil", "15 min."]], "yeast": ["Wyeast - Ku00f6lsch 2565", "75%", "Low", "56", "70", "Yes"], "rating": 0, "num rating": 5, "views": 190059},
"6": {"name": "Chocolate Vanilla Porter", "url": "/homebrew/recipe/view/29265/chocolate-vanilla-porter", "method": "All Grain", "style": "Robust Porter", "batch": 22.7, "og": 1.06, "fg": 1.016, "abv": 5.77, "ibu": 31.36, "color": 34.76, "ph mash": -1, "fermentables": [[2.268, "American - Pale 2-Row", 37.0, 1.8, 35.6], [1.361, "United Kingdom - Brown", 32.0, 65.0, 21.4], [0.907, "American - Munich - Light 10L", 33.0, 10.0, 14.2], [0.454, "American - Chocolate", 29.0, 350.0, 7.1], [0.454, "American - Caramel / Crystal 10L", 35.0, 10.0, 7.1], [0.454, "Flaked Oats", 33.0, 2.2, 7.1], [0.227, "American - Carapils (Dextrine Malt)", 33.0, 1.8, 3.6], [0.113, "Brown Sugar", 45.0, 15.0, 1.8], [0.136, "Corn Sugar - Dextrose", 46.0, 0.5, 2.1]], "hops": [[28.0, "East Kent Goldings", "Pellet", 5.4, "Boil", "60 min", 18.38, 40.0], [21.0, "East Kent Goldings", "Pellet", 5.4, "Boil", "30 min", 10.59, 30.0], [21.0, "Willamette", "Pellet", 4.7, "Boil", "5 min", 2.39, 30.0]], "hops Summary": [[49.0, "East Kent Goldings (Pellet)", 28.97, 70.0], [21.0, "Willamette (Pellet)", 2.39, 30.0]], "other": [["6 oz", "organic cocoa powder", "Flavor", "Boil", "15 min."], ["1 oz", "pure vanilla extract", "Flavor", "Boil", "0 min."], ["1 tsp", "yeast nutrient", "Other", "Boil", "15 min."], ["2 each", "Vanilla bean", "Flavor", "Secondary", "--"]], "yeast": ["Wyeast - Irish Ale 1084", "73%", "Medium", "62", "72", "Yes"], "rating": 4, "num rating": 1, "views": 188822},
"7": {"name": "Zombie Dust Clone - EXTRACT", "url": "/homebrew/recipe/view/5920/zombie-dust-clone-extract", "method": "Extract", "style": "American IPA", "batch": 18.9, "og": 1.063, "fg": 1.016, "abv": 6.16, "ibu": 70.18, "color": 8.98, "ph mash": 5.41, "fermentables": [[2.722, "Dry Malt Extract - Extra Light", 42.0, 2.5, 70.6]], "hops": [[28.0, "Citra", "Pellet", 11.0, "First Wort", "0 min", 25.02, 12.5], [28.0, "Citra", "Pellet", 11.0, "Boil", "15 min", 20.35, 12.5], [28.0, "Citra", "Pellet", 11.0, "Boil", "10 min", 14.87, 12.5], [28.0, "Citra", "Pellet", 11.0, "Boil", "5 min", 8.18, 12.5], [28.0, "Citra", "Pellet", 11.0, "Boil", "1 min", 1.77, 12.5], [84.0, "Citra", "Pellet", 11.0, "Dry Hop", "7 days", 0, 37.5]], "hops Summary": [[224.0, "Citra (Pellet)", 70.19, 100.0]], "other": [], "yeast": ["Fermentis - Safale - English Ale Yeast S-04", "75%", "High", "54", "77", "Yes"], "rating": 0, "num rating": 9, "views": 184124},
"8": {"name": "Southern Tier Pumking clone", "url": "/homebrew/recipe/view/16367/southern-tier-pumking-clone", "method": "All Grain", "style": "Holiday/Winter Special Spiced Beer", "batch": 20.8, "og": 1.083, "fg": 1.021, "abv": 8.16, "ibu": 50.22, "color": 15.64, "ph mash": -1, "fermentables": [[6.804, "American - Pale 2-Row", 37.0, 1.8, 75.9], [0.907, "American - Victory", 34.0, 28.0, 10.1], [0.34, "American - Caramel / Crystal 80L", 33.0, 80.0, 3.8], [0.907, "pumpkin", 1.75, 13.0, 10.1]], "hops": [[28.0, "Magnum", "Pellet", 15.0, "Boil", "50 min", 41.13, 50.0], [28.0, "Sterling", "Pellet", 8.7, "Boil", "10 min", 9.1, 50.0]], "hops Summary": [[28.0, "Magnum (Pellet)", 41.13, 50.0], [28.0, "Sterling (Pellet)", 9.1, 50.0]], "other": [["0.75 lb", "Demerara sugar", "Flavor", "Boil", "1 hr."], ["0.25 lb", "Light Brown sugar", "Flavor", "Boil", "1 hr."], ["0.75 tsp", "Fresh ground ginger", "Spice", "Boil", "5 min."], ["3 each", "Ceylon cinnamon sticks", "Spice", "Boil", "5 min."], ["0.50 tsp", "Whole cloves", "Spice", "Boil", "5 min."], ["0.50 tsp", "Nutmeg", "Spice", "Boil", "5 min."], ["0.50 tsp", "Allspice", "Spice", "Boil", "5 min."], ["1 each", "Vanilla Bean vodka solution (see notes for exact quantities)", "Spice", "Secondary", "--"], ["1 tsp", "Pumpkin pie spice", "Spice", "Secondary", "--"], ["1 tsp", "Capella water soluble Graham Cracker Extract (purchased online)", "Spice", "Secondary", "--"]], "yeast": ["Wyeast - American Ale 1056", "75%", "Med-Low", "60", "72", "No"], "rating": 0, "num rating": 15, "views": 181369},
"9": {"name": "Bakke Brygg Belgisk Blond 50 L", "url": "/homebrew/recipe/view/89534/bakke-brygg-belgisk-blond-50-l", "method": "All Grain", "style": "Belgian Blond Ale", "batch": 50.0, "og": 1.062, "fg": 1.012, "abv": 6.52, "ibu": 18.54, "color": 4.35, "ph mash": -1, "fermentables": [[11.0, "Castle Malting Pilsen 2RP/2RS", 37.0, 1.8, 88.0], [0.5, "Castle Malting Abbey", 33.0, 17.4, 4.0], [1.0, "Farin, hvit", 46.0, 0.0, 8.0]], "hops": [[64.0, "Hallertau Mittelfruh", "Pellet", 4.0, "Boil", "60 min", 13.36, 56.1], [50.0, "Hallertau Mittelfruh", "Pellet", 4.0, "Boil", "15 min", 5.18, 43.9]], "hops Summary": [[114.0, "Hallertau Mittelfruh (Pellet)", 18.54, 100.0]], "other": [], "yeast": ["Fermentis - Safbrew - Specialty Ale Yeast T-58", "80%", "High", "12", "25", "No"], "rating": 0, "num rating": 5, "views": 172811},
"10": {"name": "Mango Habanero IPA", "url": "/homebrew/recipe/view/61082/mango-habanero-ipa", "method": "All Grain", "style": "Imperial IPA", "batch": 20.8, "og": 1.086, "fg": 1.018, "abv": 8.88, "ibu": 98.09, "color": 8.55, "ph mash": 5.69, "fermentables": [[6.804, "American - Pale 2-Row", 37.0, 1.8, 81.1], [0.907, "American - Caramel / Crystal 20L", 35.0, 20.0, 10.8], [0.454, "Flaked Wheat", 34.0, 2.0, 5.4], [0.227, "Rolled Oats", 33.0, 2.2, 2.7]], "hops": [[35.0, "Magnum", "Pellet", 15.0, "Boil", "60 min", 57.62, 16.7], [28.0, "Centennial", "Pellet", 10.0, "Boil", "30 min", 23.62, 13.3], [35.0, "Centennial", "Pellet", 10.0, "Boil", "10 min", 13.93, 16.7], [28.0, "Citra", "Pellet", 11.1, "Boil", "1 min", 1.47, 13.3], [28.0, "Zythos", "Pellet", 11.0, "Boil", "1 min", 1.46, 13.3], [14.0, "Centennial", "Pellet", 10.0, "Dry Hop", "0 days", 0, 6.7], [28.0, "Citra", "Pellet", 10.0, "Dry Hop", "0 days", 0, 13.3], [14.0, "Zythos", "Pellet", 11.0, "Dry Hop", "0 days", 0, 6.7]], "hops Summary": [[35.0, "Magnum (Pellet)", 57.62, 16.7], [77.0, "Centennial (Pellet)", 37.55, 36.7], [28.0, "Citra (Pellet)", 1.47, 13.3], [42.0, "Zythos (Pellet)", 1.46, 20.0], [28.0, "Citra (Pellet)", 0, 13.3]], "other": [["1 each", "Whirlfloc Tab", "Fining", "Boil", "5 min."], ["44 oz", "Pureed Frozen Mango", "Flavor", "Boil", "5 min."], ["1 each", "Pureed Habanero Pepper", "Flavor", "Boil", "5 min."], ["32 oz", "Organic Mango Juice", "Flavor", "Secondary", "0 min."], ["1 each", "Sliced Habanero Pepper", "Flavor", "Secondary", "0 min."]], "yeast": ["White Labs - California Ale Yeast WLP001", "76.5%", "Medium", "68", "73", "Yes"], "rating": 5, "num rating": 6, "views": 172664}
}

df = pd.DataFrame.from_dict(json_data, orient='index')

Output:

                                           name                                                url  ... num rating   views
0                             Vanilla Cream Ale       /homebrew/recipe/view/1633/vanilla-cream-ale  ...         16  289454
1                  Sierra Nevada Pale Ale Clone  /homebrew/recipe/view/28546/sierra-nevada-pale...  ...         26  271945
2                 Zombie Dust Clone - ALL GRAIN  /homebrew/recipe/view/5916/zombie-dust-clone-a...  ...         10  208996
3      Russian River Pliny the Elder (original)  /homebrew/recipe/view/37534/russian-river-plin...  ...          6  193832
4  Spotted Clown (New Glarus Spotted Cow clone)  /homebrew/recipe/view/672/spotted-clown-new-gl...  ...          5  190059
5                      Chocolate Vanilla Porter  /homebrew/recipe/view/29265/chocolate-vanilla-...  ...          1  188822
6                   Zombie Dust Clone - EXTRACT  /homebrew/recipe/view/5920/zombie-dust-clone-e...  ...          9  184124
7                   Southern Tier Pumking clone  /homebrew/recipe/view/16367/southern-tier-pumk...  ...         15  181369
8                Bakke Brygg Belgisk Blond 50 L  /homebrew/recipe/view/89534/bakke-brygg-belgis...  ...          5  172811
9                            Mango Habanero IPA     /homebrew/recipe/view/61082/mango-habanero-ipa  ...          6  172664

Edit: you can make dataframes from the lists like fermentables and hops with apply:

df['fermentables'] = df['fermentables'].apply(pd.DataFrame)
df['hops'] = df['hops'].apply(pd.DataFrame)

You can then access these dataframes from df index:

df.at['0', 'hops']

Output:

      0        1       2    3     4       5      6     7
0  14.0  Cascade  Pellet  6.2  Boil  60 min  11.42  33.3
1  14.0  Cascade  Pellet  6.2  Boil  20 min   6.92  33.3
2  14.0     saaz  Pellet  3.0  Boil   5 min   1.10  33.3
Answered By: Tranbi
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.