In [61]:
import pandas as pd
import re
import json

def ingredient_clean(ingredient_string):
    regex = re.compile(r'½|⅓|¼|\(|\)|(\d-\d) |\d|,|\/|(oz)|(cup)|(teaspoons)|(teaspoon)|(tablespoons)|(tablespoon)|(whole)|(chopped)|( and )|(ground)|( or )|(ounce)|(weight)|( to )|( can )|( of )|(tbsp)', re.I)
    ingredient_string = regex.sub('', ingredient_string)
    return ingredient_string.replace('\n',' ').lower()

In [62]:
cleaner = []
with open('recipe_db.json') as data_file:
    raw_file = data_file.readlines()
    count = 1
    for x in raw_file:
        fixed = re.sub(r'( { "\$oid" : "(.*?)(" }))', str(count), x)
        fixed = re.sub(r'("ts" : { "\$date" : (\d{1,}))( }, )', '', fixed)
        count += 1
        cleaner.append(json.loads(fixed))
raw_recipes = pd.DataFrame(cleaner)
recipe_ing_list = set(raw_recipes['ingredients'])
recipe_ing_list = set([ingredient_clean(ing) for ing in recipe_ing_list])
recipe_ing_str = ' '.join(recipe_ing_list)

In [63]:
fc_indr_raw = pd.read_csv('master_fc_ing.csv')
ingredient_list = set(fc_indr_raw['ingredient name'])

In [ ]:
count_dict = {ingredient:recipe_ing_str.count(ingredient) 
              for ingredient in ingredient_list}
count_dict

In [72]:
total = sum(count_dict.values())

In [89]:
ratio_dict = {}
for ingredient, value in count_dict.items():
    value = value * 10
    ratio = round(1-((value/total)),2)
    ratio_dict[ingredient] = ratio

In [90]:
sorted(ratio_dict.items(), key=lambda x: x[1])


