-
Notifications
You must be signed in to change notification settings - Fork 0
/
bite170.py
38 lines (27 loc) · 1.32 KB
/
bite170.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
import pandas as pd
data = "https://s3.us-east-2.amazonaws.com/bites-data/menu.csv"
# load the data in once, functions will use this module object
df = pd.read_csv(data)
pd.options.mode.chained_assignment = None # ignore warnings
def get_food_most_calories(df=df):
"""Return the food "Item" string with most calories"""
data = df[['Item', 'Calories']]
data = data.sort_values(by=['Calories'])
return data.iloc[-1]['Item']
def get_bodybuilder_friendly_foods(df=df, excl_drinks=False):
"""Calulate the Protein/Calories ratio of foods and return the
5 foods with the best ratio.
This function has a excl_drinks switch which, when turned on,
should exclude 'Coffee & Tea' and 'Beverages' from this top 5.
You will probably need to filter out foods with 0 calories to get the
right results.
Return a list of the top 5 foot Item stings."""
data = df[df['Calories'] > 0]
if excl_drinks:
data = data[data['Category'] != 'Coffee & Tea']
data = data[data['Category'] != 'Beverages']
data['Protein/Calories'] = data['Protein'] / data['Calories']
data = list(data[['Protein/Calories', 'Item']].sort_values(by=['Protein/Calories'], ascending=False)['Item'][:5])
return data
print(get_food_most_calories())
print(get_bodybuilder_friendly_foods(df, True))