{"cells":[{"cell_type":"markdown","id":"b5c0e3fe-5673-4fef-988e-ad24a7ede136","metadata":{},"outputs":[],"source":["\u003ca href=\"https://cognitiveclass.ai\"\u003e\u003cimg src=\"https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DS0103EN-SkillsNetwork/labs/Module%203/images/IDSNlogo.png\" width=\"400\"\u003e \u003c/a\u003e\n","\n","\n","# From Understanding to Preparation\n","\n","\n","Estimated time needed: **20** minutes\n","    \n","\n","## Objectives\n","\n","After completing this lab you will be able to:\n","\n","* Describe Data Preparation \n","* Prepare Data for analysis and inference\n"]},{"cell_type":"markdown","id":"26cc623e-f99e-4956-8f7b-4990f1140201","metadata":{},"outputs":[],"source":["## Introduction\n","\n","In this lab, we will continue learning about the data science methodology, and focus on the **Data Understanding** and the **Data Preparation** stages.\n"]},{"cell_type":"markdown","id":"378850a7-59b4-414e-850b-f3eb29359eb5","metadata":{},"outputs":[],"source":["## Table of Contents\n","\n","\u003cdiv class=\"alert alert-block alert-info\" style=\"margin-top: 20px\"\u003e\n","    \n","1. [Recap](#0)\u003cbr\u003e\n","2. [Data Understanding](#2)\u003cbr\u003e\n","3. [Data Preparation](#4)\u003cbr\u003e\n","\u003c/div\u003e\n","\u003chr\u003e\n"]},{"cell_type":"code","id":"efa1b663-0a94-4ce6-8774-7be3108d4c52","metadata":{},"outputs":[],"source":["# Recap \u003ca id=\"0\"\u003e\u003c/a\u003e"]},{"cell_type":"markdown","id":"a05d4c98-ce0d-415b-b9e8-dcb5bda63169","metadata":{},"outputs":[],"source":["In the Lab **From Requirements to Collection**, we learned that the data we need to answer the question developed in the business understanding stage, namely *can we automate the process of determining the cuisine of a given recipe?*, is readily available. A researcher named Yong-Yeol Ahn scraped tens of thousands of food recipes (cuisines and ingredients) from three different websites, namely:\n"]},{"cell_type":"markdown","id":"d8e7bf74-45a8-4972-ab57-d1bbe0f29acb","metadata":{},"outputs":[],"source":["\u003cimg src=\"https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DS0103EN-SkillsNetwork/labs/Module%202/images/lab2_fig3_allrecipes.png\" width=\"500\"\u003e\n","\u003cdiv align=\"left\"\u003e\n","Credit: www.allrecipes.com\n","\u003c/div\u003e\n","\u003cbr/\u003e\u003cbr/\u003e\n","\u003cimg src=\"https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DS0103EN-SkillsNetwork/labs/Module%202/images/lab2_fig4_epicurious.png\" width=\"500\"\u003e\n","\u003cdiv align=\"left\"\u003e\n","Credit: www.epicurious.com\n","\u003c/div\u003e\n","\u003cbr/\u003e\u003cbr/\u003e\n","\u003cimg src=\"https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DS0103EN-SkillsNetwork/labs/Module%202/images/lab2_fig5_menupan.png\" width=\"500\"\u003e\n","\u003cdiv align=\"left\"\u003e\n","Credit: www.menupan.com\n","\u003c/div\u003e\n","\u003cbr/\u003e\u003cbr/\u003e\n"]},{"cell_type":"markdown","id":"f93c016e-900d-4a25-8f82-a1949bb37bca","metadata":{},"outputs":[],"source":["For more information on Yong-Yeol Ahn and his research, you can read his paper on [Flavor Network and the Principles of Food Pairing](http://yongyeol.com/papers/ahn-flavornet-2011.pdf).\n"]},{"cell_type":"markdown","id":"ff9b2122-2e46-41d2-bcef-65056fbf1aba","metadata":{},"outputs":[],"source":["We also collected the data and placed it on an IBM server for your convenience.\n","\n","------------\n"]},{"cell_type":"markdown","id":"67ad6291-75c2-45c4-87b5-69d71e933493","metadata":{},"outputs":[],"source":["# Data Understanding \u003ca id=\"2\"\u003e\u003c/a\u003e\n"]},{"cell_type":"markdown","id":"119cbb0a-9ab3-4603-b5c3-6b456a94b05f","metadata":{},"outputs":[],"source":["\u003cimg src=\"https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DS0103EN-SkillsNetwork/labs/Module%203/images/flowchart_data_understanding.png\" width=\"500\"\u003e\n"]},{"cell_type":"markdown","id":"d4308f33-1cfc-4adb-bf1e-abc5eb4f484a","metadata":{},"outputs":[],"source":["\u003cstrong\u003eImportant note:\u003c/strong\u003e Please note that you are not expected to know how to program in python. The following code is meant to illustrate the stage of data collection, so it is totally fine if you do not understand the individual lines of code. There will be a full course in this certificate on programming in python, \u003ca href=\"http://cocl.us/PY0101EN_DS0103EN_LAB3_PYTHON_edX\"\u003ePython for Data Science\u003c/a\u003e, which will teach you how to program in Python if you decide to complete this certificate.\n"]},{"cell_type":"markdown","id":"39468c59-f35f-469e-844e-925bf967e6d9","metadata":{},"outputs":[],"source":["### Using this notebook:\n","\n","To run any of the following cells of code, you can type **Shift + Enter** to excute the code in a cell.\n"]},{"cell_type":"markdown","id":"954571a0-70c8-4a79-9aa9-0e93bcb1d7c2","metadata":{},"outputs":[],"source":["Get the version of Python installed.\n"]},{"cell_type":"code","id":"f560ca7e-2985-44d9-975b-d112ebc64a74","metadata":{},"outputs":[],"source":["# check Python version\n!python -V"]},{"cell_type":"markdown","id":"f5a7d2d9-b7a9-4b45-a753-ae57ce482b00","metadata":{},"outputs":[],"source":["Download the library and dependencies that we will need to run this lab.\n"]},{"cell_type":"code","id":"44063127-f81b-49cd-9edb-322c1197cf41","metadata":{},"outputs":[],"source":["import pandas as pd # import library to read data into dataframe\npd.set_option('display.max_columns', None)\nimport numpy as np # import numpy library\nimport re # import library for regular expression"]},{"cell_type":"markdown","id":"cd1392f5-14c3-4f01-bf72-5ebb452631f0","metadata":{},"outputs":[],"source":["Download the data from the IBM server and read it into a *pandas* dataframe.\n"]},{"cell_type":"code","id":"be57a268-b1c9-49ec-b5cf-ad1d3f5a70f1","metadata":{},"outputs":[],"source":["recipes = pd.read_csv(\"https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DS0103EN-SkillsNetwork/labs/Module%202/recipes.csv\")\n\nprint(\"Data read into dataframe!\") # takes about 30 seconds"]},{"cell_type":"markdown","id":"2defad9c-5650-4098-85fb-0bf33f8ed50a","metadata":{},"outputs":[],"source":["Show the first few rows.\n"]},{"cell_type":"code","id":"85944eb0-f916-4466-88e1-53fe30e74e62","metadata":{},"outputs":[],"source":["recipes.head()"]},{"cell_type":"markdown","id":"920bbc01-3b85-40da-b37a-bce8310bc040","metadata":{},"outputs":[],"source":["Get the dimensions of the dataframe.\n"]},{"cell_type":"code","id":"ec365622-3955-42dc-a75e-98315d26c67d","metadata":{},"outputs":[],"source":["recipes.shape"]},{"cell_type":"markdown","id":"7a668f19-7918-4541-b81c-bab46adf1514","metadata":{},"outputs":[],"source":["So our dataset consists of 57,691 recipes. Each row represents a recipe, and for each recipe, the corresponding cuisine is documented as well as whether 384 ingredients exist in the recipe or not, beginning with almond and ending with zucchini.\n"]},{"cell_type":"markdown","id":"e525405a-865a-40f4-b4d8-43e30d6b7747","metadata":{},"outputs":[],"source":["We know that a basic sushi recipe includes the ingredients:\n","* rice\n","* soy sauce\n","* wasabi\n","* some fish/vegetables\n"]},{"cell_type":"markdown","id":"69258781-2fb7-4dfe-95f9-fb6fb40f6c29","metadata":{},"outputs":[],"source":["Let's check that these ingredients exist in our dataframe:\n"]},{"cell_type":"code","id":"3958e939-5124-4fae-8b6b-a0cfaf98ad6e","metadata":{},"outputs":[],"source":["ingredients = list(recipes.columns.values)\n\nprint([match.group(0) for ingredient in ingredients for match in [(re.compile(\".*(rice).*\")).search(ingredient)] if match])\nprint([match.group(0) for ingredient in ingredients for match in [(re.compile(\".*(wasabi).*\")).search(ingredient)] if match])\nprint([match.group(0) for ingredient in ingredients for match in [(re.compile(\".*(soy).*\")).search(ingredient)] if match])"]},{"cell_type":"markdown","id":"08c2c6e9-3ab5-4d96-a8b8-6f73ab6da9ae","metadata":{},"outputs":[],"source":["Yes, they do!\n","\n","* rice exists as rice.\n","* wasabi exists as wasabi.\n","* soy exists as soy_sauce.\n","\n","So maybe if a recipe contains all three ingredients: rice, wasabi, and soy_sauce, then we can confidently say that the recipe is a **Japanese** cuisine! Let's keep this in mind!\n","\n","----------------\n"]},{"cell_type":"markdown","id":"6c9d5f74-89af-4808-b7c4-693ba5f21ae3","metadata":{},"outputs":[],"source":["# Data Preparation \u003ca id=\"4\"\u003e\u003c/a\u003e\n"]},{"cell_type":"markdown","id":"a47f0904-5289-47fe-ac80-bd18a42f3fe0","metadata":{},"outputs":[],"source":["\u003cimg src=\"https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-DS0103EN-SkillsNetwork/labs/Module%203/images/lab3_fig5_flowchart_data_preparation.png\" width=\"500\"\u003e\n"]},{"cell_type":"markdown","id":"fc946c05-f6f5-4d19-9026-e828cc9680f9","metadata":{},"outputs":[],"source":["In this section, we will prepare data for the next stage in the data science methodology, which is modeling. This stage involves exploring the data further and making sure that it is in the right format for the machine learning algorithm that we selected in the analytic approach stage, which is decision trees.\n"]},{"cell_type":"markdown","id":"ccdd6613-0c23-4794-876e-0c26636bb244","metadata":{},"outputs":[],"source":["First, look at the data to see if it needs cleaning.\n"]},{"cell_type":"code","id":"7e4cc0b0-82fb-4c66-967b-07a0be439506","metadata":{},"outputs":[],"source":["recipes[\"country\"].value_counts() # frequency table"]},{"cell_type":"markdown","id":"fc963628-36a5-4c00-b31d-ad63382c9077","metadata":{},"outputs":[],"source":["By looking at the above table, we can make the following observations:\n","\n","1. Cuisine column is labeled as Country, which is inaccurate.\n","2. Cuisine names are not consistent as not all of them start with an uppercase first letter.\n","3. Some cuisines are duplicated as variation of the country name, such as Vietnam and Vietnamese.\n","4. Some cuisines have very few recipes.\n"]},{"cell_type":"markdown","id":"d842c877-0ec3-446b-8528-c57305e01072","metadata":{},"outputs":[],"source":["#### Let's fix these problems.\n"]},{"cell_type":"markdown","id":"3fde5edc-5db7-4468-aaff-1999b8a592f6","metadata":{},"outputs":[],"source":["Fix the name of the column showing the cuisine.\n"]},{"cell_type":"code","id":"2a5c9226-b7fd-4de7-b3d8-9f1703de6916","metadata":{},"outputs":[],"source":["column_names = recipes.columns.values\ncolumn_names[0] = \"cuisine\"\nrecipes.columns = column_names\n\nrecipes"]},{"cell_type":"markdown","id":"70e5cac4-4965-4f3e-8d15-1a96a9e00062","metadata":{},"outputs":[],"source":["Make all the cuisine names lowercase.\n"]},{"cell_type":"code","id":"edfc595e-a847-4505-a049-346ae83ecf28","metadata":{},"outputs":[],"source":["recipes[\"cuisine\"] = recipes[\"cuisine\"].str.lower()"]},{"cell_type":"markdown","id":"76d2b92c-01f7-4223-8a63-32907c04b153","metadata":{},"outputs":[],"source":["Make the cuisine names consistent.\n"]},{"cell_type":"code","id":"0a894845-d8cf-42a0-8e10-36e0748bc1a4","metadata":{},"outputs":[],"source":["recipes.loc[recipes[\"cuisine\"] == \"austria\", \"cuisine\"] = \"austrian\"\nrecipes.loc[recipes[\"cuisine\"] == \"belgium\", \"cuisine\"] = \"belgian\"\nrecipes.loc[recipes[\"cuisine\"] == \"china\", \"cuisine\"] = \"chinese\"\nrecipes.loc[recipes[\"cuisine\"] == \"canada\", \"cuisine\"] = \"canadian\"\nrecipes.loc[recipes[\"cuisine\"] == \"netherlands\", \"cuisine\"] = \"dutch\"\nrecipes.loc[recipes[\"cuisine\"] == \"france\", \"cuisine\"] = \"french\"\nrecipes.loc[recipes[\"cuisine\"] == \"germany\", \"cuisine\"] = \"german\"\nrecipes.loc[recipes[\"cuisine\"] == \"india\", \"cuisine\"] = \"indian\"\nrecipes.loc[recipes[\"cuisine\"] == \"indonesia\", \"cuisine\"] = \"indonesian\"\nrecipes.loc[recipes[\"cuisine\"] == \"iran\", \"cuisine\"] = \"iranian\"\nrecipes.loc[recipes[\"cuisine\"] == \"italy\", \"cuisine\"] = \"italian\"\nrecipes.loc[recipes[\"cuisine\"] == \"japan\", \"cuisine\"] = \"japanese\"\nrecipes.loc[recipes[\"cuisine\"] == \"israel\", \"cuisine\"] = \"israeli\"\nrecipes.loc[recipes[\"cuisine\"] == \"korea\", \"cuisine\"] = \"korean\"\nrecipes.loc[recipes[\"cuisine\"] == \"lebanon\", \"cuisine\"] = \"lebanese\"\nrecipes.loc[recipes[\"cuisine\"] == \"malaysia\", \"cuisine\"] = \"malaysian\"\nrecipes.loc[recipes[\"cuisine\"] == \"mexico\", \"cuisine\"] = \"mexican\"\nrecipes.loc[recipes[\"cuisine\"] == \"pakistan\", \"cuisine\"] = \"pakistani\"\nrecipes.loc[recipes[\"cuisine\"] == \"philippines\", \"cuisine\"] = \"philippine\"\nrecipes.loc[recipes[\"cuisine\"] == \"scandinavia\", \"cuisine\"] = \"scandinavian\"\nrecipes.loc[recipes[\"cuisine\"] == \"spain\", \"cuisine\"] = \"spanish_portuguese\"\nrecipes.loc[recipes[\"cuisine\"] == \"portugal\", \"cuisine\"] = \"spanish_portuguese\"\nrecipes.loc[recipes[\"cuisine\"] == \"switzerland\", \"cuisine\"] = \"swiss\"\nrecipes.loc[recipes[\"cuisine\"] == \"thailand\", \"cuisine\"] = \"thai\"\nrecipes.loc[recipes[\"cuisine\"] == \"turkey\", \"cuisine\"] = \"turkish\"\nrecipes.loc[recipes[\"cuisine\"] == \"vietnam\", \"cuisine\"] = \"vietnamese\"\nrecipes.loc[recipes[\"cuisine\"] == \"uk-and-ireland\", \"cuisine\"] = \"uk-and-irish\"\nrecipes.loc[recipes[\"cuisine\"] == \"irish\", \"cuisine\"] = \"uk-and-irish\"\n\nrecipes"]},{"cell_type":"markdown","id":"2ff73a8a-4dd7-4303-994f-6235011c7519","metadata":{},"outputs":[],"source":["Remove cuisines with \u003c 50 recipes.\n"]},{"cell_type":"code","id":"fbab46ef-8792-4382-a6a8-7153af065ce7","metadata":{},"outputs":[],"source":["# get list of cuisines to keep\nrecipes_counts = recipes[\"cuisine\"].value_counts()\ncuisines_indices = recipes_counts \u003e 50\n\ncuisines_to_keep = list(np.array(recipes_counts.index.values)[np.array(cuisines_indices)])"]},{"cell_type":"code","id":"8218d176-1f47-4726-bb17-95e3cf953a92","metadata":{},"outputs":[],"source":["rows_before = recipes.shape[0] # number of rows of original dataframe\nprint(\"Number of rows of original dataframe is {}.\".format(rows_before))\n\nrecipes = recipes.loc[recipes['cuisine'].isin(cuisines_to_keep)]\n\nrows_after = recipes.shape[0] # number of rows of processed dataframe\nprint(\"Number of rows of processed dataframe is {}.\".format(rows_after))\n\nprint(\"{} rows removed!\".format(rows_before - rows_after))"]},{"cell_type":"markdown","id":"7a11aef2-1837-4e29-94eb-09818361326e","metadata":{},"outputs":[],"source":["Convert all Yes's to 1's and the No's to 0's\n"]},{"cell_type":"code","id":"ecec707e-b487-4c1f-b23e-9efbd8cacca1","metadata":{},"outputs":[],"source":["recipes = recipes.replace(to_replace=\"Yes\", value=1)\nrecipes = recipes.replace(to_replace=\"No\", value=0)"]},{"cell_type":"markdown","id":"66ca66e2-b04b-4b2c-90f3-d310d68d71f5","metadata":{},"outputs":[],"source":["#### Let's analyze the data a little more in order to learn the data better and note any interesting preliminary observations.\n"]},{"cell_type":"markdown","id":"d08627d3-c689-497c-8574-30b357171880","metadata":{},"outputs":[],"source":["Run the following cell to get the recipes that contain **rice** *and* **soy** *and* **wasabi** *and* **seaweed**.\n"]},{"cell_type":"code","id":"7becdd34-eb6e-4bca-9394-eb68e36be6e4","metadata":{},"outputs":[],"source":["recipes.head()"]},{"cell_type":"code","id":"0e468874-9b3f-4d93-ba2f-3ef90cdac4cb","metadata":{},"outputs":[],"source":["check_recipes = recipes.loc[\n    (recipes[\"rice\"] == 1) \u0026\n    (recipes[\"soy_sauce\"] == 1) \u0026\n    (recipes[\"wasabi\"] == 1) \u0026\n    (recipes[\"seaweed\"] == 1)\n]\n\ncheck_recipes"]},{"cell_type":"markdown","id":"ed957faf-a611-4a2f-a1da-0c10ea60e303","metadata":{},"outputs":[],"source":["Based on the results of the above code, can we classify all recipes that contain **rice** *and* **soy** *and* **wasabi** *and* **seaweed** as **Japanese** recipes? Why?\n"]},{"cell_type":"raw","id":"509c4ad1-bd8d-40f9-9f35-82c403716269","metadata":{},"outputs":[],"source":["Your Answer:"]},{"cell_type":"markdown","id":"c905403d-93bd-4f72-b597-84188c9427a3","metadata":{},"outputs":[],"source":["\u003cdetails\u003e\u003csummary\u003eClick here for a solution\u003c/summary\u003e\n","\n","```python\n","   #The correct answer is:\n","    \n","    No, because other recipes such as Asian and East_Asian recipes also contain these ingredients.\n","```\n","\n","\u003c/details\u003e\n"]},{"cell_type":"markdown","id":"7e376608-086b-4f0d-8f86-494357219067","metadata":{},"outputs":[],"source":["Let's count the ingredients across all recipes.\n"]},{"cell_type":"code","id":"e4a7c68b-425d-4946-8d79-13dfc594b4f5","metadata":{},"outputs":[],"source":["# sum each column\ning = recipes.iloc[:, 1:].sum(axis=0)"]},{"cell_type":"code","id":"cd87ee11-5f65-48c9-8314-7aeab298fddd","metadata":{},"outputs":[],"source":["# define each column as a pandas series\ningredient = pd.Series(ing.index.values, index = np.arange(len(ing)))\ncount = pd.Series(list(ing), index = np.arange(len(ing)))\n\n# create the dataframe\ning_df = pd.DataFrame(dict(ingredient = ingredient, count = count))\ning_df = ing_df[[\"ingredient\", \"count\"]]\nprint(ing_df.to_string())"]},{"cell_type":"markdown","id":"5aaa34aa-8987-471c-984b-f0949d58d3eb","metadata":{},"outputs":[],"source":["Now we have a dataframe of ingredients and their total counts across all recipes. Let's sort this dataframe in descending order.\n"]},{"cell_type":"code","id":"7a3d9604-b215-4dfc-913d-7933c42e0e43","metadata":{},"outputs":[],"source":["ing_df.sort_values([\"count\"], ascending=False, inplace=True)\ning_df.reset_index(inplace=True, drop=True)\n\nprint(ing_df)"]},{"cell_type":"markdown","id":"182a9344-ab02-4262-b5a6-0fdecb3eb09b","metadata":{},"outputs":[],"source":["#### What are the 3 most popular ingredients?\n"]},{"cell_type":"raw","id":"58fa8625-321a-4a42-a0e3-c259a47eff7e","metadata":{},"outputs":[],"source":["Your Answer:\n1.\n\n2.\n\n3."]},{"cell_type":"markdown","id":"b443285a-b9de-471e-af01-3896b3841554","metadata":{},"outputs":[],"source":["\u003cdetails\u003e\u003csummary\u003eClick here for a solution\u003c/summary\u003e\n","\n","   1. Egg with \u003cstrong\u003e21,025\u003c/strong\u003e occurrences. \n","\n","   2. Wheat with \u003cstrong\u003e20,781\u003c/strong\u003e occurrences. \n","\n","   3. Butter with \u003cstrong\u003e20,719\u003c/strong\u003e occurrences.\n","\n","\n","\u003c/details\u003e\n"]},{"cell_type":"markdown","id":"8154072a-284e-4189-a15c-39bfebe9fa87","metadata":{},"outputs":[],"source":["However, note that there is a problem with the above table. There are ~40,000 American recipes in our dataset, which means that the data is biased towards American ingredients.\n"]},{"cell_type":"markdown","id":"50bc7c67-d316-4c61-910e-498e62b9741f","metadata":{},"outputs":[],"source":["**Therefore**, let's compute a more objective summary of the ingredients by looking at the ingredients per cuisine.\n"]},{"cell_type":"markdown","id":"79a99f66-ef7c-4fa4-9fec-ff161ed07bd3","metadata":{},"outputs":[],"source":["#### Let's create a *profile* for each cuisine.\n","\n","In other words, let's try to find out what ingredients Chinese people typically use, and what is **Canadian** food for example.\n"]},{"cell_type":"code","id":"66c0e910-3a39-4ec8-a349-11918ff209c3","metadata":{},"outputs":[],"source":["cuisines = recipes.groupby(\"cuisine\").mean()\ncuisines.head()"]},{"cell_type":"markdown","id":"1078f6cf-0cc6-4324-acfe-6a72b17669fd","metadata":{},"outputs":[],"source":["As shown above, we have just created a dataframe where each row is a cuisine and each column (except for the first column) is an ingredient, and the row values represent the percentage of each ingredient in the corresponding cuisine.\n","\n","**For example**:\n","\n","* *almond* is present across 15.65% of all of the **African** recipes.\n","* *butter* is present across 38.11% of all of the **Canadian** recipes.\n"]},{"cell_type":"markdown","id":"7b927dc5-784c-4092-b5d6-fe1a0d70dab4","metadata":{},"outputs":[],"source":["Let's print out the profile for each cuisine by displaying the top four ingredients in each cuisine.\n"]},{"cell_type":"code","id":"2b54ea1a-5ec6-4a89-b342-460e675a4991","metadata":{},"outputs":[],"source":["num_ingredients = 4 # define number of top ingredients to print\n\n# define a function that prints the top ingredients for each cuisine\ndef print_top_ingredients(row):\n    print(row.name.upper())\n    row_sorted = row.sort_values(ascending=False)*100\n    top_ingredients = list(row_sorted.index.values)[0:num_ingredients]\n    row_sorted = list(row_sorted)[0:num_ingredients]\n\n    for ind, ingredient in enumerate(top_ingredients):\n        print(\"%s (%d%%)\" % (ingredient, row_sorted[ind]), end=' ')\n    print(\"\\n\")\n\n# apply function to cuisines dataframe\ncreate_cuisines_profiles = cuisines.apply(print_top_ingredients, axis=1)"]},{"cell_type":"markdown","id":"9055e278-38d3-4847-8aac-8b83185ce35d","metadata":{},"outputs":[],"source":["At this point, we feel that we have understood the data well and the data is ready and is in the right format for modeling!\n","\n","-----------\n"]},{"cell_type":"markdown","id":"2d29eaf1-f88d-4388-8458-650cee4f24ed","metadata":{},"outputs":[],"source":["### Thank you for completing this lab!\n","\n","## Author\n","\n","\u003ca href=\"https://www.linkedin.com/in/aklson/\" target=\"_blank\"\u003eAlex Aklson\u003c/a\u003e\n","\n","\n","\n","## Change Log\n","\n","\n","|  Date (YYYY-MM-DD) |  Version | Changed By  |  Change Description |\n","|---|---|---|---|\n","| 2023-08-25 | 2.3 | Patsy | Aligned text for clarity. Fixed minor typos. Updated copyright to remove year.|\n","| 2021-04-06 | 2.2 | Malika | Updated data set link |\n","| 2020-09-23  | 2.1  | Lakshmi  | Fixed Typo errors |\n","| 2020-08-27  | 2.0  | Lavanya  |  Moved lab to course repo in GitLab |\n","\n","\n","\u003chr\u003e\n","\n","## \u003ch3 align=\"center\"\u003e © IBM Corporation. All rights reserved. \u003ch3/\u003e\n"]}],"metadata":{"kernelspec":{"display_name":"Python","language":"python","name":"conda-env-python-py"},"language_info":{"name":""}},"nbformat":4,"nbformat_minor":4}