text_html_output_1.png
import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

import seaborn as sns

india_nutrition_facts = pd.read_csv('../input/mcdonalds-india-menu-nutrition-facts/India_Menu.csv')

def highlight_color(s):
    return ['background-color: #FFC72C'] * 8 if s.name == 'Trans fat (g)' else [''] * 8
india_nutrition_facts.describe().style.apply(highlight_color, axis=0)

fig, axs = plt.subplots(figsize=(15,8))
plt.rcParams.update({'font.size': 9.5})
ax = [None for _ in range(10)]

df_num_features = india_nutrition_facts.select_dtypes(include=[np.number])
num_features = df_num_features.columns.tolist()
num_features.remove("Trans fat (g)")

for i in range(len(num_features)):
    ax[i] = plt.subplot2grid((3,5), (i//3,i%3), colspan=1)
    ax[i] = sns.violinplot(data=india_nutrition_facts[num_features[i]], orient="h", color='#FFC72C')
    plt.title(num_features[i])

ax[9] = fig.add_axes([0.62,0.232,0.38,0.5])
ax[9] = sns.violinplot(data=india_nutrition_facts["Trans fat (g)"], orient="h", color='#DA291C')
plt.title("Trans fat (g)", fontweight="bold")

plt.suptitle("Distribution of the Content of Each Nutrition", fontsize=15)
plt.tight_layout()
plt.show()

del df_num_features

def highlight_color(s):
    return ['background-color: #FFC72C'] * 13 if s.name == 25 else [''] * 13
india_nutrition_facts[india_nutrition_facts['Menu Items'].str.endswith('Chicken Strips')].style.apply(highlight_color, axis=1)

for c in ['Trans fat (g)', 'Total carbohydrate (g)', 'Cholesterols (mg)', 'Sat Fat (g)']:
    india_nutrition_facts.loc[25, c] = india_nutrition_facts.loc[24, c] * 5 / 3
def highlight_color(s):
    return ['background-color: #FFC72C'] * 13 if s.name == 25 else [''] * 13
india_nutrition_facts[india_nutrition_facts['Menu Items'].str.endswith('Chicken Strips')].style.apply(highlight_color, axis=1)

index = india_nutrition_facts[india_nutrition_facts['Sodium (mg)'].isna()].index.tolist()[0]
india_nutrition_facts.loc[index, 'Sodium (mg)'] = 1370.89

food_nutrition_facts = india_nutrition_facts[india_nutrition_facts['Per Serve Size'].str.endswith('g')]
food_nutrition_facts['Per Serve Size'] = food_nutrition_facts['Per Serve Size'].str.replace(' g', '').astype(float)
food_nutrition_facts.rename(columns={'Per Serve Size': 'Per Serve Size (g)'}, inplace=True)
condiment_nutrition_facts = food_nutrition_facts[food_nutrition_facts['Menu Category'] == 'Condiments Menu']
food_nutrition_facts = food_nutrition_facts[food_nutrition_facts['Menu Category'] != 'Condiments Menu']

drink_nutrition_facts = india_nutrition_facts[india_nutrition_facts['Per Serve Size'].str.endswith('ml')]
drink_nutrition_facts['Per Serve Size'] = drink_nutrition_facts['Per Serve Size'].str.replace(' ml', '').astype(float)
drink_nutrition_facts.rename(columns={'Per Serve Size': 'Per Serve Size (ml)'}, inplace=True)

def add_daily_value_features(df, cal):
    nutrition_daily_value = ['Energy (kCal)', 'Protein (g)', 'Total fat (g)', 'Sat Fat (g)', 'Trans fat (g)', 'Total carbohydrate (g)', 'Added Sugars (g)']
    max_dv_percentage = [None, 20, 30, 10, 1, 50, 2.5]
    for i in range(len(nutrition_daily_value)):
        if 'Energy' in nutrition_daily_value[i]:
            nutrition_dv_name = nutrition_daily_value[i].replace('(kCal)', '')
        else:
            nutrition_dv_name = nutrition_daily_value[i].replace('(g)', '')
        nutrition_dv_name = nutrition_dv_name + '(% Daily Value) - ' + str(cal) + ' kCal'
        value = 0.0
        if 'Energy' in nutrition_dv_name:
            value = df[nutrition_daily_value[i]] / cal * 100
        elif 'Protein' in nutrition_dv_name or 'carbohydrate' in nutrition_dv_name:
            value = df[nutrition_daily_value[i]] * 4 / (cal * max_dv_percentage[i] / 100) * 100
        elif 'Fat' in nutrition_dv_name or 'fat' in nutrition_dv_name:
            value = df[nutrition_daily_value[i]] * 9 / (cal * max_dv_percentage[i] / 100) * 100
        elif 'Sugars' in nutrition_dv_name:
            value = df[nutrition_daily_value[i]] / (cal * max_dv_percentage[i] / 100) * 100
        df[nutrition_dv_name] = round(value, 2)
    df['Cholesterols (% Daily Value)'] = round(df['Cholesterols (mg)'] / 300 * 100, 2)
    df['Sodium (% Daily Value)'] = round(df['Sodium (mg)'] / 2300 * 100, 2)
    return df

food_nutrition_facts = add_daily_value_features(food_nutrition_facts, 1500)
drink_nutrition_facts = add_daily_value_features(drink_nutrition_facts, 1500)
condiment_nutrition_facts = add_daily_value_features(condiment_nutrition_facts, 1500)

drink_nutrition_facts.head()