text_plain_output_1.png image_output_1.png
from matplotlib_venn import venn2

import pandas as pd

recipes = pd.read_csv('/kaggle/input/food-com-recipes-and-user-interactions/RAW_recipes.csv')
interactions = pd.read_csv('/kaggle/input/food-com-recipes-and-user-interactions/RAW_interactions.csv')

from_year, to_year = ('2008-01-01', '2017-12-31')
recipes['submitted'] = pd.to_datetime(recipes['submitted'])
recipes['submitted'] = recipes['submitted'].apply(lambda x: x.tz_localize(None))
recipes_l0y = recipes.loc[recipes['submitted'].between(from_year, to_year, inclusive=False)]
interactions['date'] = pd.to_datetime(interactions['date'])
interactions['date'] = interactions['date'].apply(lambda x: x.tz_localize(None))
interactions_l0y = interactions.loc[interactions['date'].between(from_year, to_year, inclusive=False)]

recipes_l0y = recipes_l0y.query('minutes < 1051200')

ratings_by_recipe = interactions_l0y.groupby(['recipe_id', 'year']).agg(rating_cnt=('rating', 'count'), rating_avg=('rating', 'mean'))

recipes_and_ratings = recipes_l0y.merge(ratings_by_recipe, left_on='id', right_on='recipe_id')

recipes_and_ratings['vegetarian'] = ['vegetarian' in tag for tag in recipes_and_ratings['tags']]
recipes_and_ratings['vegan'] = ['vegan' in tag for tag in recipes_and_ratings['tags']]
recipes_and_ratings = recipes_and_ratings.drop(columns=['name', 'tags', 'nutrition', 'steps', 'description', 'ingredients'])

vegetarian_cnt = len(recipes_and_ratings.query('vegetarian == True'))
vegan_cnt = len(recipes_and_ratings.query('vegan == True'))
intersect_cnt = len(recipes_and_ratings.query('vegetarian == True and vegan == True'))
venn2(subsets=(vegetarian_cnt, vegan_cnt - intersect_cnt, intersect_cnt), set_labels=('Vegatarian', 'Vegan'), set_colors=('#b7e778', '#031c16', '#031c16'), alpha=1)