Discover new recipes using Python 🍝.

In this post, we are going to discover food recipes using Python. This is going to be a fun post and maybe a useful one 😁. So let’s begin.

To do anything, we first need the data. Download the data from here . Also, the Jupyter notebook for this project can be found here.

import numpy as np
import pandas as pd
import os
from zipfile import ZipFile
os.listdir("../datasets/6000-Indian-Food-Dataset/")
['IndianFoodDatasetCSV.csv']

After downloading the data from Kaggle, we need to extract the zip file. Modify the path to the dataset for your case before running the next code block.

# specifying the zip file name
file_name = "../datasets/6000-Indian-Food-Dataset/archive.zip"
  
# opening the zip file in READ mode
with ZipFile(file_name, 'r') as zip:
    # printing all the contents of the zip file
    zip.printdir()
  
    # extracting all the files
    print('Extracting all the files now...')
    zip.extractall("../datasets/6000-Indian-Food-Dataset/")
    print('Done!')
File Name                                             Modified             Size
IndianFoodDatasetCSV.csv                       2020-10-24 01:08:28     24151935
IndianFoodDatasetXLS.xlsx                      2020-10-24 01:08:28      5535790
Extracting all the files now...
Done!

Now, you must have two files in your data folder. We will open the CSV file using pandas.

df = pd.read_csv("../datasets/6000-Indian-Food-Dataset/IndianFoodDatasetCSV.csv")

The data frame df contains all the rows and column of the CSV file in a proper format. Let’s take a look at few rows.

