image_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

df_check_ratio = india_nutrition_facts[india_nutrition_facts['Menu Items'].str.endswith('Chicken Strips')]
df_check_ratio = df_check_ratio.drop(23)
df_check_ratio['Per Serve Size'] = df_check_ratio['Per Serve Size'].str.replace(' g', '').astype(int)
df_check_ratio.rename(columns={'Per Serve Size': 'Per Serve Size (g)'}, inplace=True)
columns = df_check_ratio.columns.tolist()
for c in ['Menu Category', 'Menu Items', 'Added Sugars (g)']:
    columns.remove(c)
for c in columns:
    df_check_ratio.loc['Ratio', c] = df_check_ratio.loc[25, c] / df_check_ratio.loc[24, c]

fig, ax = plt.subplots(figsize=(15, 6))
plt.rcParams.update({'font.size': 13})
series_check_ratio = df_check_ratio.loc['Ratio', :].dropna()
series_check_ratio = series_check_ratio.apply(lambda x: np.log(x))
series_check_ratio = series_check_ratio.sort_values(ascending=False)
colors = []
for i in range(10):
    if i == 0:
        colors.append('#DA291C')
    elif i >= 7:
        colors.append('#1C75DA')
    else:
        colors.append('lightgray')
ax = sns.barplot(x=series_check_ratio, y=series_check_ratio.index, edgecolor='black', orient='hor', palette=colors)
sns.despine(top=True, right=True, left=True)
ax.tick_params(left=False)
plt.title('The Ratio of Nutrition Contents', fontsize=15, loc='left', y=1.05)
plt.tight_layout()
plt.show()