{"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":"# list of elements to calculate mean\nn_num = [1, 2, 3, 4, 5, 6]\nn = len(n_num)\n  \nget_sum = sum(n_num)\nmean = get_sum / n\n  \nprint(\"Mean is: \" + str(mean))\n\n# list of elements to calculate median\nn_num = [1, 2, 3, 4, 5]\nn = len(n_num)\nn_num.sort()\n  \nif n % 2 == 0:\n    median1 = n_num[n//2]\n    median2 = n_num[n//2 - 1]\n    median = (median1 + median2)/2\nelse:\n    median = n_num[n//2]\nprint(\"Median is: \" + str(median))\n\nimport numpy as np\n\n# First quartile (Q1)\nQ1 = np.median(n_num[:3])\nprint(\"Q1 is :\",Q1) \n  \n# Third quartile (Q3)\nQ3= np.median(n_num[3:])\nprint(\"Q3 is :\", Q3)\n  \n# Interquartile range (IQR)\nIQR = Q3 - Q1\nprint(\"IQR is :\", IQR)","metadata":{"execution":{"iopub.status.busy":"2022-11-10T04:38:16.664104Z","iopub.execute_input":"2022-11-10T04:38:16.664482Z","iopub.status.idle":"2022-11-10T04:38:16.675350Z","shell.execute_reply.started":"2022-11-10T04:38:16.664452Z","shell.execute_reply":"2022-11-10T04:38:16.673801Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Question 2**","metadata":{}},{"cell_type":"code","source":"import random\n\ncount = [0, 0, 0, 0, 0, 0]\n\nfor i in range(10000):\n    count[random.randint(0,5)] += 1\n\nfor i in range(6):\n    print (\"Value %d appeared %d times\" % (i + 1, count[i]))","metadata":{"execution":{"iopub.status.busy":"2022-11-10T04:38:16.677232Z","iopub.execute_input":"2022-11-10T04:38:16.677562Z","iopub.status.idle":"2022-11-10T04:38:16.701446Z","shell.execute_reply.started":"2022-11-10T04:38:16.677534Z","shell.execute_reply":"2022-11-10T04:38:16.700091Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Question 3**","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd","metadata":{"execution":{"iopub.status.busy":"2022-11-10T04:38:16.702550Z","iopub.execute_input":"2022-11-10T04:38:16.702906Z","iopub.status.idle":"2022-11-10T04:38:16.711845Z","shell.execute_reply.started":"2022-11-10T04:38:16.702877Z","shell.execute_reply":"2022-11-10T04:38:16.710960Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df=pd.read_csv(\"../input/amex-default-prediction/train_data.csv\", nrows=200000)","metadata":{"execution":{"iopub.status.busy":"2022-11-10T04:38:16.714280Z","iopub.execute_input":"2022-11-10T04:38:16.714571Z","iopub.status.idle":"2022-11-10T04:38:29.297644Z","shell.execute_reply.started":"2022-11-10T04:38:16.714546Z","shell.execute_reply":"2022-11-10T04:38:29.296623Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2022-11-10T04:38:29.298954Z","iopub.execute_input":"2022-11-10T04:38:29.299409Z","iopub.status.idle":"2022-11-10T04:38:29.334574Z","shell.execute_reply.started":"2022-11-10T04:38:29.299366Z","shell.execute_reply":"2022-11-10T04:38:29.333579Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.shape","metadata":{"execution":{"iopub.status.busy":"2022-11-10T04:38:29.336018Z","iopub.execute_input":"2022-11-10T04:38:29.336377Z","iopub.status.idle":"2022-11-10T04:38:29.342991Z","shell.execute_reply.started":"2022-11-10T04:38:29.336341Z","shell.execute_reply":"2022-11-10T04:38:29.341815Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.drop(['D_132', 'D_134', 'D_135', 'D_136', 'D_137', 'D_138', 'D_142'], axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-11-10T04:38:29.344442Z","iopub.execute_input":"2022-11-10T04:38:29.345028Z","iopub.status.idle":"2022-11-10T04:38:29.452347Z","shell.execute_reply.started":"2022-11-10T04:38:29.344995Z","shell.execute_reply":"2022-11-10T04:38:29.451057Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.isnull()","metadata":{"execution":{"iopub.status.busy":"2022-11-10T04:38:29.453829Z","iopub.execute_input":"2022-11-10T04:38:29.454204Z","iopub.status.idle":"2022-11-10T04:38:29.535161Z","shell.execute_reply.started":"2022-11-10T04:38:29.454144Z","shell.execute_reply":"2022-11-10T04:38:29.533760Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"i=0\nfor col in df.columns:\n    if (df[col].isnull().sum()/len(df[col])*100) >=75:\n        print(\"Dropping column\", col)\n        df.drop(labels=col,axis=1,inplace=True)\n        i=i+1","metadata":{"execution":{"iopub.status.busy":"2022-11-10T04:38:29.536755Z","iopub.execute_input":"2022-11-10T04:38:29.537069Z","iopub.status.idle":"2022-11-10T04:38:30.859297Z","shell.execute_reply.started":"2022-11-10T04:38:29.537042Z","shell.execute_reply":"2022-11-10T04:38:30.858090Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.isnull()","metadata":{"execution":{"iopub.status.busy":"2022-11-10T04:38:30.863127Z","iopub.execute_input":"2022-11-10T04:38:30.863456Z","iopub.status.idle":"2022-11-10T04:38:30.944204Z","shell.execute_reply.started":"2022-11-10T04:38:30.863431Z","shell.execute_reply":"2022-11-10T04:38:30.943386Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info(max_cols=200, show_counts=True)\n","metadata":{"execution":{"iopub.status.busy":"2022-11-10T04:38:30.945214Z","iopub.execute_input":"2022-11-10T04:38:30.946312Z","iopub.status.idle":"2022-11-10T04:38:31.046901Z","shell.execute_reply.started":"2022-11-10T04:38:30.946280Z","shell.execute_reply":"2022-11-10T04:38:31.045608Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df= df.astype({'B_30':'str','B_38': 'str', 'D_114' : 'str', 'D_116':'str', 'D_117' :'str', 'D_120':'str', 'D_126':'str', 'D_63':'str','D_64':'str','D_68':'str'})\n","metadata":{"execution":{"iopub.status.busy":"2022-11-10T04:38:31.049111Z","iopub.execute_input":"2022-11-10T04:38:31.049561Z","iopub.status.idle":"2022-11-10T04:38:31.512982Z","shell.execute_reply.started":"2022-11-10T04:38:31.049520Z","shell.execute_reply":"2022-11-10T04:38:31.511894Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# define categorical variables (columns)\ncategorical = list(df.select_dtypes('object').columns)\nprint(f\"Categorical variables (columns) are: {categorical}\")","metadata":{"execution":{"iopub.status.busy":"2022-11-10T04:38:31.514180Z","iopub.execute_input":"2022-11-10T04:38:31.514436Z","iopub.status.idle":"2022-11-10T04:38:31.683875Z","shell.execute_reply.started":"2022-11-10T04:38:31.514413Z","shell.execute_reply":"2022-11-10T04:38:31.682521Z"},"trusted":true},"execution_count":null,"outputs":[]}]}