{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load in \n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"31e59738cf7ec965a1a2a025d2f42a9cfa51f1da"},"cell_type":"markdown","source":"**Data Analysis**\nIn this kernel we try to do some simple insights into the training data on categorization of the resutaurant classification. I padded the labels to 9 categories and transformed them into individual columns in the dataframe with a value of N, if that category is not present in the input label and Y if that category is peresent in the lable. This rearrangement helps us to answer various questions:\n1. How many restaurants serve lunch and dinner\n2. How many restaurants serve dinner with alcohol in the outdoors and are kid friendly\n3. How mant restaurants serve dinner only and need reservations"},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"import matplotlib.pyplot as plt\n%matplotlib inline\ntrain = pd.read_csv('../input/train.csv')\ndef pad_labels(data_input):\n    results = data_input.split(' ', 9)\n    input_value = list(map(int, results))\n    padded_order = [0,1,2,3,4,5,6,7,8]\n    final_list = ['N','N','N','N','N','N','N','N','N']\n    for index, val in enumerate(padded_order):\n        if val in input_value:\n            final_list[index] = 'Y'\n    return ' '.join(e for e in final_list)\ntrain.labels.apply(str)\ntrain=train.fillna({'labels':'0'})\ntrain['padded_labels'] = train['labels'].apply(pad_labels)\ntrain['Lunch'],train['Dinner'], train['Reservations'], train['Outdoor'], train['Expensive'], train['Alcohol'], train['TableService'], train['Classy'], train['Kids'] = train['padded_labels'].str.split(' ', 9).str\nnormalized_data = train\nnormalized_data = normalized_data.drop(['labels', 'padded_labels'], axis=1)","execution_count":null,"outputs":[]},{"metadata":{"_kg_hide-input":true,"_kg_hide-output":true,"trusted":true,"_uuid":"e0b1622bea7e67513d143d55804e0d9f3f515cbf"},"cell_type":"code","source":"plt.style.use('ggplot')\ngraph_df = normalized_data.Lunch.value_counts().rename('Lunch').to_frame()\\\n               .join(normalized_data.Dinner.value_counts().rename('Dinner').to_frame()) \\\n               .join(normalized_data.Alcohol.value_counts().rename('Alcohol').to_frame()) \\\n               .join(normalized_data.TableService.value_counts().rename('TableService').to_frame())\n\ngraph_df.plot(kind='bar',figsize=(8, 4))","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"4f4bfe4569bcc7e95d9261f36d1abe0dce681fcf"},"cell_type":"markdown","source":"**How many restaurants serve both lunch and dinner**"},{"metadata":{"_kg_hide-input":true,"trusted":true,"_uuid":"e572293a902482a8b9d8a4314a4a9622cd2540b4"},"cell_type":"code","source":"normalized_data[(normalized_data['Lunch']=='Y') & (normalized_data['Dinner'] == 'Y')].Lunch.value_counts().item()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d01d05c8c47b13ac0e088aa83be249869a501354"},"cell_type":"markdown","source":"**How many restaurants need reservations for dinner**"},{"metadata":{"_kg_hide-input":true,"trusted":true,"_uuid":"3fe3e3944c439d77314eff2dbdb17ac95c867940"},"cell_type":"code","source":"normalized_data[(normalized_data['Dinner'] == 'Y') & (normalized_data['Reservations'] == 'Y')].Dinner.value_counts().item()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"e8bf6a57c79738a76521eadf4fd7e5aeddc85f5f"},"cell_type":"markdown","source":"**How many restaurants serve alcohol in the outdoor and are kid friendly?**"},{"metadata":{"_kg_hide-input":true,"trusted":true,"_uuid":"31edb9c58953fc719c24ef093ef7ac9d6eb11f33"},"cell_type":"code","source":"normalized_data[(normalized_data['Alcohol']=='Y') & (normalized_data['Kids'] == 'Y') & (normalized_data['Outdoor'] == 'Y')].Alcohol.value_counts().item()","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}