Out[90]:
[('pepper', 0.5),
 ('butter', 0.59),
 ('clove', 0.64),
 ('egg', 0.67),
 ('onion', 0.69),
 ('garlic', 0.71),
 ('olive', 0.72),
 ('olive oil', 0.74),
 ('cheese', 0.76),
 ('cream', 0.77),
 ('nut', 0.79),
 ('milk', 0.79),
 ('black pepper', 0.81),
 ('lemon', 0.81),
 ('eel', 0.82),
 ('tomato', 0.83),
 ('chicken', 0.83),
 ('vanilla', 0.84),
 ('seed', 0.85),
 ('gin', 0.86),
 ('vegetable', 0.87),
 ('corn', 0.89),
 ('vinegar', 0.89),
 ('pea', 0.9),
 ('rum', 0.91),
 ('vegetable oil', 0.91),
 ('bread', 0.91),
 ('wine', 0.91),
 ('cinnamon', 0.91),
 ('potato', 0.92),
 ('parsley', 0.92),
 ('lemon juice', 0.92),
 ('apple', 0.92),
 ('rice', 0.93),
 ('lime', 0.93),
 ('beef', 0.93),
 ('carrot', 0.93),
 ('bean', 0.93),
 ('orange', 0.93),
 ('ginger', 0.93),
 ('mustard', 0.94),
 ('honey', 0.94),
 ('thyme', 0.94),
 ('mushroom', 0.94),
 ('almond', 0.95),
 ('white wine', 0.95),
 ('celery', 0.95),
 ('coconut', 0.95),
 ('parmesan', 0.95),
 ('basil', 0.95),
 ('leaf', 0.95),
 ('cumin', 0.95),
 ('bell pepper', 0.95),
 ('nutmeg', 0.96),
 ('cream cheese', 0.96),
 ('raisin', 0.96),
 ('oat', 0.96),
 ('pork', 0.96),
 ('shallot', 0.96),
 ('cilantro', 0.96),
 ('bacon', 0.96),
 ('sage', 0.96),
 ('soy sauce', 0.96),
 ('parmesan cheese', 0.96),
 ('walnut', 0.96),
 ('cheddar cheese', 0.96),
 ('coriander', 0.96),
 ('mint', 0.96),
 ('rosemary', 0.97),
 ('yogurt', 0.97),
 ('wheat', 0.97),
 ('bay', 0.97),
 ('rose', 0.97),
 ('lime juice', 0.97),
 ('tea', 0.97),
 ('pecan', 0.97),
 ('chicken broth', 0.97),
 ('ham', 0.97),
 ('oregano', 0.97),
 ('smoke', 0.97),
 ('cocoa', 0.97),
 ('cayenne', 0.97),
 ('starch', 0.97),
 ('red wine', 0.97),
 ('flower', 0.97),
 ('peanut', 0.97),
 ('cherry', 0.98),
 ('broccoli', 0.98),
 ('meat', 0.98),
 ('root', 0.98),
 ('grape', 0.98),
 ('dill', 0.98),
 ('green bell pepper', 0.98),
 ('pineapple', 0.98),
 ('plum', 0.98),
 ('shrimp', 0.98),
 ('salmon', 0.98),
 ('fennel', 0.98),
 ('cider', 0.98),
 ('squash', 0.98),
 ('yeast', 0.98),
 ('lamb', 0.98),
 ('fruit', 0.98),
 ('turkey', 0.98),
 ('berry', 0.98),
 ('fish', 0.98),
 ('chive', 0.98),
 ('banana', 0.98),
 ('cucumber', 0.98),
 ('zucchini', 0.98),
 ('avocado', 0.98),
 ('pumpkin', 0.98),
 ('sesame oil', 0.98),
 ('grain', 0.98),
 ('cabbage', 0.98),
 ('pear', 0.98),
 ('lettuce', 0.98),
 ('buttermilk', 0.98),
 ('orange juice', 0.98),
 ('peanut butter', 0.98),
 ('egg noodle', 0.99),
 ('sweet potato', 0.99),
 ('leek', 0.99),
 ('strawberry', 0.99),
 ('gelatin', 0.99),
 ('rapeseed', 0.99),
 ('macaroni', 0.99),
 ('raspberry', 0.99),
 ('tuna', 0.99),
 ('apricot', 0.99),
 ('cereal', 0.99),
 ('beet', 0.99),
 ('cardamom', 0.99),
 ('sherry', 0.99),
 ('date', 0.99),
 ('coconut oil', 0.99),
 ('sunflower oil', 0.99),
 ('asparagus', 0.99),
 ('watercress', 0.99),
 ('white bread', 0.99),
 ('cranberry', 0.99),
 ('plant', 0.99),
 ('goat cheese', 0.99),
 ('ewe', 0.99),
 ('peach', 0.99),
 ('oyster', 0.99),
 ('pork sausage', 0.99),
 ('lentil', 0.99),
 ('coffee', 0.99),
 ('beef broth', 0.99),
 ('prawn', 0.99),
 ('sesame seed', 0.99),
 ('currant', 0.99),
 ('dried parsley', 0.99),
 ('kale', 0.99),
 ('hop', 0.99),
 ('black bean', 0.99),
 ('rhubarb', 0.99),
 ('hazelnut', 0.99),
 ('blue cheese', 0.99),
 ('anise', 0.99),
 ('cashew', 0.99),
 ('star anise', 0.99),
 ('wood', 0.99),
 ('brown rice', 0.99),
 ('maple syrup', 0.99),
 ('seed oil', 0.99),
 ('scallion', 0.99),
 ('artichoke', 0.99),
 ('swiss cheese', 0.99),
 ('radish', 0.99),
 ('pistachio', 0.99),
 ('corn tortilla', 0.99),
 ('beer', 0.99),
 ('saffron', 0.99),
 ('mango', 0.99),
 ('apple juice', 0.99),
 ('lard', 0.99),
 ('cauliflower', 0.99),
 ('horseradish', 0.99),
 ('turmeric', 0.99),
 ('crab', 0.99),
 ('liver', 0.99),
 ('chickpea', 0.99),
 ('brandy', 0.99),
 ('tarragon', 0.99),
 ('feta cheese', 0.99),
 ('kidney bean', 0.99),
 ('litchi', 1.0),
 ('corn salad', 1.0),
 ('cabernet sauvignon grape', 1.0),
 ('saigon cinnamon', 1.0),
 ('satsuma', 1.0),
 ('sour cherry', 1.0),
 ('corn oil', 1.0),
 ('balm', 1.0),
 ('salmon roe', 1.0),
 ('mexican lime', 1.0),
 ('marula', 1.0),
 ('lovage', 1.0),
 ('corn flake', 1.0),
 ('caraway', 1.0),
 ('sapodilla', 1.0),
 ('cuttlefish', 1.0),
 ('garlic mustard', 1.0),
 ('french bean', 1.0),
 ('porcini', 1.0),
 ('cabbage juice', 1.0),
 ('sour milk', 1.0),
 ('roasted pecan', 1.0),
 ('sake', 1.0),
 ('cassia', 1.0),
 ('spike', 1.0),
 ('mandarin', 1.0),
 ('fish oil', 1.0),
 ('condiment', 1.0),
 ('anise seed', 1.0),
 ('raw chicken', 1.0),
 ('raw pea', 1.0),
 ('port wine', 1.0),
 ('tangerine', 1.0),
 ('nutmeg oil', 1.0),
 ('angelica', 1.0),
 ('smoked herring', 1.0),
 ('wild berry', 1.0),
 ('mussel', 1.0),
 ('lavender', 1.0),
 ('fruit juice', 1.0),
 ('okra', 1.0),
 ('hogweed', 1.0),
 ('cassava', 1.0),
 ('rosemary oil', 1.0),
 ('provolone cheese', 1.0),
 ('palm', 1.0),
 ('pike', 1.0),
 ('hyssop', 1.0),
 ('oak leaf', 1.0),
 ('curcuma', 1.0),
 ('split pea', 1.0),
 ('sturgeon caviar', 1.0),
 ('whale', 1.0),
 ('endive', 1.0),
 ('potato chip', 1.0),
 ('red kidney bean', 1.0),
 ('mutton', 1.0),
 ('smoked sausage', 1.0),
 ('prune', 1.0),
 ('wild rice', 1.0),
 ('octopus', 1.0),
 ('scallop', 1.0),
 ('lilac', 1.0),
 ('clam', 1.0),
 ('wild strawberry', 1.0),
 ('orchid', 1.0),
 ('sauvignon grape', 1.0),
 ('vanilla oil', 1.0),
 ('quince', 1.0),
 ('galanga', 1.0),
 ('grapefruit juice', 1.0),
 ('bergamot', 1.0),
 ('celery root', 1.0),
 ('cottage cheese', 1.0),
 ('fenugreek', 1.0),
 ('wheat flake', 1.0),
 ('blackberry', 1.0),
 ('celery seed', 1.0),
 ('squid', 1.0),
 ('starfruit', 1.0),
 ('sherry wine', 1.0),
 ('roasted shrimp', 1.0),
 ('herring', 1.0),
 ('lemongrass', 1.0),
 ('citrus oil', 1.0),
 ('coriander oil', 1.0),
 ('sea bass', 1.0),
 ('kaffir lime', 1.0),
 ('katsuobushi', 1.0),
 ('arrack', 1.0),
 ('juniper berry', 1.0),
 ('raw pork', 1.0),
 ('roasted onion', 1.0),
 ('gruyere cheese', 1.0),
 ('blackberry brandy', 1.0),
 ('bay laurel', 1.0),
 ('capsicum', 1.0),
 ('sheep milk', 1.0),
 ('raw radish', 1.0),
 ('roasted barley', 1.0),
 ('camembert cheese', 1.0),
 ('strawberry jam', 1.0),
 ('savory', 1.0),
 ('cognac', 1.0),
 ('ribes', 1.0),
 ('beef liver', 1.0),
 ('butter oil', 1.0),
 ('loquat', 1.0),
 ('buckwheat', 1.0),
 ('raw beef', 1.0),
 ('tabasco pepper', 1.0),
 ('cape gooseberry', 1.0),
 ('valencia orange juice', 1.0),
 ('california pepper', 1.0),
 ('carob', 1.0),
 ('cod', 1.0),
 ('red bean', 1.0),
 ('muscat grape', 1.0),
 ('jackfruit', 1.0),
 ('cantaloupe', 1.0),
 ('dairy', 1.0),
 ('carnation', 1.0),
 ('grapefruit peel', 1.0),
 ('lemon peel', 1.0),
 ('passion fruit', 1.0),
 ('apricot kernel', 1.0),
 ('raw peanut', 1.0),
 ('sparkling wine', 1.0),
 ('laurel', 1.0),
 ('whiskey', 1.0),
 ('tomato juice', 1.0),
 ('wort', 1.0),
 ('durian', 1.0),
 ('roasted peanut', 1.0),
 ('black currant', 1.0),
 ('pimenta', 1.0),
 ('kelp', 1.0),
 ('toasted sesame seed', 1.0),
 ('sumac', 1.0),
 ('pimento', 1.0),
 ('wheat bread', 1.0),
 ('betel', 1.0),
 ('pine oil', 1.0),
 ('udo', 1.0),
 ('malt', 1.0),
 ('skim milk', 1.0),
 ('cinnamon oil', 1.0),
 ('blueberry', 1.0),
 ('mate', 1.0),
 ('roasted coconut', 1.0),
 ('dolphin', 1.0),
 ('roasted almond', 1.0),
 ('mashed potato', 1.0),
 ('cured ham', 1.0),
 ('beet root', 1.0),
 ('roasted macadamia nut', 1.0),
 ('roasted pork', 1.0),
 ('grapefruit', 1.0),
 ('pear brandy', 1.0),
 ('dried spinach', 1.0),
 ('animal', 1.0),
 ('thai pepper', 1.0),
 ('lemon balm', 1.0),
 ('chayote', 1.0),
 ('citron', 1.0),
 ('piri piri', 1.0),
 ('smoked pork belly', 1.0),
 ('bitter almond', 1.0),
 ('parsnip', 1.0),
 ('jamaican rum', 1.0),
 ('jerusalem artichoke', 1.0),
 ('roasted beef', 1.0),
 ('truffle', 1.0),
 ('boiled chicken', 1.0),
 ('butterfat', 1.0),
 ('caraway seed', 1.0),
 ('citrus juice', 1.0),
 ('comte cheese', 1.0),
 ('chicken liver', 1.0),
 ('concord grape', 1.0),
 ('sauerkraut', 1.0),
 ('strawberry juice', 1.0),
 ('roquefort cheese', 1.0),
 ('frankfurter', 1.0),
 ('kumquat', 1.0),
 ('veal', 1.0),
 ('fermented shrimp', 1.0),
 ('peppermint oil', 1.0),
 ('lime oil', 1.0),
 ('guarana', 1.0),
 ('ginger oil', 1.0),
 ('roasted chicken', 1.0),
 ('long pepper', 1.0),
 ('filbert', 1.0),
 ('romano cheese', 1.0),
 ('caviar', 1.0),
 ('myrtle', 1.0),
 ('dried kidney bean', 1.0),
 ('shellfish', 1.0),
 ('cooked apple', 1.0),
 ('neroli oil', 1.0),
 ('watermelon', 1.0),
 ('echinacea', 1.0),
 ('pennyroyal', 1.0),
 ('smoked salmon', 1.0),
 ('bael', 1.0),
 ('birch', 1.0),
 ('ceylon cinnamon', 1.0),
 ('florida orange juice', 1.0),
 ('camphor', 1.0),
 ('cabernet sauvignon wine', 1.0),
 ('shiitake', 1.0),
 ('tuber', 1.0),
 ('rye flour', 1.0),
 ('mace', 1.0),
 ('munster cheese', 1.0),
 ('popcorn', 1.0),
 ('chamomile', 1.0),
 ('acacia', 1.0),
 ('red sage', 1.0),
 ('seaweed', 1.0),
 ('keta salmon', 1.0),
 ('bourbon whiskey', 1.0),
 ('lingonberry', 1.0),
 ('chinese cabbage', 1.0),
 ('barley', 1.0),
 ('kiwi', 1.0),
 ('salmon caviar', 1.0),
 ('scotch', 1.0),
 ('corn grit', 1.0),
 ('catfish', 1.0),
 ('fried pork', 1.0),
 ('violet', 1.0),
 ('guineafowl', 1.0),
 ('sweet basil', 1.0),
 ('wheat bran', 1.0),
 ('clove oil', 1.0),
 ('brussels sprout', 1.0),
 ('cherry juice', 1.0),
 ('ceylon tea', 1.0),
 ('haddock', 1.0),
 ('citrus peel', 1.0),
 ('black raspberry', 1.0),
 ('rose hip', 1.0),
 ('holy basil', 1.0),
 ('armagnac', 1.0),
 ('maize', 1.0),
 ('wasabi', 1.0),
 ('black sesame seed', 1.0),
 ('grilled pork', 1.0),
 ('rue', 1.0),
 ('rutabaga', 1.0),
 ('kohlrabi', 1.0),
 ('lemon oil', 1.0),
 ('fig', 1.0),
 ('milk fat', 1.0),
 ('cypress', 1.0),
 ('roasted meat', 1.0),
 ('roasted spanish peanut', 1.0),
 ('malt whiskey', 1.0),
 ('lingonberry juice', 1.0),
 ('tamarind', 1.0),
 ('lean fish', 1.0),
 ('fried chicken', 1.0),
 ('bartlett pear', 1.0),
 ('winter savory', 1.0),
 ('irish whiskey', 1.0),
 ('baked potato', 1.0),
 ('orange flower', 1.0),
 ('oatmeal', 1.0),
 ('mandarin peel', 1.0),
 ('dried fig', 1.0),
 ('scotch whiskey', 1.0),
 ('orange oil', 1.0),
 ('mackerel', 1.0),
 ('prickly pear', 1.0),
 ('oregano oil', 1.0),
 ('cubeb', 1.0),
 ('orange peel', 1.0),
 ('water apple', 1.0),
 ('french lavender', 1.0),
 ('lobster', 1.0),
 ('roasted turkey', 1.0),
 ('basil oil', 1.0),
 ('chicory', 1.0),
 ('melon', 1.0),
 ('roasted sesame seed', 1.0),
 ('raspberry brandy', 1.0),
 ('nettle', 1.0),
 ('summer savory', 1.0),
 ('passion fruit juice', 1.0),
 ('lemongrass oil', 1.0),
 ('goat milk', 1.0),
 ('seal', 1.0),
 ('plum wine', 1.0),
 ('chinese cinnamon', 1.0),
 ('papaya', 1.0),
 ('macadamia nut', 1.0),
 ('tangerine juice', 1.0),
 ('rye bread', 1.0),
 ('guava', 1.0),
 ('mangosteen', 1.0),
 ('navy bean', 1.0),
 ('cacao', 1.0),
 ('bitter orange', 1.0),
 ('jasmine tea', 1.0),
 ('pinto bean', 1.0),
 ('french fried potato', 1.0),
 ('brazil nut', 1.0),
 ('anise hyssop', 1.0),
 ('yam', 1.0),
 ('grapefruit oil', 1.0),
 ('onion juice', 1.0),
 ('beech', 1.0),
 ('winter melon', 1.0),
 ('grape vine', 1.0),
 ('tulip', 1.0),
 ('spearmint', 1.0),
 ('garlic oil', 1.0),
 ('rum brandy', 1.0),
 ('pork liver', 1.0),
 ('roasted hazelnut', 1.0),
 ('beet juice', 1.0),
 ('green tea', 1.0),
 ('blackberry juice', 1.0),
 ('snap bean', 1.0),
 ('jasmine', 1.0),
 ('rose wine', 1.0),
 ('huckleberry', 1.0),
 ('chervil', 1.0),
 ('rice bran', 1.0),
 ('licorice', 1.0),
 ('raspberry juice', 1.0),
 ('sassafras', 1.0),
 ('smoked pork', 1.0),
 ('raw potato', 1.0),
 ('cumin oil', 1.0),
 ('honeydew', 1.0),
 ('mint oil', 1.0),
 ('musk', 1.0),
 ('marjoram', 1.0),
 ('apple brandy', 1.0),
 ('soybean oil', 1.0),
 ('black tea', 1.0),
 ('smoked fish', 1.0),
 ('emmental cheese', 1.0),
 ('soybean', 1.0),
 ('raw asparagus', 1.0),
 ('boiled crab', 1.0),
 ('mentha', 1.0),
 ('elderberry', 1.0),
 ('cherimoya', 1.0),
 ('apple sauce', 1.0),
 ('lima bean', 1.0),
 ('red meat', 1.0),
 ('nira', 1.0),
 ('brewed tea', 1.0),
 ('ouzo', 1.0),
 ('cured pork', 1.0),
 ('berry juice', 1.0),
 ('peppermint', 1.0),
 ('sugarcane', 1.0),
 ('cherry brandy', 1.0),
 ('mung bean', 1.0),
 ('boiled beef', 1.0),
 ('grape juice', 1.0),
 ('roselle', 1.0),
 ('orris', 1.0),
 ('geranium', 1.0),
 ('pilchard', 1.0),
 ('citrus', 1.0),
 ('peanut oil', 1.0),
 ('turnip', 1.0),
 ('oat groat', 1.0),
 ('whitefish', 1.0),
 ('toasted oat', 1.0),
 ('eucalyptus', 1.0),
 ('dill seed', 1.0),
 ('laurel leaf', 1.0),
 ('roasted nut', 1.0),
 ('tequila', 1.0),
 ('palm oil', 1.0),
 ('neroli', 1.0),
 ('nectarine', 1.0),
 ('crayfish', 1.0),
 ('red currant', 1.0)]

In [ ]: