{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":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)\n\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n\nimport os\nprint(os.listdir(\"../input\"))\n\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"df = pd.read_csv(\"../input/train.csv\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"43332e8e9d9d26b91fa663356273dbb7877c2d41"},"cell_type":"code","source":"df.columns","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"3c1ba0ab06dddcafa974894a66ffbe15097e9dac"},"cell_type":"code","source":"df['PassengerId'].head(10)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"f6dfd7c64db88e9346171168bef3d7e31d3a7048"},"cell_type":"code","source":"df[['Name', 'Sex']].head(10)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"709e40ab0af2b81153e38d2fa7c196082685605a"},"cell_type":"code","source":"df['Survived'].value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e3ae1c094bf862f1a0f357ec73460b327de91958"},"cell_type":"code","source":"df['Sex'].value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"scrolled":true,"_uuid":"1b1be183c2e8d827b3ad869720aceb0117194318"},"cell_type":"code","source":"df['Pclass'].value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a67a20fc4c9d6222ffd030b3c68754d53e51037b"},"cell_type":"code","source":"df['Age'].mean()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d12b1c25c087a32ee5596c9f3c2d6a2cd569a303"},"cell_type":"code","source":"df['Fare'].max()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"fe5f6bc0c293419529a567a897156b30674bdf78"},"cell_type":"code","source":"df['Fare'].min()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"64a8bd0e3e0c17d342f73e084d7364808d7974bf"},"cell_type":"code","source":"df['Fare'].mean()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"580ea39ec505fd8f873eb2b3343193173ab8a7ea"},"cell_type":"code","source":"df['Embarked'].value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2848fabb209defde6928d30cebaff83221255c79"},"cell_type":"code","source":"df.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4c4949e656941eb7759f115e2f748d88aaa3b0ea"},"cell_type":"code","source":"ml_df = df[df['Sex'] == 'male']","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"fc5bd4ddb0c3c5ebe513b0fbd9a2bdbfcf4367a2"},"cell_type":"code","source":"len(ml_df)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"11529588ea09eab1e70d5efff8af401aee6bb846"},"cell_type":"code","source":"df_age_above_50 = df[df['Age'] > 50]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d634f3623efee6643005728aacede9cd65a6e237"},"cell_type":"code","source":"df_ml_age_above_50 = df[(df['Age'] > 50) & (df['Sex'] == 'male')]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"scrolled":true,"_uuid":"49e30b787fe2952f766a524bf8c76dc5a7e1e676"},"cell_type":"code","source":"df_ml_age_above_50","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"917514ded8a66f5e333bb1a92f214a994e6082fc"},"cell_type":"code","source":"df_ml_age_between_30_and_50 = df[(df['Age'] <= 50) & (df['Age'] >= 30) & (df['Sex'] == 'male')]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"88982565e29d0830f2b5cc8f727d0dddb6fce65d"},"cell_type":"code","source":"df_fml_age_between_30_and_50 = df[(df['Age'] <= 50) & (df['Age'] >= 30) & (df['Sex'] == 'female')]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e08da3a0e9e4457a687407593b070b9ff83a3d57"},"cell_type":"code","source":"df_embarked_s_and_female = df[(df['Embarked'] == 'S') & (df['Sex'] == 'female')]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"5d69e3ea2bbd67bf1b79f228166cec6be2137b4d"},"cell_type":"code","source":"len(df_ml_age_between_30_and_50)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"00002f6a3c9eaf46c93438bbebc2894d3f7613ff"},"cell_type":"code","source":"len(df_fml_age_between_30_and_50)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"332b848b77fa83e8aa94cf425f490e4b1cccee9e"},"cell_type":"code","source":"len(df_embarked_s_and_female)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4bce34062b88a0775d80ad7f8dc2c34766f2fcdd"},"cell_type":"code","source":"df['Embarked'].isnull().value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a94e076363cb48ce20493895819af347867dbfd6"},"cell_type":"code","source":"df['Embarked'] = df['Embarked'].fillna(\"S\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ee4afd1d10570c28f4634864e39210fa794f8e7e"},"cell_type":"code","source":"df['Embarked'].isnull().value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"eaf374c449bcc3d5a75bc74a3bd80e4be51e533c"},"cell_type":"code","source":"df['Age'].isnull().value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"9535e386523598f07806cd53c6ac9790375eea9d"},"cell_type":"code","source":"df['Age'] = df['Age'].fillna(df['Age'].mean())","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4d0a7a0eaae22e0eb2a2b5a987aa92c1ca075832"},"cell_type":"code","source":"df['Age'].isnull().value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"88cf42ab0686f3a6e438f73d911c74212fa804c7"},"cell_type":"code","source":"df.columns[df.isnull().any()]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"fd91187f0ced8c67b55185fcde667d36b6c38d67"},"cell_type":"code","source":"df['Cabin'].isnull().value_counts()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"7744bb9c07f1cf62545658cf6530b245626094b9"},"cell_type":"markdown","source":"# ASSIGNMENT (DATE: 30 JAN 2019)"},{"metadata":{"_uuid":"6ab57a1c952cedc166aa944b6a44caa7601009b4"},"cell_type":"markdown","source":"## REMOVING ROWS WITH MISSING VALUES"},{"metadata":{"trusted":true,"_uuid":"6a5e8a3522bae34b912822b036e9e1d69ff89aa5"},"cell_type":"code","source":"df1 = pd.read_csv(\"../input/train.csv\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"cd9909e402e1e478ab8ca9bcc8f7dee19d377ceb"},"cell_type":"code","source":"df1.columns[df1.isnull().any()]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"b47fb0912275ce83cf31e0c6e80dee0e51ff34b4"},"cell_type":"code","source":"df1['Age'].isnull().value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"14c7b9041596d687e20e63b9e480a30aca614d39"},"cell_type":"code","source":"df1['Embarked'].isnull().value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"6ae417471cb2d2e478945d2ed6831b45d12cedf8"},"cell_type":"code","source":"df1['Cabin'].isnull().value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"f9bdfab41f2d0fa365bd5f313b97d0db9c39797c"},"cell_type":"code","source":"tmp_df_row = df1.dropna(how = 'any')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"645199d4a773c3ca7ac9c31bf1ceaea87150f86b"},"cell_type":"code","source":"len(tmp_df_row)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"16ccf0075ce3a7355ae1d0a350294ad2d31ceeea"},"cell_type":"code","source":"tmp_df_row_all = df1.dropna(how = 'all')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"55e875b5f45e098df42bce6260e5134cabd60034"},"cell_type":"code","source":"len(tmp_df_row_all)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"74ad8b9d7a3390d154426cf08fd3525b396f3f8f"},"cell_type":"code","source":"#Remove rows which has null value in a specific column\n\ntmp_df_row_subset_age = df1.dropna(subset = ['Age'])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"774f5cd85dbfa907905aeac62dacdd590cc968a9"},"cell_type":"code","source":"len(tmp_df_row_subset_age)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ddb246f37304ac3c4085236f55f04373d8067f94"},"cell_type":"code","source":"tmp_df_row_subset_age['Age'].isnull().value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d8cde943d8c1b4b7a6b99f6981ff9b168578365c"},"cell_type":"code","source":"tmp_df_row_subset_embarked = df1.dropna(subset = ['Embarked'])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"da52fd4fc4ee4cee7fd9d99e820878845fcf55d7"},"cell_type":"code","source":"len(tmp_df_row_subset_embarked)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"307865ace32c7fb850f904a8c9da3aa6e5c7c6a5"},"cell_type":"code","source":"tmp_df_row_subset_embarked['Embarked'].isnull().value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2e3a9be8dbdce39e6acc9cdd0ffbc96ccedb9d99"},"cell_type":"code","source":"tmp_df_row_subset_cabin = df1.dropna(subset = ['Cabin'])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a47e0923c6a3f34ae85cb05efa24d7d33be84fac"},"cell_type":"code","source":"len(tmp_df_row_subset_cabin)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0b9ecfe00fcf8d27fb807ac131910b2e38fe987f"},"cell_type":"code","source":"tmp_df_row_subset_cabin['Cabin'].isnull().value_counts()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"2ea883dd05f78c93f47ea1e53c3087937d08faf6"},"cell_type":"markdown","source":"## DROPPING COLUMNS"},{"metadata":{"trusted":true,"_uuid":"2ea7a42736d635ecfe29d22e6c4ab96fbc055181"},"cell_type":"code","source":"df1['Cabin'].isnull().value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c11b9d4daaf959d41d2214d31f6c1cd7eefd79c3"},"cell_type":"code","source":"tmp_df_col = df1.drop(['Cabin'], axis = 1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"535f973323a85f362570d235453b12060d4e150b"},"cell_type":"code","source":"tmp_df_col","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"4681f246ab89a3125dba69dc0b49ff66b9dc9fc9"},"cell_type":"markdown","source":"## IMPUTING MISSING VALUES"},{"metadata":{"trusted":true,"_uuid":"7105ebb4d16e7a5a60fad36b85d5250315aded8d"},"cell_type":"code","source":"tmp_df = df1","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"36bc1ded0522827991ad6f71157959bc1f0d569b"},"cell_type":"code","source":"tmp_df['Embarked'].isnull().value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c938e5b797bda6c94d50066c539af3761d74d57b"},"cell_type":"code","source":"tmp_df['Embarked'] = tmp_df['Embarked'].fillna(\"S\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"9221e95ca9d74c566276a3ccae3f1ca2d7bcd2a1"},"cell_type":"code","source":"tmp_df['Embarked'].isnull().value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0b822a5191dcfe430912e6d727ba02a16d9a0165"},"cell_type":"code","source":"tmp_df['Age'].isnull().value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a52ddd0c2bae217e23d2cc7d082ef23b61a7917f"},"cell_type":"code","source":"tmp_df['Age'] = tmp_df['Age'].fillna(tmp_df['Age'].mean())","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e8211a75cb26c6f2d8f151f7c6d7bf2a47521d41"},"cell_type":"code","source":"tmp_df['Age'].isnull().value_counts()","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}