Introduction

During a conversation with one of my friends, I showed them some of my work with analyzing the protein content of various meats and vegetables. After seeing the analysis, they asked me if I would be interested in analyzing the total caloric intake for a week's worth of meals.

I learned a great amount concatenating, droping, and manipulating indexes in Pandas.

Loading The Libraries and Dataframes

I was given the following data from a single file, the original file had the tables in seperate sheets. I exported the original file into seperate csv files so that I could load each table into separate dataframes

import pandas as pd
from IPython.core.display import display, HTML  
display(HTML("<style>.container { width:100% !important; }</style>"))
df_days = pd.read_csv('Days.csv')
df_ingredients = pd.read_csv('Ingredients.csv')
df_meals = pd.read_csv('Meals.csv')
df_results = pd.read_csv('Results.csv')

Investigating Dataframes

Before calculating the totals, I wanted to take a look at the dataframes, I transposed the columns in libreoffice such that the Days were columns, and the meals were rows. The majority of Pandas operations manipulate columns rather than rows.

I also transposed the columns for the other dataframes (df_meals and df_ingredients, )as well

df_days
Meal Monday Tuesday Wednesday Thursday Friday Saturday Sunday
0 Standard breakfast 1 1 1 0 0 0 0
1 Standard lunch 1 1 1 1 1 0 0
2 Standard dinner 1 1 1 0 0 0 0
3 Weekday egg muffin breakfast 0 0 0 1 1 0 0
4 Weekend egg muffin breakfast 0 0 0 0 0 1 2
5 Seafood dinner 0 0 0 0 0 1 1
6 Pasta lunch 0 0 0 0 0 1 1
7 Rice and pinto beans dinner 0 0 0 1 1 0 0
8 Mango dessert 1 1 1 1 1 1 1
9 Vanilla soymilk drink 1 1 1 1 1 0 0
df_meals
Meal Standard breakfast Standard lunch Standard dinner Weekday egg muffin breakfast Weekend egg muffin breakfast Seafood dinner Pasta lunch Rice and pinto beans dinner Mango dessert Vanilla soymilk drink
0 Brown rice 0 0 0 0 0 0 0 1 0 0
1 Whole wheat bread 0 1 0 0 0 0 0 0 0 0
2 Whole wheat cereal 1 0 0 0 0 0 0 0 0 0
3 Whole wheat muffin 0 0 0 1 2 0 0 0 0 0
4 Whole wheat pasta 0 0 0 0 0 0 1 0 0 0
5 Boneless skinless chicken breast 0 0 1 0 0 0 0 0 0 0
6 Salmon 0 0 0 0 0 1 0 0 0 0
7 Pinto beans 0 0 0 0 0 0 0 1 0 0
8 Black beans 0 0 0 0 0 0 0 0 0 0
9 Peanut butter 0 1 0 0 0 0 0 0 0 0
10 Eggs 0 0 0 1 1 0 0 0 0 0
11 Vanilla soymilk 0 0 0 0 0 0 0 0 0 1
12 Unsweet soymilk 1 0 0 0 0 0 0 0 0 0
13 Spinach 0 0 1 0 0 0 0 0 0 0
14 Broccoli 0 0 0 0 0 1 0 1 0 0
15 Carrots 0 1 0 0 0 0 1 0 0 0
16 Tomatoes 0 0 1 0 0 0 0 0 0 0
17 Banana 1 0 0 1 1 0 0 0 0 0
18 Strawberries 1 0 0 0 0 0 0 0 0 0
19 Mangos 0 0 0 0 0 0 0 0 1 0
20 Strawberry jam 0 1 0 0 0 0 0 0 0 0
21 Marinara sauce 0 0 0 0 0 0 1 0 0 0
22 American cheese 0 0 0 1 2 0 0 0 0 0
23 Olive oil 0 0 1 0 0 0 0 0 0 0
24 Salt 0 0 1 0 0 1 0 0 0 0
df_ingredients
Item Brand and style Quantity Calories Total Fat Saturated Fat Monounsaturated Fat Polyunsaturated Fat Cholesterol Carbs Sugar Protein Fiber Sodium
0 Brown rice 365 Everyday Value, long grain 150g 570 4.5 0.0 0.0 0.0 0 117 0 12 6 0
1 Whole wheat bread Brownberry, whole grains 2 slices 220 4.0 0.0 0.0 2.0 0 42 6 8 6 320
2 Whole wheat cereal 365 Everyday Value, wheat squares 60g 220 1.0 0.0 0.0 0.0 0 47 0 7 5 5
3 Whole wheat muffin Aunt Millie's, english muffins 1 muffin 110 1.5 0.0 0.0 0.5 0 21 1 6 3 180
4 Whole wheat pasta Barilla, whole grain penne 4oz 360 3.0 0.0 0.0 0.0 0 78 2 16 14 0
5 Boneless skinless chicken breast NaN 3oz 135 3.0 1.0 1.0 0.5 100 0 0 28 0 40
6 Salmon NaN 6oz 270 9.0 1.5 3.0 1.5 95 0 0 43 0 690
7 Pinto beans 365 Everyday Value 455g 350 0.0 0.0 0.0 0.0 0 67 2 25 28 18
8 Black beans 365 Everyday Value 455g 385 0.0 0.0 0.0 0.0 0 74 3 25 25 35
9 Peanut butter Jif, creamy 33g 190 16.0 3.5 0.0 0.0 0 8 3 7 2 140
10 Eggs Grade A large brown 2 eggs 180 14.0 4.0 6.0 3.0 370 1 0 12 0 190
11 Vanilla soymilk Silk, vanilla 1 cup 100 3.5 0.5 0.5 2.0 0 11 9 6 1 85
12 Unsweet soymilk Silk, unsweet vanilla 1 cup 80 4.0 0.5 1.0 2.5 0 4 1 7 2 70
13 Spinach NaN 60g 15 0.0 0.0 0.0 0.0 0 2 0 2 1 50
14 Broccoli Essential Everyday, frozen 2 cups 60 0.0 0.0 0.0 0.0 0 8 4 4 4 40
15 Carrots Green Giant, baby cut Carrots 4.5oz 55 0.0 0.0 0.0 0.0 0 12 8 1 3 98
16 Tomatoes Garden Ripe, grape tomatoes 100g 95 0.5 0.0 0.0 0.0 0 6 0 1 2 6
17 Banana NaN 1 banana 110 0.0 0.0 0.0 0.0 0 29 15 1 3 1
18 Strawberries Nature Blessed, frozen 1 cup 45 0.0 0.0 0.0 0.0 0 12 6 0 3 3
19 Mangos Nature Blessed, frozen 1 cup 75 0.0 0.0 0.0 0.0 0 20 19 1 1 1
20 Strawberry jam Smucker's, squeeze 20g 50 0.0 0.0 0.0 0.0 0 13 12 0 0 0
21 Marinara sauce Ragu Simply, chunky 0.25 cups 35 1.0 0.0 0.0 0.0 0 6 4 1 1 245
22 American cheese Dutch Farms, american singles 1 slice 70 5.0 0.0 0.0 0.0 0 2 0 3 0 300
23 Olive oil 365 Everyday Value, extra virgin 1 tbsp 120 14.0 2.0 0.0 0.0 0 0 0 0 0 0
24 Salt Morton, coarse kosher 0.25 tsp 0 0.0 0.0 0.0 0.0 0 0 0 0 0 480
df_results
Day Calories Total Fat Saturated Fat Monounsaturated Fat Polyunsaturated Fat Cholesterol Carbs Sugar Protein Fiber Sodium
0 Monday NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
1 Tuesday NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
2 Wednesday NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
3 Thursday NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
4 Friday NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
5 Saturday NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
6 Sunday NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN

