|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "### 1.Load the dataset into the pandas data frame. To do so, you first need to import the pandas library, and then, use the function pd.read_csv(), as shown below:" |
| 8 | + ] |
| 9 | + }, |
| 10 | + { |
| 11 | + "cell_type": "code", |
| 12 | + "execution_count": 1, |
| 13 | + "metadata": {}, |
| 14 | + "outputs": [], |
| 15 | + "source": [ |
| 16 | + "import pandas as pd\n", |
| 17 | + "\n", |
| 18 | + "#reading the data into the dataframe into the object data\n", |
| 19 | + "df = pd.read_csv('../Data/Banking_Marketing.csv', header=0)" |
| 20 | + ] |
| 21 | + }, |
| 22 | + { |
| 23 | + "cell_type": "markdown", |
| 24 | + "metadata": {}, |
| 25 | + "source": [ |
| 26 | + "### 2.Print the datatype of each column. To do so, use the dtypes attribute from pandas data frame." |
| 27 | + ] |
| 28 | + }, |
| 29 | + { |
| 30 | + "cell_type": "code", |
| 31 | + "execution_count": 3, |
| 32 | + "metadata": {}, |
| 33 | + "outputs": [ |
| 34 | + { |
| 35 | + "data": { |
| 36 | + "text/plain": [ |
| 37 | + "age float64\n", |
| 38 | + "job object\n", |
| 39 | + "marital object\n", |
| 40 | + "education object\n", |
| 41 | + "default object\n", |
| 42 | + "housing object\n", |
| 43 | + "loan object\n", |
| 44 | + "contact object\n", |
| 45 | + "month object\n", |
| 46 | + "day_of_week object\n", |
| 47 | + "duration float64\n", |
| 48 | + "campaign int64\n", |
| 49 | + "pdays int64\n", |
| 50 | + "previous int64\n", |
| 51 | + "poutcome object\n", |
| 52 | + "emp_var_rate float64\n", |
| 53 | + "cons_price_idx float64\n", |
| 54 | + "cons_conf_idx float64\n", |
| 55 | + "euribor3m float64\n", |
| 56 | + "nr_employed float64\n", |
| 57 | + "y int64\n", |
| 58 | + "dtype: object" |
| 59 | + ] |
| 60 | + }, |
| 61 | + "execution_count": 3, |
| 62 | + "metadata": {}, |
| 63 | + "output_type": "execute_result" |
| 64 | + } |
| 65 | + ], |
| 66 | + "source": [ |
| 67 | + "#finding the data types of each column\n", |
| 68 | + "df.dtypes" |
| 69 | + ] |
| 70 | + }, |
| 71 | + { |
| 72 | + "cell_type": "markdown", |
| 73 | + "metadata": {}, |
| 74 | + "source": [ |
| 75 | + "### 3.Print how many missing values on each column. To do so, use isna() function from pandas dataframe" |
| 76 | + ] |
| 77 | + }, |
| 78 | + { |
| 79 | + "cell_type": "code", |
| 80 | + "execution_count": 4, |
| 81 | + "metadata": {}, |
| 82 | + "outputs": [ |
| 83 | + { |
| 84 | + "data": { |
| 85 | + "text/plain": [ |
| 86 | + "age 2\n", |
| 87 | + "job 0\n", |
| 88 | + "marital 0\n", |
| 89 | + "education 0\n", |
| 90 | + "default 0\n", |
| 91 | + "housing 0\n", |
| 92 | + "loan 0\n", |
| 93 | + "contact 6\n", |
| 94 | + "month 0\n", |
| 95 | + "day_of_week 0\n", |
| 96 | + "duration 7\n", |
| 97 | + "campaign 0\n", |
| 98 | + "pdays 0\n", |
| 99 | + "previous 0\n", |
| 100 | + "poutcome 0\n", |
| 101 | + "emp_var_rate 0\n", |
| 102 | + "cons_price_idx 0\n", |
| 103 | + "cons_conf_idx 0\n", |
| 104 | + "euribor3m 0\n", |
| 105 | + "nr_employed 0\n", |
| 106 | + "y 0\n", |
| 107 | + "dtype: int64" |
| 108 | + ] |
| 109 | + }, |
| 110 | + "execution_count": 4, |
| 111 | + "metadata": {}, |
| 112 | + "output_type": "execute_result" |
| 113 | + } |
| 114 | + ], |
| 115 | + "source": [ |
| 116 | + "df.isna().sum()" |
| 117 | + ] |
| 118 | + }, |
| 119 | + { |
| 120 | + "cell_type": "markdown", |
| 121 | + "metadata": {}, |
| 122 | + "source": [ |
| 123 | + "### 4.Remove all the missing rows from the dataframe. To do so, we make use of the function dropna()." |
| 124 | + ] |
| 125 | + }, |
| 126 | + { |
| 127 | + "cell_type": "code", |
| 128 | + "execution_count": 6, |
| 129 | + "metadata": {}, |
| 130 | + "outputs": [ |
| 131 | + { |
| 132 | + "data": { |
| 133 | + "text/plain": [ |
| 134 | + "age 0\n", |
| 135 | + "job 0\n", |
| 136 | + "marital 0\n", |
| 137 | + "education 0\n", |
| 138 | + "default 0\n", |
| 139 | + "housing 0\n", |
| 140 | + "loan 0\n", |
| 141 | + "contact 0\n", |
| 142 | + "month 0\n", |
| 143 | + "day_of_week 0\n", |
| 144 | + "duration 0\n", |
| 145 | + "campaign 0\n", |
| 146 | + "pdays 0\n", |
| 147 | + "previous 0\n", |
| 148 | + "poutcome 0\n", |
| 149 | + "emp_var_rate 0\n", |
| 150 | + "cons_price_idx 0\n", |
| 151 | + "cons_conf_idx 0\n", |
| 152 | + "euribor3m 0\n", |
| 153 | + "nr_employed 0\n", |
| 154 | + "y 0\n", |
| 155 | + "dtype: int64" |
| 156 | + ] |
| 157 | + }, |
| 158 | + "execution_count": 6, |
| 159 | + "metadata": {}, |
| 160 | + "output_type": "execute_result" |
| 161 | + } |
| 162 | + ], |
| 163 | + "source": [ |
| 164 | + "#removing Null values\n", |
| 165 | + "df = df.dropna()\n", |
| 166 | + "#Let us check again if NA’s still available\n", |
| 167 | + "df.isna().sum()" |
| 168 | + ] |
| 169 | + } |
| 170 | + ], |
| 171 | + "metadata": { |
| 172 | + "kernelspec": { |
| 173 | + "display_name": "Python 3", |
| 174 | + "language": "python", |
| 175 | + "name": "python3" |
| 176 | + }, |
| 177 | + "language_info": { |
| 178 | + "codemirror_mode": { |
| 179 | + "name": "ipython", |
| 180 | + "version": 3 |
| 181 | + }, |
| 182 | + "file_extension": ".py", |
| 183 | + "mimetype": "text/x-python", |
| 184 | + "name": "python", |
| 185 | + "nbconvert_exporter": "python", |
| 186 | + "pygments_lexer": "ipython3", |
| 187 | + "version": "3.6.4" |
| 188 | + } |
| 189 | + }, |
| 190 | + "nbformat": 4, |
| 191 | + "nbformat_minor": 2 |
| 192 | +} |
0 commit comments