{"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":"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\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 read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-07-25T11:54:19.097332Z","iopub.execute_input":"2022-07-25T11:54:19.097723Z","iopub.status.idle":"2022-07-25T11:54:19.108310Z","shell.execute_reply.started":"2022-07-25T11:54:19.097693Z","shell.execute_reply":"2022-07-25T11:54:19.107145Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport plotly.express as px","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:54:19.139788Z","iopub.execute_input":"2022-07-25T11:54:19.140164Z","iopub.status.idle":"2022-07-25T11:54:19.145961Z","shell.execute_reply.started":"2022-07-25T11:54:19.140132Z","shell.execute_reply":"2022-07-25T11:54:19.144687Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## reading file \ntrain = pd.read_csv('/kaggle/input/titanic/train.csv')\ntest = pd.read_csv('/kaggle/input/titanic/test.csv')","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:54:19.182056Z","iopub.execute_input":"2022-07-25T11:54:19.183088Z","iopub.status.idle":"2022-07-25T11:54:19.199049Z","shell.execute_reply.started":"2022-07-25T11:54:19.183042Z","shell.execute_reply":"2022-07-25T11:54:19.198090Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:54:19.218715Z","iopub.execute_input":"2022-07-25T11:54:19.219772Z","iopub.status.idle":"2022-07-25T11:54:19.227434Z","shell.execute_reply.started":"2022-07-25T11:54:19.219727Z","shell.execute_reply":"2022-07-25T11:54:19.226189Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:54:19.257515Z","iopub.execute_input":"2022-07-25T11:54:19.258516Z","iopub.status.idle":"2022-07-25T11:54:19.264812Z","shell.execute_reply.started":"2022-07-25T11:54:19.258451Z","shell.execute_reply":"2022-07-25T11:54:19.263732Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.columns ","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:54:19.294671Z","iopub.execute_input":"2022-07-25T11:54:19.295443Z","iopub.status.idle":"2022-07-25T11:54:19.302465Z","shell.execute_reply.started":"2022-07-25T11:54:19.295405Z","shell.execute_reply":"2022-07-25T11:54:19.301595Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.columns","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:54:19.329037Z","iopub.execute_input":"2022-07-25T11:54:19.329448Z","iopub.status.idle":"2022-07-25T11:54:19.335848Z","shell.execute_reply.started":"2022-07-25T11:54:19.329414Z","shell.execute_reply":"2022-07-25T11:54:19.334987Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.concat([train,test])\ndf.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:54:19.360242Z","iopub.execute_input":"2022-07-25T11:54:19.360900Z","iopub.status.idle":"2022-07-25T11:54:19.372044Z","shell.execute_reply.started":"2022-07-25T11:54:19.360865Z","shell.execute_reply":"2022-07-25T11:54:19.370834Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10,6))\nsns.heatmap(df.isna().transpose(),\n            cmap=\"flare\",\n            cbar_kws={'label': 'Missing Data'})\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:54:19.383922Z","iopub.execute_input":"2022-07-25T11:54:19.384844Z","iopub.status.idle":"2022-07-25T11:54:20.050923Z","shell.execute_reply.started":"2022-07-25T11:54:19.384804Z","shell.execute_reply":"2022-07-25T11:54:20.049682Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:54:20.054912Z","iopub.execute_input":"2022-07-25T11:54:20.055257Z","iopub.status.idle":"2022-07-25T11:54:20.066921Z","shell.execute_reply.started":"2022-07-25T11:54:20.055228Z","shell.execute_reply":"2022-07-25T11:54:20.065693Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.Survived.fillna('Not Specified',inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:54:20.070620Z","iopub.execute_input":"2022-07-25T11:54:20.070945Z","iopub.status.idle":"2022-07-25T11:54:20.077291Z","shell.execute_reply.started":"2022-07-25T11:54:20.070917Z","shell.execute_reply":"2022-07-25T11:54:20.076439Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.Age.fillna('Not Specified',inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:54:20.079047Z","iopub.execute_input":"2022-07-25T11:54:20.079512Z","iopub.status.idle":"2022-07-25T11:54:20.090507Z","shell.execute_reply.started":"2022-07-25T11:54:20.079483Z","shell.execute_reply":"2022-07-25T11:54:20.089657Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.Cabin.fillna('Not Specified',inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:54:20.091909Z","iopub.execute_input":"2022-07-25T11:54:20.092343Z","iopub.status.idle":"2022-07-25T11:54:20.102659Z","shell.execute_reply.started":"2022-07-25T11:54:20.092302Z","shell.execute_reply":"2022-07-25T11:54:20.101668Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:55:22.212327Z","iopub.execute_input":"2022-07-25T11:55:22.212774Z","iopub.status.idle":"2022-07-25T11:55:22.225079Z","shell.execute_reply.started":"2022-07-25T11:55:22.212736Z","shell.execute_reply":"2022-07-25T11:55:22.223923Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.dropna(axis = 0 , inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:55:19.964785Z","iopub.execute_input":"2022-07-25T11:55:19.965224Z","iopub.status.idle":"2022-07-25T11:55:19.977198Z","shell.execute_reply.started":"2022-07-25T11:55:19.965191Z","shell.execute_reply":"2022-07-25T11:55:19.975418Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.shape","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:55:32.915381Z","iopub.execute_input":"2022-07-25T11:55:32.915783Z","iopub.status.idle":"2022-07-25T11:55:32.923303Z","shell.execute_reply.started":"2022-07-25T11:55:32.915750Z","shell.execute_reply":"2022-07-25T11:55:32.922101Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:55:44.668701Z","iopub.execute_input":"2022-07-25T11:55:44.669123Z","iopub.status.idle":"2022-07-25T11:55:44.687006Z","shell.execute_reply.started":"2022-07-25T11:55:44.669091Z","shell.execute_reply":"2022-07-25T11:55:44.685979Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Exploratory Data Analysis.\n","metadata":{}},{"cell_type":"code","source":"df.columns","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:56:58.238347Z","iopub.execute_input":"2022-07-25T11:56:58.238764Z","iopub.status.idle":"2022-07-25T11:56:58.245854Z","shell.execute_reply.started":"2022-07-25T11:56:58.238729Z","shell.execute_reply":"2022-07-25T11:56:58.244858Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:57:05.405889Z","iopub.execute_input":"2022-07-25T11:57:05.406287Z","iopub.status.idle":"2022-07-25T11:57:05.426201Z","shell.execute_reply.started":"2022-07-25T11:57:05.406257Z","shell.execute_reply":"2022-07-25T11:57:05.424878Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.describe()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:57:14.260742Z","iopub.execute_input":"2022-07-25T11:57:14.261128Z","iopub.status.idle":"2022-07-25T11:57:14.296581Z","shell.execute_reply.started":"2022-07-25T11:57:14.261098Z","shell.execute_reply":"2022-07-25T11:57:14.295513Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.corr()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:57:57.812454Z","iopub.execute_input":"2022-07-25T11:57:57.813717Z","iopub.status.idle":"2022-07-25T11:57:57.828395Z","shell.execute_reply.started":"2022-07-25T11:57:57.813673Z","shell.execute_reply":"2022-07-25T11:57:57.827214Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.columns","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:58:19.530492Z","iopub.execute_input":"2022-07-25T11:58:19.531041Z","iopub.status.idle":"2022-07-25T11:58:19.539728Z","shell.execute_reply.started":"2022-07-25T11:58:19.530993Z","shell.execute_reply":"2022-07-25T11:58:19.538655Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Analyze of Passenger Class.","metadata":{}},{"cell_type":"code","source":"df.value_counts('Pclass')","metadata":{"execution":{"iopub.status.busy":"2022-07-25T11:59:32.326868Z","iopub.execute_input":"2022-07-25T11:59:32.327296Z","iopub.status.idle":"2022-07-25T11:59:32.337466Z","shell.execute_reply.started":"2022-07-25T11:59:32.327263Z","shell.execute_reply":"2022-07-25T11:59:32.336020Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pclass = df.groupby(['Pclass']).size().reset_index().sort_values(by = 'Pclass',ascending = True).rename(columns = {0:'counts'})\npclass","metadata":{"execution":{"iopub.status.busy":"2022-07-25T12:04:12.456798Z","iopub.execute_input":"2022-07-25T12:04:12.457466Z","iopub.status.idle":"2022-07-25T12:04:12.480244Z","shell.execute_reply.started":"2022-07-25T12:04:12.457423Z","shell.execute_reply":"2022-07-25T12:04:12.478788Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10,6))\nplt.pie(pclass.counts,labels  = ['Pclass-1','Pclass-2','Pclass-3'],autopct = '%1.2f%%')\nplt.title('Ratio of Passenger Classes')\nsns.set_style(\"darkgrid\")\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T12:13:46.872789Z","iopub.execute_input":"2022-07-25T12:13:46.873748Z","iopub.status.idle":"2022-07-25T12:13:46.994545Z","shell.execute_reply.started":"2022-07-25T12:13:46.873704Z","shell.execute_reply":"2022-07-25T12:13:46.992975Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"langs= ['Pclass-1','Pclass-2','Pclass-3']\nplt.figure(figsize=(10,6))\nplt.tight_layout(pad=2)\nsns.barplot(x = pclass.counts,y = langs);\nplt.xlabel('Number of Passengers')\nplt.ylabel('Passenger Class')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T12:38:15.652620Z","iopub.execute_input":"2022-07-25T12:38:15.653067Z","iopub.status.idle":"2022-07-25T12:38:15.848421Z","shell.execute_reply.started":"2022-07-25T12:38:15.653031Z","shell.execute_reply":"2022-07-25T12:38:15.847168Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Analyze of Age Groups","metadata":{}},{"cell_type":"code","source":"df.Age.nunique()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T12:15:42.861915Z","iopub.execute_input":"2022-07-25T12:15:42.862441Z","iopub.status.idle":"2022-07-25T12:15:42.871845Z","shell.execute_reply.started":"2022-07-25T12:15:42.862392Z","shell.execute_reply":"2022-07-25T12:15:42.870544Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ages = df.groupby('Age').size().reset_index().rename(columns = {0:'counts'}).sort_values(by = 'counts',ascending = False).reset_index().drop('index',axis = 1)\nages.head()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T12:35:53.131548Z","iopub.execute_input":"2022-07-25T12:35:53.133594Z","iopub.status.idle":"2022-07-25T12:35:53.161583Z","shell.execute_reply.started":"2022-07-25T12:35:53.133531Z","shell.execute_reply":"2022-07-25T12:35:53.160712Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10,6))\nplt.tight_layout(pad=2)\nsns.barplot(x = ages.Age[:10],y = ages.counts[:10]);\nplt.title('Count Of Age Groups')\nplt.xlabel('Age Group')\nplt.ylabel('Number of Passengers')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T12:38:01.832525Z","iopub.execute_input":"2022-07-25T12:38:01.832976Z","iopub.status.idle":"2022-07-25T12:38:02.107661Z","shell.execute_reply.started":"2022-07-25T12:38:01.832944Z","shell.execute_reply":"2022-07-25T12:38:02.106333Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Analyze of Gender","metadata":{}},{"cell_type":"code","source":"df.Sex.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T12:43:11.783270Z","iopub.execute_input":"2022-07-25T12:43:11.783857Z","iopub.status.idle":"2022-07-25T12:43:11.793613Z","shell.execute_reply.started":"2022-07-25T12:43:11.783804Z","shell.execute_reply":"2022-07-25T12:43:11.792480Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10,6))\nax2= px.treemap(df,path=[\"Sex\"],title=\"No of Males & Females:\")\nax2.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T12:45:48.598829Z","iopub.execute_input":"2022-07-25T12:45:48.599283Z","iopub.status.idle":"2022-07-25T12:45:48.692310Z","shell.execute_reply.started":"2022-07-25T12:45:48.599247Z","shell.execute_reply":"2022-07-25T12:45:48.691151Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10,6))\nsns.countplot(x = 'Sex',data = df)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T12:45:53.298967Z","iopub.execute_input":"2022-07-25T12:45:53.299416Z","iopub.status.idle":"2022-07-25T12:45:53.446768Z","shell.execute_reply.started":"2022-07-25T12:45:53.299380Z","shell.execute_reply":"2022-07-25T12:45:53.445587Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Analyze of Cabin","metadata":{"execution":{"iopub.status.busy":"2022-07-25T12:51:02.369087Z","iopub.execute_input":"2022-07-25T12:51:02.369484Z","iopub.status.idle":"2022-07-25T12:51:02.392337Z","shell.execute_reply.started":"2022-07-25T12:51:02.369453Z","shell.execute_reply":"2022-07-25T12:51:02.391385Z"}}},{"cell_type":"code","source":"plt.figure(figsize=(10,6))\nax2= px.treemap(df,path=[\"Cabin\"],title=\"Popularity of Cabin\")\nax2.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T12:53:05.489185Z","iopub.execute_input":"2022-07-25T12:53:05.489573Z","iopub.status.idle":"2022-07-25T12:53:05.593099Z","shell.execute_reply.started":"2022-07-25T12:53:05.489534Z","shell.execute_reply":"2022-07-25T12:53:05.591803Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Analyze of Survived","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(10,6))\nsns.countplot(x = 'Survived',data = df)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-25T12:55:50.619301Z","iopub.execute_input":"2022-07-25T12:55:50.619814Z","iopub.status.idle":"2022-07-25T12:55:50.820470Z","shell.execute_reply.started":"2022-07-25T12:55:50.619776Z","shell.execute_reply":"2022-07-25T12:55:50.819326Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Thanks For Reviewing my notebook.I will upgrade it further more.\n\nEDA Done by Rimmel Asghar with ❤","metadata":{}}]}