Generating The Code

After looking at the raw data and transposing the data, I decided to use multiple for loops to solve the problem.

My general plan followed

  1. get meals for each day
    • make a dataframe for each day where there is 1
  2. get foods for each meal
  3. add each food to a list
  4. add each ingredient to a list
  5. store sum in results

The following code iterates through all the dataframesdf_days,df_meals, and df_ingredients intialized in the previous step to generate a dataframe with all the individual ingredients for all the days

Variables Intialized outside of the loop

  • meal_list, food_list, and ingredient_list are initially empty, we will set values for them once the loop begins.
  • days is a list of the days of the week, we will use to keep track of the day. Furthermore, we will use days to specify which column we want python to focus on
  • df_summary is a empty dataframe we will append the ingredients to
  • counter is a integer variable that that is used as a index when iterating the days list, it is set to be -1 to offset the starting column of df_days

all print() and display() statements were used to view the variables as the loop iterated

Explanation For The First loop

The first for loop iterates accross the columns of df_days dataframe in the first loop, generates a list of meals consumed in a day

  • column_title is the title of the column from df_days
  • day is the current day
  • df_day_non_zero is df_days, but all values greater than 0
  • meal_list uses df_day_non_zero but has only the meals quantity for a single day, .reset_index() resets the index as filtering for the day changes the index, .drop(columns = "index") drops the index created by .reset_index()

