|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "### 1. Import the library and Load the dataset to pandas dataframe" |
| 8 | + ] |
| 9 | + }, |
| 10 | + { |
| 11 | + "cell_type": "code", |
| 12 | + "execution_count": 4, |
| 13 | + "metadata": {}, |
| 14 | + "outputs": [], |
| 15 | + "source": [ |
| 16 | + "import pandas as pd\n", |
| 17 | + "df = pd.read_csv('../Data/Student_bucketing.csv',header = 0)" |
| 18 | + ] |
| 19 | + }, |
| 20 | + { |
| 21 | + "cell_type": "markdown", |
| 22 | + "metadata": {}, |
| 23 | + "source": [ |
| 24 | + "### 2.\tDisplay the first 5 rows of the Dataframe" |
| 25 | + ] |
| 26 | + }, |
| 27 | + { |
| 28 | + "cell_type": "code", |
| 29 | + "execution_count": 5, |
| 30 | + "metadata": {}, |
| 31 | + "outputs": [ |
| 32 | + { |
| 33 | + "data": { |
| 34 | + "text/html": [ |
| 35 | + "<div>\n", |
| 36 | + "<style scoped>\n", |
| 37 | + " .dataframe tbody tr th:only-of-type {\n", |
| 38 | + " vertical-align: middle;\n", |
| 39 | + " }\n", |
| 40 | + "\n", |
| 41 | + " .dataframe tbody tr th {\n", |
| 42 | + " vertical-align: top;\n", |
| 43 | + " }\n", |
| 44 | + "\n", |
| 45 | + " .dataframe thead th {\n", |
| 46 | + " text-align: right;\n", |
| 47 | + " }\n", |
| 48 | + "</style>\n", |
| 49 | + "<table border=\"1\" class=\"dataframe\">\n", |
| 50 | + " <thead>\n", |
| 51 | + " <tr style=\"text-align: right;\">\n", |
| 52 | + " <th></th>\n", |
| 53 | + " <th>Student_id</th>\n", |
| 54 | + " <th>Age</th>\n", |
| 55 | + " <th>Grade</th>\n", |
| 56 | + " <th>Employed</th>\n", |
| 57 | + " <th>marks</th>\n", |
| 58 | + " </tr>\n", |
| 59 | + " </thead>\n", |
| 60 | + " <tbody>\n", |
| 61 | + " <tr>\n", |
| 62 | + " <th>0</th>\n", |
| 63 | + " <td>1</td>\n", |
| 64 | + " <td>19</td>\n", |
| 65 | + " <td>1st Class</td>\n", |
| 66 | + " <td>yes</td>\n", |
| 67 | + " <td>29</td>\n", |
| 68 | + " </tr>\n", |
| 69 | + " <tr>\n", |
| 70 | + " <th>1</th>\n", |
| 71 | + " <td>2</td>\n", |
| 72 | + " <td>20</td>\n", |
| 73 | + " <td>2nd Class</td>\n", |
| 74 | + " <td>no</td>\n", |
| 75 | + " <td>41</td>\n", |
| 76 | + " </tr>\n", |
| 77 | + " <tr>\n", |
| 78 | + " <th>2</th>\n", |
| 79 | + " <td>3</td>\n", |
| 80 | + " <td>18</td>\n", |
| 81 | + " <td>1st Class</td>\n", |
| 82 | + " <td>no</td>\n", |
| 83 | + " <td>57</td>\n", |
| 84 | + " </tr>\n", |
| 85 | + " <tr>\n", |
| 86 | + " <th>3</th>\n", |
| 87 | + " <td>4</td>\n", |
| 88 | + " <td>21</td>\n", |
| 89 | + " <td>2nd Class</td>\n", |
| 90 | + " <td>no</td>\n", |
| 91 | + " <td>29</td>\n", |
| 92 | + " </tr>\n", |
| 93 | + " <tr>\n", |
| 94 | + " <th>4</th>\n", |
| 95 | + " <td>5</td>\n", |
| 96 | + " <td>19</td>\n", |
| 97 | + " <td>1st Class</td>\n", |
| 98 | + " <td>no</td>\n", |
| 99 | + " <td>57</td>\n", |
| 100 | + " </tr>\n", |
| 101 | + " </tbody>\n", |
| 102 | + "</table>\n", |
| 103 | + "</div>" |
| 104 | + ], |
| 105 | + "text/plain": [ |
| 106 | + " Student_id Age Grade Employed marks\n", |
| 107 | + "0 1 19 1st Class yes 29\n", |
| 108 | + "1 2 20 2nd Class no 41\n", |
| 109 | + "2 3 18 1st Class no 57\n", |
| 110 | + "3 4 21 2nd Class no 29\n", |
| 111 | + "4 5 19 1st Class no 57" |
| 112 | + ] |
| 113 | + }, |
| 114 | + "execution_count": 5, |
| 115 | + "metadata": {}, |
| 116 | + "output_type": "execute_result" |
| 117 | + } |
| 118 | + ], |
| 119 | + "source": [ |
| 120 | + "df.head()" |
| 121 | + ] |
| 122 | + }, |
| 123 | + { |
| 124 | + "cell_type": "markdown", |
| 125 | + "metadata": {}, |
| 126 | + "source": [ |
| 127 | + "### 3.\tPerforming bucketing using the pd.cut() function on the marks column and displaying the top 10 columns. " |
| 128 | + ] |
| 129 | + }, |
| 130 | + { |
| 131 | + "cell_type": "code", |
| 132 | + "execution_count": 6, |
| 133 | + "metadata": {}, |
| 134 | + "outputs": [], |
| 135 | + "source": [ |
| 136 | + "df['bucket'] = pd.cut(df['marks'],5,labels = ['Poor','Below_average','Average','Above_Average','Excellent'])" |
| 137 | + ] |
| 138 | + }, |
| 139 | + { |
| 140 | + "cell_type": "code", |
| 141 | + "execution_count": 32, |
| 142 | + "metadata": {}, |
| 143 | + "outputs": [ |
| 144 | + { |
| 145 | + "data": { |
| 146 | + "text/html": [ |
| 147 | + "<div>\n", |
| 148 | + "<style scoped>\n", |
| 149 | + " .dataframe tbody tr th:only-of-type {\n", |
| 150 | + " vertical-align: middle;\n", |
| 151 | + " }\n", |
| 152 | + "\n", |
| 153 | + " .dataframe tbody tr th {\n", |
| 154 | + " vertical-align: top;\n", |
| 155 | + " }\n", |
| 156 | + "\n", |
| 157 | + " .dataframe thead th {\n", |
| 158 | + " text-align: right;\n", |
| 159 | + " }\n", |
| 160 | + "</style>\n", |
| 161 | + "<table border=\"1\" class=\"dataframe\">\n", |
| 162 | + " <thead>\n", |
| 163 | + " <tr style=\"text-align: right;\">\n", |
| 164 | + " <th></th>\n", |
| 165 | + " <th>Student_id</th>\n", |
| 166 | + " <th>Age</th>\n", |
| 167 | + " <th>Grade</th>\n", |
| 168 | + " <th>Employed</th>\n", |
| 169 | + " <th>marks</th>\n", |
| 170 | + " <th>bucket</th>\n", |
| 171 | + " </tr>\n", |
| 172 | + " </thead>\n", |
| 173 | + " <tbody>\n", |
| 174 | + " <tr>\n", |
| 175 | + " <th>0</th>\n", |
| 176 | + " <td>1</td>\n", |
| 177 | + " <td>19</td>\n", |
| 178 | + " <td>1st Class</td>\n", |
| 179 | + " <td>yes</td>\n", |
| 180 | + " <td>29</td>\n", |
| 181 | + " <td>Poor</td>\n", |
| 182 | + " </tr>\n", |
| 183 | + " <tr>\n", |
| 184 | + " <th>1</th>\n", |
| 185 | + " <td>2</td>\n", |
| 186 | + " <td>20</td>\n", |
| 187 | + " <td>2nd Class</td>\n", |
| 188 | + " <td>no</td>\n", |
| 189 | + " <td>41</td>\n", |
| 190 | + " <td>Below_average</td>\n", |
| 191 | + " </tr>\n", |
| 192 | + " <tr>\n", |
| 193 | + " <th>2</th>\n", |
| 194 | + " <td>3</td>\n", |
| 195 | + " <td>18</td>\n", |
| 196 | + " <td>1st Class</td>\n", |
| 197 | + " <td>no</td>\n", |
| 198 | + " <td>57</td>\n", |
| 199 | + " <td>Average</td>\n", |
| 200 | + " </tr>\n", |
| 201 | + " <tr>\n", |
| 202 | + " <th>3</th>\n", |
| 203 | + " <td>4</td>\n", |
| 204 | + " <td>21</td>\n", |
| 205 | + " <td>2nd Class</td>\n", |
| 206 | + " <td>no</td>\n", |
| 207 | + " <td>29</td>\n", |
| 208 | + " <td>Poor</td>\n", |
| 209 | + " </tr>\n", |
| 210 | + " <tr>\n", |
| 211 | + " <th>4</th>\n", |
| 212 | + " <td>5</td>\n", |
| 213 | + " <td>19</td>\n", |
| 214 | + " <td>1st Class</td>\n", |
| 215 | + " <td>no</td>\n", |
| 216 | + " <td>57</td>\n", |
| 217 | + " <td>Average</td>\n", |
| 218 | + " </tr>\n", |
| 219 | + " <tr>\n", |
| 220 | + " <th>5</th>\n", |
| 221 | + " <td>6</td>\n", |
| 222 | + " <td>20</td>\n", |
| 223 | + " <td>2nd Class</td>\n", |
| 224 | + " <td>yes</td>\n", |
| 225 | + " <td>53</td>\n", |
| 226 | + " <td>Average</td>\n", |
| 227 | + " </tr>\n", |
| 228 | + " <tr>\n", |
| 229 | + " <th>6</th>\n", |
| 230 | + " <td>7</td>\n", |
| 231 | + " <td>19</td>\n", |
| 232 | + " <td>3rd Class</td>\n", |
| 233 | + " <td>yes</td>\n", |
| 234 | + " <td>78</td>\n", |
| 235 | + " <td>Above_Average</td>\n", |
| 236 | + " </tr>\n", |
| 237 | + " <tr>\n", |
| 238 | + " <th>7</th>\n", |
| 239 | + " <td>8</td>\n", |
| 240 | + " <td>21</td>\n", |
| 241 | + " <td>3rd Class</td>\n", |
| 242 | + " <td>yes</td>\n", |
| 243 | + " <td>70</td>\n", |
| 244 | + " <td>Above_Average</td>\n", |
| 245 | + " </tr>\n", |
| 246 | + " <tr>\n", |
| 247 | + " <th>8</th>\n", |
| 248 | + " <td>9</td>\n", |
| 249 | + " <td>22</td>\n", |
| 250 | + " <td>3rd Class</td>\n", |
| 251 | + " <td>yes</td>\n", |
| 252 | + " <td>97</td>\n", |
| 253 | + " <td>Excellent</td>\n", |
| 254 | + " </tr>\n", |
| 255 | + " <tr>\n", |
| 256 | + " <th>9</th>\n", |
| 257 | + " <td>10</td>\n", |
| 258 | + " <td>21</td>\n", |
| 259 | + " <td>1st Class</td>\n", |
| 260 | + " <td>no</td>\n", |
| 261 | + " <td>58</td>\n", |
| 262 | + " <td>Average</td>\n", |
| 263 | + " </tr>\n", |
| 264 | + " </tbody>\n", |
| 265 | + "</table>\n", |
| 266 | + "</div>" |
| 267 | + ], |
| 268 | + "text/plain": [ |
| 269 | + " Student_id Age Grade Employed marks bucket\n", |
| 270 | + "0 1 19 1st Class yes 29 Poor\n", |
| 271 | + "1 2 20 2nd Class no 41 Below_average\n", |
| 272 | + "2 3 18 1st Class no 57 Average\n", |
| 273 | + "3 4 21 2nd Class no 29 Poor\n", |
| 274 | + "4 5 19 1st Class no 57 Average\n", |
| 275 | + "5 6 20 2nd Class yes 53 Average\n", |
| 276 | + "6 7 19 3rd Class yes 78 Above_Average\n", |
| 277 | + "7 8 21 3rd Class yes 70 Above_Average\n", |
| 278 | + "8 9 22 3rd Class yes 97 Excellent\n", |
| 279 | + "9 10 21 1st Class no 58 Average" |
| 280 | + ] |
| 281 | + }, |
| 282 | + "execution_count": 32, |
| 283 | + "metadata": {}, |
| 284 | + "output_type": "execute_result" |
| 285 | + } |
| 286 | + ], |
| 287 | + "source": [ |
| 288 | + "df.head(10)" |
| 289 | + ] |
| 290 | + } |
| 291 | + ], |
| 292 | + "metadata": { |
| 293 | + "kernelspec": { |
| 294 | + "display_name": "Python 3", |
| 295 | + "language": "python", |
| 296 | + "name": "python3" |
| 297 | + }, |
| 298 | + "language_info": { |
| 299 | + "codemirror_mode": { |
| 300 | + "name": "ipython", |
| 301 | + "version": 3 |
| 302 | + }, |
| 303 | + "file_extension": ".py", |
| 304 | + "mimetype": "text/x-python", |
| 305 | + "name": "python", |
| 306 | + "nbconvert_exporter": "python", |
| 307 | + "pygments_lexer": "ipython3", |
| 308 | + "version": "3.6.4" |
| 309 | + } |
| 310 | + }, |
| 311 | + "nbformat": 4, |
| 312 | + "nbformat_minor": 2 |
| 313 | +} |
0 commit comments