{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Exploratory Data Analysis Of Recruit Restaurant Visitor Forecasting\n\nIn this notebook, I'm going to analyze the datasets from the Kaggle competition \"Recruit Restaurant Visitor Forecasting\". The data comes in the shape of 8 relational files which are derived from two separate Japanese websites that collect user information: “Hot Pepper Gourmet (hpg): similar to Yelp” (search and reserve) and “AirREGI / Restaurant Board (air): similar to Square” (reservation control and cash register). The competition asks us to predict restaurant reservations but in this notebook I'm only going to analyze the data and get some insights that might be useful for predictions later on. ","metadata":{}},{"cell_type":"markdown","source":"### 1. Asking questions","metadata":{}},{"cell_type":"markdown","source":"Before moving on to the analysis, I'll generate some key business questions that I'd like to answer from analyzing this data. These questions are:\n\n1) What's the distribution of total number of visitors per day? \n\n2) What's the median number of visitors per day of the week and month? \n\n3) How our reservations data compares to the actual visitor numbers?\n\n4) What are the most common types of cuisine? \n\n5) What the areas with most restaurants? \n\n6) What's the distribution of holidays through the year? \n\n7) What's the average number of visitors by restaurant type? \n ","metadata":{}},{"cell_type":"markdown","source":"### 2. Prepare & Preprocess Data","metadata":{}},{"cell_type":"code","source":"# Import necessary libraries\nimport pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport datetime","metadata":{"_uuid":"c11f584b-6e19-4d9d-84b4-d6b742ecd47e","_cell_guid":"a690ef1b-e5ed-43e9-a998-741669b5eeb3","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2022-07-20T18:20:52.367342Z","iopub.execute_input":"2022-07-20T18:20:52.368050Z","iopub.status.idle":"2022-07-20T18:20:53.313185Z","shell.execute_reply.started":"2022-07-20T18:20:52.367953Z","shell.execute_reply":"2022-07-20T18:20:53.312280Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Import data \nweather_data_df = pd.read_csv(\"../input/recruit-restaurant-visitor-forecasting-data/WeatherData.csv\")\nair_reserve_df = pd.read_csv(\"../input/recruit-restaurant-visitor-forecasting-data/air_reserve.csv\")\nair_store_info_df = pd.read_csv(\"../input/recruit-restaurant-visitor-forecasting-data/air_store_info.csv\")\nair_visit_df = pd.read_csv(\"../input/recruit-restaurant-visitor-forecasting-data/air_visit_data.csv\")\narea_name_mapping_df = pd.read_csv(\"../input/recruit-restaurant-visitor-forecasting-data/area_name_mapping.csv\")\ndate_info_df = pd.read_csv(\"../input/recruit-restaurant-visitor-forecasting-data/date_info.csv\")\nhpg_reserve_df = pd.read_csv(\"../input/recruit-restaurant-visitor-forecasting-data/hpg_reserve.csv\")\nhpg_reserve_info_df = pd.read_csv(\"../input/recruit-restaurant-visitor-forecasting-data/hpg_store_info.csv\")\nhpg_store_info_df = pd.read_csv(\"../input/recruit-restaurant-visitor-forecasting-data/hpg_store_info.csv\")\nsample_submission_df = pd.read_csv(\"../input/recruit-restaurant-visitor-forecasting-data/sample_submission.csv\")\nstore_id_relation_df = pd.read_csv(\"../input/recruit-restaurant-visitor-forecasting-data/store_id_relation.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-07-20T18:20:53.314717Z","iopub.execute_input":"2022-07-20T18:20:53.315015Z","iopub.status.idle":"2022-07-20T18:20:56.745888Z","shell.execute_reply.started":"2022-07-20T18:20:53.314986Z","shell.execute_reply":"2022-07-20T18:20:56.744928Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Name dfs\nweather_data_df.name = \"weather_data_df\"\nair_reserve_df.name = \"air_reserve_df\"\nair_store_info_df.name = \"air_store_info_df\"\nair_visit_df.name = \"air_visit_df\"\narea_name_mapping_df.name = \"area_name_mapping_df\"\ndate_info_df.name = \"date_info_df\"\nhpg_reserve_df.name = \"hpg_reserve_df\"\nhpg_reserve_info_df.name = \"hpg_reserve_info_df\"\nhpg_store_info_df.name = \"hpg_store_info_df\"\nsample_submission_df.name = \"sample_submission_df\"\nsample_submission_df.name = \"sample_submission_df\"","metadata":{"execution":{"iopub.status.busy":"2022-07-20T18:20:56.749392Z","iopub.execute_input":"2022-07-20T18:20:56.749830Z","iopub.status.idle":"2022-07-20T18:20:56.760446Z","shell.execute_reply.started":"2022-07-20T18:20:56.749786Z","shell.execute_reply":"2022-07-20T18:20:56.759397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# This function will check if there is missing values and give key info about each dataset\ndef data_checking(dataframes):\n    for df in dataframes:\n        print(\"Name Of Dataset: {}\".format(df.name))\n        print(\"Info about Dataset :\")\n        print(\"Shape of Dataset :{}\".format(df.shape))\n        print(\"First 2 rows of dataset:\")\n        print(df.head(2))\n        df.info()\n        print(\"Missing_Values:\")\n        print(round(df.isna().sum() / len(df), 2))\n        print(\"Stats:\")\n        print(df.describe())\n        print(\"**\"*50)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T18:20:56.762000Z","iopub.execute_input":"2022-07-20T18:20:56.762343Z","iopub.status.idle":"2022-07-20T18:20:56.771390Z","shell.execute_reply.started":"2022-07-20T18:20:56.762313Z","shell.execute_reply":"2022-07-20T18:20:56.770549Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfs = [weather_data_df, air_reserve_df, air_store_info_df, air_visit_df, \n       area_name_mapping_df, date_info_df, hpg_reserve_df, hpg_reserve_info_df]\n\ndata_checking(dfs)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T18:20:56.772722Z","iopub.execute_input":"2022-07-20T18:20:56.773025Z","iopub.status.idle":"2022-07-20T18:20:57.892739Z","shell.execute_reply.started":"2022-07-20T18:20:56.772996Z","shell.execute_reply":"2022-07-20T18:20:57.891812Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"All of our datasets with the exception of weatherdata have no missing values. We notice though an issue with dates that are not in the correct format. So we need to fix this. ","metadata":{}},{"cell_type":"code","source":"# Fixing date format\nfor df in dfs:\n    for col in df.columns:\n        if \"date\" in col:\n            df[col] = pd.to_datetime(df[col])        ","metadata":{"execution":{"iopub.status.busy":"2022-07-20T18:20:57.895828Z","iopub.execute_input":"2022-07-20T18:20:57.896101Z","iopub.status.idle":"2022-07-20T18:21:01.466099Z","shell.execute_reply.started":"2022-07-20T18:20:57.896073Z","shell.execute_reply":"2022-07-20T18:21:01.464982Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### 3. Analyze","metadata":{}},{"cell_type":"markdown","source":"**A) Air System**","metadata":{}},{"cell_type":"code","source":"# What's the distribution of total number of visitors per day?\nplt.figure(figsize=(12,8))\nsns.lineplot(data=air_visit_df.groupby(\"visit_date\")[\"visitors\"].sum().reset_index(), x=\"visit_date\", y=\"visitors\")\nplt.xticks(rotation=45)\nplt.title(\"Total N° Of Visitors per day\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T18:21:01.467546Z","iopub.execute_input":"2022-07-20T18:21:01.467837Z","iopub.status.idle":"2022-07-20T18:21:01.795182Z","shell.execute_reply.started":"2022-07-20T18:21:01.467810Z","shell.execute_reply":"2022-07-20T18:21:01.794414Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Before 07/2016, the number of visitors ranged between 4000 and 8000. Starting from 07/2016, the number of visitors sharply increased and started ranging between 10000 and 23000.","metadata":{}},{"cell_type":"code","source":"# What's the distribution of median number of visitors per week?\n# Add col for dayofweek\nair_visit_df[\"dayofweek\"] = [day.day_name() for day in air_visit_df[\"visit_date\"]]\n# Plot results\nplt.figure(figsize=(12,8))\nsns.barplot(data=air_visit_df.groupby(\"dayofweek\")[\"visitors\"].median().reset_index().sort_values(\"visitors\"), x=\"dayofweek\", y=\"visitors\")\nplt.xticks(rotation=45)\nplt.title(\"Median N° Of Visitors per dayofweek\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T18:21:01.797179Z","iopub.execute_input":"2022-07-20T18:21:01.797461Z","iopub.status.idle":"2022-07-20T18:21:05.778424Z","shell.execute_reply.started":"2022-07-20T18:21:01.797426Z","shell.execute_reply":"2022-07-20T18:21:05.777431Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Without a surpirse, weekends see most number of visitors. The peak is on saturdays. ","metadata":{}},{"cell_type":"code","source":"# What's the distribution of median number of visitors per month?\n# Add col for dayofweek\nair_visit_df[\"month\"] = [day.month_name() for day in air_visit_df[\"visit_date\"]]\n# Plot results\nplt.figure(figsize=(12,8))\nsns.barplot(data=air_visit_df.groupby(\"month\")[\"visitors\"].median().reset_index().sort_values(\"visitors\"), x=\"month\", y=\"visitors\")\nplt.xticks(rotation=45)\nplt.title(\"Median N° Of Visitors per month\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T18:21:05.780454Z","iopub.execute_input":"2022-07-20T18:21:05.780780Z","iopub.status.idle":"2022-07-20T18:21:10.008148Z","shell.execute_reply.started":"2022-07-20T18:21:05.780746Z","shell.execute_reply":"2022-07-20T18:21:10.007150Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The period of year where there are most visitors are spring and december.","metadata":{}},{"cell_type":"code","source":"# Distribution of visitors\nplt.figure(figsize=(12,8))\nsns.distplot(air_visit_df['visitors'])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T18:21:10.009356Z","iopub.execute_input":"2022-07-20T18:21:10.009660Z","iopub.status.idle":"2022-07-20T18:21:11.426950Z","shell.execute_reply.started":"2022-07-20T18:21:10.009630Z","shell.execute_reply":"2022-07-20T18:21:11.425962Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Most air visitors range between 0 and 100 with some rare values beyond that. ","metadata":{}},{"cell_type":"markdown","source":"How our reservations data compares to the actual visitor numbers?","metadata":{}},{"cell_type":"code","source":"# Plot results\nplt.figure(figsize=(12,8))\nair_reserve_grouped = air_reserve_df.groupby(air_reserve_df[\"visit_datetime\"].dt.date)[\"reserve_visitors\"].sum().reset_index().sort_values(\"reserve_visitors\")\nsns.lineplot(data=air_reserve_grouped, x=\"visit_datetime\", y=\"reserve_visitors\")\nplt.xticks(rotation=45)\nplt.title(\"Visitors per month\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T18:21:11.428415Z","iopub.execute_input":"2022-07-20T18:21:11.428816Z","iopub.status.idle":"2022-07-20T18:21:11.774991Z","shell.execute_reply.started":"2022-07-20T18:21:11.428770Z","shell.execute_reply":"2022-07-20T18:21:11.774012Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The actual total number of visitors who reserved correlates with visitors. We can see a deep in visitors during holidays and around May 2017.","metadata":{}},{"cell_type":"code","source":"# Distribution of visitors by hour\nplt.figure(figsize=(12,8))\nhourly_air_reserve_grouped = air_reserve_df.groupby(air_reserve_df[\"visit_datetime\"].dt.hour)[\"reserve_visitors\"].sum().reset_index().sort_values(\"reserve_visitors\")\nsns.barplot(data=hourly_air_reserve_grouped, x=\"visit_datetime\", y=\"reserve_visitors\")\nplt.xticks(rotation=45)\nplt.title(\"Visitors per hour\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T18:21:11.776338Z","iopub.execute_input":"2022-07-20T18:21:11.776716Z","iopub.status.idle":"2022-07-20T18:21:12.112145Z","shell.execute_reply.started":"2022-07-20T18:21:11.776599Z","shell.execute_reply":"2022-07-20T18:21:12.111388Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Air visitors seems to enjoy going to restaurant during the evening. The peak of visits is at 18.","metadata":{}},{"cell_type":"code","source":"# Time from reservation to visit (hours)\nair_reserve_df[\"delta\"] = (air_reserve_df[\"visit_datetime\"] - air_reserve_df[\"reserve_datetime\"]).dt.total_seconds() / 3600\n# Plot delta distribution \nplt.figure(figsize=(12,8))\nsns.distplot(air_reserve_df[\"delta\"][(air_reserve_df['delta'] >= 0) & (air_reserve_df['delta'] <= 189)])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T18:21:12.113399Z","iopub.execute_input":"2022-07-20T18:21:12.113984Z","iopub.status.idle":"2022-07-20T18:21:12.774765Z","shell.execute_reply.started":"2022-07-20T18:21:12.113940Z","shell.execute_reply":"2022-07-20T18:21:12.773718Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"air_reserve_df.delta.describe()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T18:21:12.776063Z","iopub.execute_input":"2022-07-20T18:21:12.776484Z","iopub.status.idle":"2022-07-20T18:21:12.789554Z","shell.execute_reply.started":"2022-07-20T18:21:12.776448Z","shell.execute_reply":"2022-07-20T18:21:12.788394Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We can see that the mean time between reservation and visit is very large 199 Hours which is more than 8 days. But since there are many outliers in this data, we would prefer using the median which gives a median delta of little bit more than 2 days. ","metadata":{}},{"cell_type":"markdown","source":"**B) HPG System**","metadata":{}},{"cell_type":"code","source":"# What's the distribution of total number of visitors per day?\nplt.figure(figsize=(12,8))\nhpg_reserve_df_grouped = hpg_reserve_df.groupby(hpg_reserve_df[\"visit_datetime\"].dt.date)[\"reserve_visitors\"].sum().reset_index().sort_values(\"reserve_visitors\")\nsns.lineplot(data=hpg_reserve_df_grouped, x=\"visit_datetime\", y=\"reserve_visitors\")\nplt.xticks(rotation=45)\nplt.title(\"Total Visitors per month\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T18:21:12.791110Z","iopub.execute_input":"2022-07-20T18:21:12.791482Z","iopub.status.idle":"2022-07-20T18:21:14.642860Z","shell.execute_reply.started":"2022-07-20T18:21:12.791452Z","shell.execute_reply":"2022-07-20T18:21:14.641732Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The trend for total number of visitors for HPG seem to be more stable especially between Jan and Nov 2016. Then we can see a significant jump at around Dec until Jan 2017. This might be explained by end of year holidays. We can also abserve a significant dip around May 2017. ","metadata":{}},{"cell_type":"code","source":"# Distribution of visitors by hour\nplt.figure(figsize=(12,8))\nhourly_hpg_reserve_grouped = hpg_reserve_df.groupby(hpg_reserve_df[\"visit_datetime\"].dt.hour)[\"reserve_visitors\"].sum().reset_index().sort_values(\"reserve_visitors\")\nsns.barplot(data=hourly_hpg_reserve_grouped, x=\"visit_datetime\", y=\"reserve_visitors\")\nplt.xticks(rotation=45)\nplt.title(\"Total Visitors per hour\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T18:21:14.644346Z","iopub.execute_input":"2022-07-20T18:21:14.644684Z","iopub.status.idle":"2022-07-20T18:21:15.205046Z","shell.execute_reply.started":"2022-07-20T18:21:14.644651Z","shell.execute_reply":"2022-07-20T18:21:15.204088Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"HPG hourly reservation distribution is almost exactly like Air system. With the exception that for HPG tend to visit a bit late than Air with the peak of visits at 19 H. ","metadata":{}},{"cell_type":"code","source":"# Time from reservation to visit (hours)\nhpg_reserve_df[\"delta\"] = (hpg_reserve_df[\"visit_datetime\"] - hpg_reserve_df[\"reserve_datetime\"]).dt.total_seconds() / 3600\n# Plot delta distribution \nplt.figure(figsize=(12,8))\nsns.distplot(hpg_reserve_df[\"delta\"][(hpg_reserve_df['delta'] >= 0) & (hpg_reserve_df['delta'] <= 189)])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T18:21:15.206382Z","iopub.execute_input":"2022-07-20T18:21:15.206686Z","iopub.status.idle":"2022-07-20T18:21:22.401745Z","shell.execute_reply.started":"2022-07-20T18:21:15.206656Z","shell.execute_reply":"2022-07-20T18:21:22.400710Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The delta for HPG is significantly lower than Air's. With a mean delta of 1.78 Hours. ","metadata":{}},{"cell_type":"code","source":"hpg_reserve_df[\"delta\"].describe()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T18:21:22.403302Z","iopub.execute_input":"2022-07-20T18:21:22.403805Z","iopub.status.idle":"2022-07-20T18:21:22.485717Z","shell.execute_reply.started":"2022-07-20T18:21:22.403750Z","shell.execute_reply":"2022-07-20T18:21:22.484796Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"What are the most common types of cuisine?","metadata":{}},{"cell_type":"code","source":"# Most common types of cuisine for Air\nplt.figure(figsize=(12,8))\nair_store_info_df_grouped = pd.DataFrame(air_store_info_df[[\"air_genre_name\" ]].groupby(\"air_genre_name\")[\"air_genre_name\"].count().sort_values(ascending=False))\nsns.barplot(data=air_store_info_df_grouped, x='air_genre_name', y=air_store_info_df_grouped.index)\nplt.title(\"Most common types of cuisine for Air\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T18:21:22.486937Z","iopub.execute_input":"2022-07-20T18:21:22.487219Z","iopub.status.idle":"2022-07-20T18:21:22.764981Z","shell.execute_reply.started":"2022-07-20T18:21:22.487192Z","shell.execute_reply":"2022-07-20T18:21:22.764159Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Wide variety of cuisine choice is available. Foreign cuisine doesn't seem to be popular with the exception of Italian/French. ","metadata":{}},{"cell_type":"code","source":"# TOP 15 Areas for Air Restaurants\nplt.figure(figsize=(12,8))\nair_store_info_df_grouped = pd.DataFrame(air_store_info_df[[\"air_area_name\" ]].groupby(\"air_area_name\")[\"air_area_name\"].count().sort_values(ascending=False))[:15]\nsns.barplot(data=air_store_info_df_grouped, x='air_area_name', y=air_store_info_df_grouped.index)\nplt.title(\"Locations with most restaurants for Air\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T18:21:22.766150Z","iopub.execute_input":"2022-07-20T18:21:22.766432Z","iopub.status.idle":"2022-07-20T18:21:23.208957Z","shell.execute_reply.started":"2022-07-20T18:21:22.766406Z","shell.execute_reply":"2022-07-20T18:21:23.208023Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Most common types of cuisine for HPG\nplt.figure(figsize=(12,8))\nhpg_store_info_df_grouped = pd.DataFrame(hpg_store_info_df[[\"hpg_genre_name\" ]].groupby(\"hpg_genre_name\")[\"hpg_genre_name\"].count().sort_values(ascending=False))\nsns.barplot(data=hpg_store_info_df_grouped, x='hpg_genre_name', y=hpg_store_info_df_grouped.index)\nplt.title(\"Most common types of cuisine for HPG\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T18:21:23.210173Z","iopub.execute_input":"2022-07-20T18:21:23.210470Z","iopub.status.idle":"2022-07-20T18:21:23.685316Z","shell.execute_reply.started":"2022-07-20T18:21:23.210441Z","shell.execute_reply":"2022-07-20T18:21:23.684337Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"In HPG system, Japanese and International cuisine are very popular. ","metadata":{}},{"cell_type":"code","source":"# TOP 15 Areas for HPG Restaurants\nplt.figure(figsize=(12,8))\nhpg_store_info_df_grouped = pd.DataFrame(hpg_store_info_df[[\"hpg_area_name\" ]].groupby(\"hpg_area_name\")[\"hpg_area_name\"].count().sort_values(ascending=False))[:15]\nsns.barplot(data=hpg_store_info_df_grouped, x='hpg_area_name', y=hpg_store_info_df_grouped.index)\nplt.title(\"Locations with most restaurants for HPG\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T18:21:23.686763Z","iopub.execute_input":"2022-07-20T18:21:23.687158Z","iopub.status.idle":"2022-07-20T18:21:24.026557Z","shell.execute_reply.started":"2022-07-20T18:21:23.687118Z","shell.execute_reply":"2022-07-20T18:21:24.025739Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"What's the distribution of holidays through the year? ","metadata":{}},{"cell_type":"code","source":"# Plot\ndate_info_df[\"holiday_flg\"].value_counts().plot(kind=\"bar\")\nplt.title(\"holiday_dist\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T18:21:24.029222Z","iopub.execute_input":"2022-07-20T18:21:24.029684Z","iopub.status.idle":"2022-07-20T18:21:24.171348Z","shell.execute_reply.started":"2022-07-20T18:21:24.029647Z","shell.execute_reply":"2022-07-20T18:21:24.170246Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"date_info_df[\"holiday_flg\"].value_counts(normalize=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-20T18:21:24.173051Z","iopub.execute_input":"2022-07-20T18:21:24.173355Z","iopub.status.idle":"2022-07-20T18:21:24.182178Z","shell.execute_reply.started":"2022-07-20T18:21:24.173325Z","shell.execute_reply":"2022-07-20T18:21:24.180985Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Around 7% of our dataset is composed of holidays. ","metadata":{}},{"cell_type":"markdown","source":"What's the average number of visitors by restaurant type? ","metadata":{}},{"cell_type":"code","source":"# First, we need to join the air_reserve_df to air_store_info_df\nair_store_joined = air_visit_df.merge(air_store_info_df, on='air_store_id', how='left')","metadata":{"execution":{"iopub.status.busy":"2022-07-20T18:21:24.183526Z","iopub.execute_input":"2022-07-20T18:21:24.184114Z","iopub.status.idle":"2022-07-20T18:21:24.271877Z","shell.execute_reply.started":"2022-07-20T18:21:24.184070Z","shell.execute_reply":"2022-07-20T18:21:24.270596Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Then we need to use facet grid in order to visualize the results \navg_vis_by_type_air = air_store_joined.groupby([\"visit_date\",\"air_genre_name\"])[\"visitors\"].mean().reset_index()\n# Plot results\ngrid = sns.FacetGrid(avg_vis_by_type_air, col='air_genre_name',col_wrap=4)\ngrid.map(sns.lineplot, 'visit_date', 'visitors')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-20T18:21:24.273352Z","iopub.execute_input":"2022-07-20T18:21:24.273781Z","iopub.status.idle":"2022-07-20T18:21:28.541173Z","shell.execute_reply.started":"2022-07-20T18:21:24.273739Z","shell.execute_reply":"2022-07-20T18:21:28.540162Z"},"trusted":true},"execution_count":null,"outputs":[]}]}