-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecipies.py
More file actions
25 lines (20 loc) · 734 Bytes
/
Copy pathrecipies.py
File metadata and controls
25 lines (20 loc) · 734 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import numpy as np
import pandas as pd
import re
# read the entire file into a Python array
with open("recipies/recipeitems-latest.json", "r") as f:
# Extract each line
data = (line.strip() for line in f)
# Reformat so each line is the element of a list
data_json = "[{0}]".format(','.join(data))
# read the result as a JSON
recipes = pd.read_json(data_json)
spice_list = ['salt', 'pepper', 'oregano', 'sage', 'parsley',
'rosemary', 'tarragon', 'thyme', 'paprika', 'cumin']
spice_df = pd.DataFrame(
dict((spice, recipes.ingredients.str.contains(spice, re.IGNORECASE)) for spice in spice_list)
)
# make a query
selection = spice_df.query("parsley & paprika & tarragon")
print(len(selection))
print(selection.head())