Explanation For The Second Loop

The second for loop iterates accross the columns of meal_list dataframe generated for a day from the previous step, generates a list of foods consumed in meal

  • meal_item is the title of the column from df_meals
  • df_empty is a empty temporary dataframe that we generate each iteration
  • food_quantity stores the number of meal consumed in a day
  • df_meal_day is df_meals, but all values greater than 0
  • food_list dataframe that uses df_meal_day to get the meal item for a particular meal
  • food_list[meal_item] dataframe that multiplies the specific quantity by the food_quantity

Explanation For The Third Loop

The third for loop iterates through the food_list dataframe generated for a meal from the previous step, concatenates the ingredients to df_empty dataframe, uses a conditional that will multiply the nutritional value by the number of values consumed

  • df_current_ingredient is df_ingredients but when the food item matches the value from `food_list
  • ingredient_quantity stores the number of meal items consumed in a single meal

After the third for loop, we will concatenate all the ingredients per meal into a single dataframe with two columns for the day and meal the item was consumed from. When creating new columns using the df["new column"] = value Pandas will add the new column to the end of the columns.

meal_list = []
food_list = []
ingredient_list = []
days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
df_summary = pd.DataFrame()
counter = -1

# loop through days table
for column_title in df_days:
    # get meals for each day
        # make a dataframe for each day where there is 1 
        day = days[counter]
        df_day_non_zero = df_days[df_days[day] > 0]
        meal_list = df_day_non_zero[["Meal",day]].reset_index().drop(columns = "index")
        
        #print statements for debugging and tracking variable values
        #meal_quantity = meal_list[day][]
        #print("days[i]")
        #display(days[counter])
        
        #print("df_day")
        #display(df_day)
        #print("column_title")
        #display(column_title)
        #print("meal_list")
        #display(meal_list)
        
        food_counter = 0
    # get foods for each meal
        for meal_item in meal_list["Meal"]:
            #print("meal_item")
            #display(meal_item)
            
            df_empty = pd.DataFrame()
            food_quantity = meal_list[day][food_counter]
            
            #print("food_quantity multiplication factor")
            #display(food_quantity)
            
            df_meal_day = df_meals[df_meals[meal_item] >= 1]
            food_list = df_meal_day[["Meal", meal_item]].reset_index().drop(columns = "index")
            
            #print("food_list before multiplication")
            #display(food_list)
            
            food_list[meal_item] = food_list[meal_item]*food_quantity # multiplies the list by the number of times from days ie if someone eats 2 meals, the meal item will be multipled by 2
            
            
            #print("food_list after multiplication")
            #display(food_list)
            
            # add each food to a list
            for food_list_index in range(len(food_list)):
                #print("food_list")
                #display(food_list)
                #print("food_list_index")
                #display(food_list_index)
                df_current_ingredient = df_ingredients[df_ingredients["Item"] == food_list["Meal"][food_list_index]]
                ingredient_quantity = food_list[meal_item][food_list_index]
                
                #print("df_current_ingredient")
                #display(df_current_ingredient)
                #print("food_list[Meal][food_list_index]")
                #display(food_list["Meal"][food_list_index])
                #print("ingredient_quantity")
                #display(ingredient_quantity)
                            
                if(ingredient_quantity>=1):
                    df_empty = pd.concat([df_empty, df_current_ingredient * ingredient_quantity])
                else:
                    df_empty = pd.concat([df_empty, df_current_ingredient])
                #display(df_empty)
           
            # add each ingredient     
                #need to make a running total, and then append to a seperate df for each day
            df_empty.loc[column_title,:] = df_empty[["Item","Calories", "Total Fat", "Saturated Fat", "Monounsaturated Fat", "Polyunsaturated Fat", "Cholesterol", "Carbs", "Sugar","Protein", "Fiber", "Sodium"]].sum(axis=0)
            df_empty["Meal"] = meal_item
            #display(df_empty)
            df_summary = pd.concat([df_summary, df_empty.tail(1)])
            #display(df_summary)
            food_counter+=1
        counter+=1

    
    # store sum in results
df_summary = df_summary.reset_index().rename(columns = {"index" : "Day"})
df_summary
Day Item Brand and style Quantity Calories Total Fat Saturated Fat Monounsaturated Fat Polyunsaturated Fat Cholesterol Carbs Sugar Protein Fiber Sodium Meal
0 Meal Whole wheat muffinWhole wheat muffinWhole whea... NaN NaN 1300.0 54.0 8.0 12.0 8.0 740.0 152.0 34.0 62.0 18.0 2302.0 Weekend egg muffin breakfast
1 Meal SalmonBroccoliSalt NaN NaN 330.0 9.0 1.5 3.0 1.5 95.0 8.0 4.0 47.0 4.0 1210.0 Seafood dinner
2 Meal Whole wheat pastaCarrotsMarinara sauce NaN NaN 450.0 4.0 0.0 0.0 0.0 0.0 96.0 14.0 18.0 18.0 343.0 Pasta lunch
3 Meal Mangos NaN NaN 75.0 0.0 0.0 0.0 0.0 0.0 20.0 19.0 1.0 1.0 1.0 Mango dessert
4 Monday Whole wheat cerealUnsweet soymilkBananaStrawbe... NaN NaN 455.0 5.0 0.5 1.0 2.5 0.0 92.0 22.0 15.0 13.0 79.0 Standard breakfast
5 Monday Whole wheat breadPeanut butterCarrotsStrawberr... NaN NaN 515.0 20.0 3.5 0.0 2.0 0.0 75.0 29.0 16.0 11.0 558.0 Standard lunch
6 Monday Boneless skinless chicken breastSpinachTomatoe... NaN NaN 365.0 17.5 3.0 1.0 0.5 100.0 8.0 0.0 31.0 3.0 576.0 Standard dinner
7 Monday Mangos NaN NaN 75.0 0.0 0.0 0.0 0.0 0.0 20.0 19.0 1.0 1.0 1.0 Mango dessert
8 Monday Vanilla soymilk NaN NaN 100.0 3.5 0.5 0.5 2.0 0.0 11.0 9.0 6.0 1.0 85.0 Vanilla soymilk drink
9 Tuesday Whole wheat cerealUnsweet soymilkBananaStrawbe... NaN NaN 455.0 5.0 0.5 1.0 2.5 0.0 92.0 22.0 15.0 13.0 79.0 Standard breakfast
10 Tuesday Whole wheat breadPeanut butterCarrotsStrawberr... NaN NaN 515.0 20.0 3.5 0.0 2.0 0.0 75.0 29.0 16.0 11.0 558.0 Standard lunch
11 Tuesday Boneless skinless chicken breastSpinachTomatoe... NaN NaN 365.0 17.5 3.0 1.0 0.5 100.0 8.0 0.0 31.0 3.0 576.0 Standard dinner
12 Tuesday Mangos NaN NaN 75.0 0.0 0.0 0.0 0.0 0.0 20.0 19.0 1.0 1.0 1.0 Mango dessert
13 Tuesday Vanilla soymilk NaN NaN 100.0 3.5 0.5 0.5 2.0 0.0 11.0 9.0 6.0 1.0 85.0 Vanilla soymilk drink
14 Wednesday Whole wheat cerealUnsweet soymilkBananaStrawbe... NaN NaN 455.0 5.0 0.5 1.0 2.5 0.0 92.0 22.0 15.0 13.0 79.0 Standard breakfast
15 Wednesday Whole wheat breadPeanut butterCarrotsStrawberr... NaN NaN 515.0 20.0 3.5 0.0 2.0 0.0 75.0 29.0 16.0 11.0 558.0 Standard lunch
16 Wednesday Boneless skinless chicken breastSpinachTomatoe... NaN NaN 365.0 17.5 3.0 1.0 0.5 100.0 8.0 0.0 31.0 3.0 576.0 Standard dinner
17 Wednesday Mangos NaN NaN 75.0 0.0 0.0 0.0 0.0 0.0 20.0 19.0 1.0 1.0 1.0 Mango dessert
18 Wednesday Vanilla soymilk NaN NaN 100.0 3.5 0.5 0.5 2.0 0.0 11.0 9.0 6.0 1.0 85.0 Vanilla soymilk drink
19 Thursday Whole wheat breadPeanut butterCarrotsStrawberr... NaN NaN 515.0 20.0 3.5 0.0 2.0 0.0 75.0 29.0 16.0 11.0 558.0 Standard lunch
20 Thursday Whole wheat muffinEggsBananaAmerican cheese NaN NaN 470.0 20.5 4.0 6.0 3.5 370.0 53.0 16.0 22.0 6.0 671.0 Weekday egg muffin breakfast
21 Thursday Brown ricePinto beansBroccoli NaN NaN 980.0 4.5 0.0 0.0 0.0 0.0 192.0 6.0 41.0 38.0 58.0 Rice and pinto beans dinner
22 Thursday Mangos NaN NaN 75.0 0.0 0.0 0.0 0.0 0.0 20.0 19.0 1.0 1.0 1.0 Mango dessert
23 Thursday Vanilla soymilk NaN NaN 100.0 3.5 0.5 0.5 2.0 0.0 11.0 9.0 6.0 1.0 85.0 Vanilla soymilk drink
24 Friday Whole wheat breadPeanut butterCarrotsStrawberr... NaN NaN 515.0 20.0 3.5 0.0 2.0 0.0 75.0 29.0 16.0 11.0 558.0 Standard lunch
25 Friday Whole wheat muffinEggsBananaAmerican cheese NaN NaN 470.0 20.5 4.0 6.0 3.5 370.0 53.0 16.0 22.0 6.0 671.0 Weekday egg muffin breakfast
26 Friday Brown ricePinto beansBroccoli NaN NaN 980.0 4.5 0.0 0.0 0.0 0.0 192.0 6.0 41.0 38.0 58.0 Rice and pinto beans dinner
27 Friday Mangos NaN NaN 75.0 0.0 0.0 0.0 0.0 0.0 20.0 19.0 1.0 1.0 1.0 Mango dessert
28 Friday Vanilla soymilk NaN NaN 100.0 3.5 0.5 0.5 2.0 0.0 11.0 9.0 6.0 1.0 85.0 Vanilla soymilk drink
29 Saturday Whole wheat muffinWhole wheat muffinEggsBanana... NaN NaN 650.0 27.0 4.0 6.0 4.0 370.0 76.0 17.0 31.0 9.0 1151.0 Weekend egg muffin breakfast
30 Saturday SalmonBroccoliSalt NaN NaN 330.0 9.0 1.5 3.0 1.5 95.0 8.0 4.0 47.0 4.0 1210.0 Seafood dinner
31 Saturday Whole wheat pastaCarrotsMarinara sauce NaN NaN 450.0 4.0 0.0 0.0 0.0 0.0 96.0 14.0 18.0 18.0 343.0 Pasta lunch
32 Saturday Mangos NaN NaN 75.0 0.0 0.0 0.0 0.0 0.0 20.0 19.0 1.0 1.0 1.0 Mango dessert
33 Sunday Whole wheat muffinWhole wheat muffinWhole whea... NaN NaN 1300.0 54.0 8.0 12.0 8.0 740.0 152.0 34.0 62.0 18.0 2302.0 Weekend egg muffin breakfast
34 Sunday SalmonBroccoliSalt NaN NaN 330.0 9.0 1.5 3.0 1.5 95.0 8.0 4.0 47.0 4.0 1210.0 Seafood dinner
35 Sunday Whole wheat pastaCarrotsMarinara sauce NaN NaN 450.0 4.0 0.0 0.0 0.0 0.0 96.0 14.0 18.0 18.0 343.0 Pasta lunch
36 Sunday Mangos NaN NaN 75.0 0.0 0.0 0.0 0.0 0.0 20.0 19.0 1.0 1.0 1.0 Mango dessert

Generating The Summary

using the grouping function in Pandas, we can genereate a summary dataframe

df_grouped = df_summary[4:].groupby(['Day']).sum().reindex(days) 
df_grouped
Calories Total Fat Saturated Fat Monounsaturated Fat Polyunsaturated Fat Cholesterol Carbs Sugar Protein Fiber Sodium
Day
Monday 1510.0 46.0 7.5 2.5 7.0 100.0 206.0 79.0 69.0 29.0 1299.0
Tuesday 1510.0 46.0 7.5 2.5 7.0 100.0 206.0 79.0 69.0 29.0 1299.0
Wednesday 1510.0 46.0 7.5 2.5 7.0 100.0 206.0 79.0 69.0 29.0 1299.0
Thursday 2140.0 48.5 8.0 6.5 7.5 370.0 351.0 79.0 86.0 57.0 1373.0
Friday 2140.0 48.5 8.0 6.5 7.5 370.0 351.0 79.0 86.0 57.0 1373.0
Saturday 1505.0 40.0 5.5 9.0 5.5 465.0 200.0 54.0 97.0 32.0 2705.0
Sunday 2155.0 67.0 9.5 15.0 9.5 835.0 276.0 71.0 128.0 41.0 3856.0

Tests Cells

The following cells were used to test solutions I tried when generating the for loop.

It was easier to run these on individual cells rather than in the nested for loop and print statements

df_test = df_days[df_days["Thursday"] == 1]
#df_test[["Meal","Monday"]]
df_test

print(df_days.columns.values[1:8])
['Monday' 'Tuesday' 'Wednesday' 'Thursday' 'Friday' 'Saturday' 'Sunday']
df_test2 = df_meals[df_meals["Standard breakfast"] ==1]
df_test2
Meal Standard breakfast Standard lunch Standard dinner Weekday egg muffin breakfast Weekend egg muffin breakfast Seafood dinner Pasta lunch Rice and pinto beans dinner Mango dessert Vanilla soymilk drink
2 Whole wheat cereal 1 0 0 0 0 0 0 0 0 0
12 Unsweet soymilk 1 0 0 0 0 0 0 0 0 0
17 Banana 1 0 0 1 1 0 0 0 0 0
18 Strawberries 1 0 0 0 0 0 0 0 0 0
df_test2[["Meal"]]
Meal
2 Whole wheat cereal
12 Unsweet soymilk
17 Banana
18 Strawberries
ingredient_list = []
ingredient_list = df_test2[["Meal"]].reset_index().drop(columns = "index")
ingredient_list
Meal
0 Whole wheat cereal
1 Unsweet soymilk
2 Banana
3 Strawberries
len(ingredient_list)
4
df_test3 = df_ingredients[df_ingredients["Item"] == ingredient_list["Meal"][0]]
df_test3
Item Brand and style Quantity Calories Total Fat Saturated Fat Monounsaturated Fat Polyunsaturated Fat Cholesterol Carbs Sugar Protein Fiber Sodium
2 Whole wheat cereal 365 Everyday Value, wheat squares 60g 220 1.0 0.0 0.0 0.0 0 47 0 7 5 5
df_test4 = df_ingredients[df_ingredients["Item"] == ingredient_list["Meal"][1]]
df_test4
Item Brand and style Quantity Calories Total Fat Saturated Fat Monounsaturated Fat Polyunsaturated Fat Cholesterol Carbs Sugar Protein Fiber Sodium
12 Unsweet soymilk Silk, unsweet vanilla 1 cup 80 4.0 0.5 1.0 2.5 0 4 1 7 2 70
df_test5 = df_test3.append(df_test4)
df_test5
Item Brand and style Quantity Calories Total Fat Saturated Fat Monounsaturated Fat Polyunsaturated Fat Cholesterol Carbs Sugar Protein Fiber Sodium
2 Whole wheat cereal 365 Everyday Value, wheat squares 60g 220 1.0 0.0 0.0 0.0 0 47 0 7 5 5
12 Unsweet soymilk Silk, unsweet vanilla 1 cup 80 4.0 0.5 1.0 2.5 0 4 1 7 2 70
df_test5.loc['Total',:]= df_test5.sum(axis=0)
df_test5
Item Brand and style Quantity Calories Total Fat Saturated Fat Monounsaturated Fat Polyunsaturated Fat Cholesterol Carbs Sugar Protein Fiber Sodium
2 Whole wheat cereal 365 Everyday Value, wheat squares 60g 220.0 1.0 0.0 0.0 0.0 0.0 47.0 0.0 7.0 5.0 5.0
12 Unsweet soymilk Silk, unsweet vanilla 1 cup 80.0 4.0 0.5 1.0 2.5 0.0 4.0 1.0 7.0 2.0 70.0
Total Whole wheat cerealUnsweet soymilkWhole wheat c... 365 Everyday Value, wheat squaresSilk, unsweet... 60g1 cup60g1 cup 600.0 10.0 1.0 2.0 5.0 0.0 102.0 2.0 28.0 14.0 150.0
df_test5
Item Brand and style Quantity Calories Total Fat Saturated Fat Monounsaturated Fat Polyunsaturated Fat Cholesterol Carbs Sugar Protein Fiber Sodium
2 Whole wheat cereal 365 Everyday Value, wheat squares 60g 220.0 1.0 0.0 0.0 0.0 0.0 47.0 0.0 7.0 5.0 5.0
12 Unsweet soymilk Silk, unsweet vanilla 1 cup 80.0 4.0 0.5 1.0 2.5 0.0 4.0 1.0 7.0 2.0 70.0
Total Whole wheat cerealUnsweet soymilkWhole wheat c... 365 Everyday Value, wheat squaresSilk, unsweet... 60g1 cup60g1 cup 600.0 10.0 1.0 2.0 5.0 0.0 102.0 2.0 28.0 14.0 150.0
df_meal_day = df_meals[df_meals["Weekend egg muffin breakfast"] >= 1]
display(df_meal_day)
display(df_meals)
Meal Standard breakfast Standard lunch Standard dinner Weekday egg muffin breakfast Weekend egg muffin breakfast Seafood dinner Pasta lunch Rice and pinto beans dinner Mango dessert Vanilla soymilk drink
3 Whole wheat muffin 0 0 0 1 2 0 0 0 0 0
10 Eggs 0 0 0 1 1 0 0 0 0 0
17 Banana 1 0 0 1 1 0 0 0 0 0
22 American cheese 0 0 0 1 2 0 0 0 0 0
Meal Standard breakfast Standard lunch Standard dinner Weekday egg muffin breakfast Weekend egg muffin breakfast Seafood dinner Pasta lunch Rice and pinto beans dinner Mango dessert Vanilla soymilk drink
0 Brown rice 0 0 0 0 0 0 0 1 0 0
1 Whole wheat bread 0 1 0 0 0 0 0 0 0 0
2 Whole wheat cereal 1 0 0 0 0 0 0 0 0 0
3 Whole wheat muffin 0 0 0 1 2 0 0 0 0 0
4 Whole wheat pasta 0 0 0 0 0 0 1 0 0 0
5 Boneless skinless chicken breast 0 0 1 0 0 0 0 0 0 0
6 Salmon 0 0 0 0 0 1 0 0 0 0
7 Pinto beans 0 0 0 0 0 0 0 1 0 0
8 Black beans 0 0 0 0 0 0 0 0 0 0
9 Peanut butter 0 1 0 0 0 0 0 0 0 0
10 Eggs 0 0 0 1 1 0 0 0 0 0
11 Vanilla soymilk 0 0 0 0 0 0 0 0 0 1
12 Unsweet soymilk 1 0 0 0 0 0 0 0 0 0
13 Spinach 0 0 1 0 0 0 0 0 0 0
14 Broccoli 0 0 0 0 0 1 0 1 0 0
15 Carrots 0 1 0 0 0 0 1 0 0 0
16 Tomatoes 0 0 1 0 0 0 0 0 0 0
17 Banana 1 0 0 1 1 0 0 0 0 0
18 Strawberries 1 0 0 0 0 0 0 0 0 0
19 Mangos 0 0 0 0 0 0 0 0 1 0
20 Strawberry jam 0 1 0 0 0 0 0 0 0 0
21 Marinara sauce 0 0 0 0 0 0 1 0 0 0
22 American cheese 0 0 0 1 2 0 0 0 0 0
23 Olive oil 0 0 1 0 0 0 0 0 0 0
24 Salt 0 0 1 0 0 1 0 0 0 0
food_list = df_meal_day[["Meal", "Standard breakfast"]].reset_index().drop(columns = "index")
food_list
Meal Standard breakfast
0 Mangos 0
df_day[["Meal", "Monday"]]
Meal Monday
4 Weekend egg muffin breakfast 0
5 Seafood dinner 0
6 Pasta lunch 0
8 Mango dessert 1
meal_list
Meal Sunday
0 Weekend egg muffin breakfast 2
1 Seafood dinner 1
2 Pasta lunch 1
3 Mango dessert 1
df_test6 = meal_list[meal_list["Sunday"]>1]["Sunday"]
df_test6
0    2
Name: Sunday, dtype: int64
df_test7 = meal_list["Meal"][meal_list["Sunday"]==2]
df_test7
0    Weekend egg muffin breakfast
Name: Meal, dtype: object
cats = [ 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']

df_weekday = df_summary[4:].groupby(['Day']).sum().reindex(cats) 
df_weekday
Calories Total Fat Saturated Fat Monounsaturated Fat Polyunsaturated Fat Cholesterol Carbs Sugar Protein Fiber Sodium
Day
Monday 1510.0 46.0 7.5 2.5 7.0 100.0 206.0 79.0 69.0 29.0 1299.0
Tuesday 1510.0 46.0 7.5 2.5 7.0 100.0 206.0 79.0 69.0 29.0 1299.0
Wednesday 1510.0 46.0 7.5 2.5 7.0 100.0 206.0 79.0 69.0 29.0 1299.0
Thursday 2140.0 48.5 8.0 6.5 7.5 370.0 351.0 79.0 86.0 57.0 1373.0
Friday 2140.0 48.5 8.0 6.5 7.5 370.0 351.0 79.0 86.0 57.0 1373.0
Saturday 1505.0 40.0 5.5 9.0 5.5 465.0 200.0 54.0 97.0 32.0 2705.0
Sunday 2155.0 67.0 9.5 15.0 9.5 835.0 276.0 71.0 128.0 41.0 3856.0