df.head()
Srno RecipeName TranslatedRecipeName Ingredients TranslatedIngredients PrepTimeInMins CookTimeInMins TotalTimeInMins Servings Cuisine Course Diet Instructions TranslatedInstructions URL
0 1 Masala Karela Recipe Masala Karela Recipe 6 Karela (Bitter Gourd/ Pavakkai) - deseeded,S... 6 Karela (Bitter Gourd/ Pavakkai) - deseeded,S... 15 30 45 6 Indian Side Dish Diabetic Friendly To begin making the Masala Karela Recipe,de-se... To begin making the Masala Karela Recipe,de-se... https://www.archanaskitchen.com/masala-karela-...
1 2 टमाटर पुलियोगरे रेसिपी - Spicy Tomato Rice (Re... Spicy Tomato Rice (Recipe) 2-1/2 कप चावल - पका ले,3 टमाटर,3 छोटा चमच्च बी... 2-1 / 2 cups rice - cooked, 3 tomatoes, 3 teas... 5 10 15 3 South Indian Recipes Main Course Vegetarian टमाटर पुलियोगरे बनाने के लिए सबसे पहले टमाटर क... To make tomato puliogere, first cut the tomato... http://www.archanaskitchen.com/spicy-tomato-ri...
2 3 Ragi Semiya Upma Recipe - Ragi Millet Vermicel... Ragi Semiya Upma Recipe - Ragi Millet Vermicel... 1-1/2 cups Rice Vermicelli Noodles (Thin),1 On... 1-1/2 cups Rice Vermicelli Noodles (Thin),1 On... 20 30 50 4 South Indian Recipes South Indian Breakfast High Protein Vegetarian To begin making the Ragi Vermicelli Recipe, fi... To begin making the Ragi Vermicelli Recipe, fi... http://www.archanaskitchen.com/ragi-vermicelli...
3 4 Gongura Chicken Curry Recipe - Andhra Style Go... Gongura Chicken Curry Recipe - Andhra Style Go... 500 grams Chicken,2 Onion - chopped,1 Tomato -... 500 grams Chicken,2 Onion - chopped,1 Tomato -... 15 30 45 4 Andhra Lunch Non Vegeterian To begin making Gongura Chicken Curry Recipe f... To begin making Gongura Chicken Curry Recipe f... http://www.archanaskitchen.com/gongura-chicken...
4 5 आंध्रा स्टाइल आलम पचड़ी रेसिपी - Adrak Chutney ... Andhra Style Alam Pachadi Recipe - Adrak Chutn... 1 बड़ा चमच्च चना दाल,1 बड़ा चमच्च सफ़ेद उरद दाल,2... 1 tablespoon chana dal, 1 tablespoon white ura... 10 20 30 4 Andhra South Indian Breakfast Vegetarian आंध्रा स्टाइल आलम पचड़ी बनाने के लिए सबसे पहले ... To make Andhra Style Alam Pachadi, first heat ... https://www.archanaskitchen.com/andhra-style-a...

The Srno column is an unnecessary one and we will drop it. To drop a column from a pandas DataFrame use the drop() method and specify the columns you want dropped.

# drop the serial no column
df = df.drop(columns=['Srno'])
df.head()
RecipeName TranslatedRecipeName Ingredients TranslatedIngredients PrepTimeInMins CookTimeInMins TotalTimeInMins Servings Cuisine Course Diet Instructions TranslatedInstructions URL
0 Masala Karela Recipe Masala Karela Recipe 6 Karela (Bitter Gourd/ Pavakkai) - deseeded,S... 6 Karela (Bitter Gourd/ Pavakkai) - deseeded,S... 15 30 45 6 Indian Side Dish Diabetic Friendly To begin making the Masala Karela Recipe,de-se... To begin making the Masala Karela Recipe,de-se... https://www.archanaskitchen.com/masala-karela-...
1 टमाटर पुलियोगरे रेसिपी - Spicy Tomato Rice (Re... Spicy Tomato Rice (Recipe) 2-1/2 कप चावल - पका ले,3 टमाटर,3 छोटा चमच्च बी... 2-1 / 2 cups rice - cooked, 3 tomatoes, 3 teas... 5 10 15 3 South Indian Recipes Main Course Vegetarian टमाटर पुलियोगरे बनाने के लिए सबसे पहले टमाटर क... To make tomato puliogere, first cut the tomato... http://www.archanaskitchen.com/spicy-tomato-ri...
2 Ragi Semiya Upma Recipe - Ragi Millet Vermicel... Ragi Semiya Upma Recipe - Ragi Millet Vermicel... 1-1/2 cups Rice Vermicelli Noodles (Thin),1 On... 1-1/2 cups Rice Vermicelli Noodles (Thin),1 On... 20 30 50 4 South Indian Recipes South Indian Breakfast High Protein Vegetarian To begin making the Ragi Vermicelli Recipe, fi... To begin making the Ragi Vermicelli Recipe, fi... http://www.archanaskitchen.com/ragi-vermicelli...
3 Gongura Chicken Curry Recipe - Andhra Style Go... Gongura Chicken Curry Recipe - Andhra Style Go... 500 grams Chicken,2 Onion - chopped,1 Tomato -... 500 grams Chicken,2 Onion - chopped,1 Tomato -... 15 30 45 4 Andhra Lunch Non Vegeterian To begin making Gongura Chicken Curry Recipe f... To begin making Gongura Chicken Curry Recipe f... http://www.archanaskitchen.com/gongura-chicken...
4 आंध्रा स्टाइल आलम पचड़ी रेसिपी - Adrak Chutney ... Andhra Style Alam Pachadi Recipe - Adrak Chutn... 1 बड़ा चमच्च चना दाल,1 बड़ा चमच्च सफ़ेद उरद दाल,2... 1 tablespoon chana dal, 1 tablespoon white ura... 10 20 30 4 Andhra South Indian Breakfast Vegetarian आंध्रा स्टाइल आलम पचड़ी बनाने के लिए सबसे पहले ... To make Andhra Style Alam Pachadi, first heat ... https://www.archanaskitchen.com/andhra-style-a...

Let’s print out the dimensions of the data frame.

df.shape
(6871, 14)

We have a total of 6871 recipes and there are 14 properties for each recipe. As you can see, the recipes are categories by diets, course, cuisine and many more. Let’s get the statistics for some categories.

df.Diet.value_counts()
Vegetarian                      4712
High Protein Vegetarian          705
Non Vegeterian                   427
Eggetarian                       344
Diabetic Friendly                260
High Protein Non Vegetarian      225
No Onion No Garlic (Sattvic)      73
Vegan                             61
Gluten Free                       50
Sugar Free Diet                   14
Name: Diet, dtype: int64
df.Course.value_counts()
Lunch                           1765
Side Dish                        992
Snack                            876
Dinner                           782
Dessert                          659
Appetizer                        639
Main Course                      315
World Breakfast                  260
South Indian Breakfast           260
North Indian Breakfast           123
Indian Breakfast                 101
Vegetarian                        47
One Pot Dish                      33
High Protein Vegetarian            7
Brunch                             4
Vegan                              3
Non Vegeterian                     2
No Onion No Garlic (Sattvic)       1
Eggetarian                         1
Sugar Free Diet                    1
Name: Course, dtype: int64
df.Cuisine.value_counts()
Indian                  1157
Continental             1021
North Indian Recipes     938
South Indian Recipes     682
Italian Recipes          236
                        ... 
Jewish                     1
Dessert                    1
Lunch                      1
Brunch                     1
Dinner                     1
Name: Cuisine, Length: 82, dtype: int64

I am really interested in the high protein vegetarian diet categories. Let’s filter out vegetarian high protein dishes with maximum preparation and cooking time of 30 minutes from Indian cuisine. We can do this by combining multiple columns condtions for the data frame.

First filter out the recipes based on diet like this.

high_protein_veg_recp = df[df['Diet'] == 'High Protein Vegetarian']

Next, we can filter out the recipes based on Cuisine.

high_protein_veg_recp = high_protein_veg_recp[high_protein_veg_recp['Cuisine'] == 'Indian']

And, finally last filter for TotalTimeInMins

high_protein_veg_recp = high_protein_veg_recp[high_protein_veg_recp['TotalTimeInMins'] < 31]

Now the data frame high_protein_veg_recp contains all the recipes that are vegetarian, high in protein, Indian cuisine, and total preparation time less than or equal to 30 minutes. Let’s see some of them.

high_protein_veg_recp.head()
RecipeName TranslatedRecipeName Ingredients TranslatedIngredients PrepTimeInMins CookTimeInMins TotalTimeInMins Servings Cuisine Course Diet Instructions TranslatedInstructions URL
1775 Soya Chunks Pepper Curry Recipe Soya Chunks Pepper Curry Recipe 2 cups Soy Chunks (Nuggets),1 Green Bell Peppe... 2 cups Soy Chunks (Nuggets),1 Green Bell Peppe... 10 20 30 3 Indian Lunch High Protein Vegetarian To begin making the Soya Chunks Pepper Curry r... To begin making the Soya Chunks Pepper Curry r... https://www.archanaskitchen.com/soya-chunks-pe...
1976 High-Protein Peanut Chutney Recipe-Indian Styl... High-Protein Peanut Chutney Recipe-Indian Styl... 1/2 teaspoon Ghee,3/4 cup Roasted Peanuts (Moo... 1/2 teaspoon Ghee,3/4 cup Roasted Peanuts (Moo... 15 15 30 5 Indian Side Dish High Protein Vegetarian To begin making the Peanut Chutney Recipe, fir... To begin making the Peanut Chutney Recipe, fir... http://www.archanaskitchen.com/peanut-chutney-...
2146 Rajma and Corn Salad Recipe Rajma and Corn Salad Recipe 1/2 cup Kashmiri Rajma - or regular rajma,1/2 ... 1/2 cup Kashmiri Rajma - or regular rajma,1/2 ... 15 10 25 5 Indian Side Dish High Protein Vegetarian To begin making the Rajma and Corn Salad Recip... To begin making the Rajma and Corn Salad Recip... https://www.archanaskitchen.com/kidney-beans-c...
2248 सोया चंक्स सब्ज़ी रेसिपी - Soya Chunks Sabzi (R... Soya Chunks Sabzi (Recipe In Hindi) 1 कप सोया चंक्स,4 कप पानी - गुनगुना,1 प्याज - ... 1 cup soy chunks, 4 cups water - lukewarm, 1 o... 10 20 30 3 Indian Lunch High Protein Vegetarian सोया चंक्स सब्ज़ी बनाने के लिए सबसे पहले सोया च... To make Soya Chunks vegetable, first of all, p... http://www.archanaskitchen.com/soya-chunks-sab...
2373 Matar Masala Tofu Recipe Matar Masala Tofu Recipe 200 grams Tofu,3/4 cups Homemade tomato puree,... 200 grams Tofu,3/4 cups Homemade tomato puree,... 10 10 20 2 Indian Lunch High Protein Vegetarian To begin making the Matar Masala Tofu Recipe, ... To begin making the Matar Masala Tofu Recipe, ... http://www.archanaskitchen.com/matar-masala-to...

We can also combine multiple conditions we set for the columns of the data frame like this.

high_protein_veg_recp = df[(df['Diet'] == 'High Protein Vegetarian') & (df['Cuisine'] == 'Indian') & (df['TotalTimeInMins'] < 31)].reset_index(drop=True)
high_protein_veg_recp.head()
RecipeName TranslatedRecipeName Ingredients TranslatedIngredients PrepTimeInMins CookTimeInMins TotalTimeInMins Servings Cuisine Course Diet Instructions TranslatedInstructions URL
0 Soya Chunks Pepper Curry Recipe Soya Chunks Pepper Curry Recipe 2 cups Soy Chunks (Nuggets),1 Green Bell Peppe... 2 cups Soy Chunks (Nuggets),1 Green Bell Peppe... 10 20 30 3 Indian Lunch High Protein Vegetarian To begin making the Soya Chunks Pepper Curry r... To begin making the Soya Chunks Pepper Curry r... https://www.archanaskitchen.com/soya-chunks-pe...
1 High-Protein Peanut Chutney Recipe-Indian Styl... High-Protein Peanut Chutney Recipe-Indian Styl... 1/2 teaspoon Ghee,3/4 cup Roasted Peanuts (Moo... 1/2 teaspoon Ghee,3/4 cup Roasted Peanuts (Moo... 15 15 30 5 Indian Side Dish High Protein Vegetarian To begin making the Peanut Chutney Recipe, fir... To begin making the Peanut Chutney Recipe, fir... http://www.archanaskitchen.com/peanut-chutney-...
2 Rajma and Corn Salad Recipe Rajma and Corn Salad Recipe 1/2 cup Kashmiri Rajma - or regular rajma,1/2 ... 1/2 cup Kashmiri Rajma - or regular rajma,1/2 ... 15 10 25 5 Indian Side Dish High Protein Vegetarian To begin making the Rajma and Corn Salad Recip... To begin making the Rajma and Corn Salad Recip... https://www.archanaskitchen.com/kidney-beans-c...
3 सोया चंक्स सब्ज़ी रेसिपी - Soya Chunks Sabzi (R... Soya Chunks Sabzi (Recipe In Hindi) 1 कप सोया चंक्स,4 कप पानी - गुनगुना,1 प्याज - ... 1 cup soy chunks, 4 cups water - lukewarm, 1 o... 10 20 30 3 Indian Lunch High Protein Vegetarian सोया चंक्स सब्ज़ी बनाने के लिए सबसे पहले सोया च... To make Soya Chunks vegetable, first of all, p... http://www.archanaskitchen.com/soya-chunks-sab...
4 Matar Masala Tofu Recipe Matar Masala Tofu Recipe 200 grams Tofu,3/4 cups Homemade tomato puree,... 200 grams Tofu,3/4 cups Homemade tomato puree,... 10 10 20 2 Indian Lunch High Protein Vegetarian To begin making the Matar Masala Tofu Recipe, ... To begin making the Matar Masala Tofu Recipe, ... http://www.archanaskitchen.com/matar-masala-to...

Notice, that I have also reset the index of the data frame by appending reset_index(drop=True) at the end of the conditions.

Finally, let’s assume that you have Tofu in your fridge and you want to know what high protein dishes you can make using Tofu. We can do this by filtering the rows of the data frame based on tofu keyword. Let’s print out the details for recipes that has Tofu in them.

# Create a Tofu data frame
tofu_df = pd.DataFrame()
# find all the Tofu recipes and add them to the Tofu data frame
for p in high_protein_veg_recp['RecipeName']:
    if 'Tofu' in p:
        tofu_df = tofu_df.append(high_protein_veg_recp.loc[high_protein_veg_recp['RecipeName'] == p])
# print out the tofu data frame
tofu_df
RecipeName TranslatedRecipeName Ingredients TranslatedIngredients PrepTimeInMins CookTimeInMins TotalTimeInMins Servings Cuisine Course Diet Instructions TranslatedInstructions URL
4 Matar Masala Tofu Recipe Matar Masala Tofu Recipe 200 grams Tofu,3/4 cups Homemade tomato puree,... 200 grams Tofu,3/4 cups Homemade tomato puree,... 10 10 20 2 Indian Lunch High Protein Vegetarian To begin making the Matar Masala Tofu Recipe, ... To begin making the Matar Masala Tofu Recipe, ... http://www.archanaskitchen.com/matar-masala-to...
11 Mango Tofu Smoothie Recipe Mango Tofu Smoothie Recipe 1 Ripe Bananas - spotty and frozen,1-1/2 cups ... 1 Ripe Bananas - spotty and frozen,1-1/2 cups ... 5 5 10 2 Indian World Breakfast High Protein Vegetarian To begin making the Mango Tofu smoothie, place... To begin making the Mango Tofu smoothie, place... http://www.archanaskitchen.com/mango-tofu-smoo...

Enjoy your Tofu recipes 😋