├── finished-files ├── .ipynb_checkpoints │ ├── 07 - Pandas Groupby Method (Finished)-checkpoint.ipynb │ └── 11 - Common Operations in Pandas (Finished)-checkpoint.ipynb ├── 01 - NumPy Arrays (Finished).ipynb ├── 02 - NumPy Methods and Operations (Finished).ipynb ├── 03 - NumPy Indexing and Assignment (Finished).ipynb ├── 04 - Pandas Series (Finished).ipynb ├── 05 - Pandas DataFrames (Finished).ipynb ├── 06 - How To Deal With Missing Data in Pandas (Finished).ipynb ├── 07 - Pandas Groupby Method (Finished).ipynb ├── 08 - How To Concatenate DataFrames in Pandas (Finished).ipynb ├── 09 - How To Merge DataFrames in Pandas (Finished).ipynb ├── 10 - How To Join DataFrames in Pandas (Finished).ipynb └── 11 - Common Operations in Pandas (Finished).ipynb ├── starter-files ├── 01 - NumPy Arrays.ipynb ├── 02 - NumPy Methods and Operations.ipynb ├── 03 - NumPy Indexing and Assignment.ipynb ├── 04 - Pandas Series.ipynb ├── 05 - Pandas DataFrames.ipynb ├── 06 - How To Deal With Missing Data in Pandas.ipynb ├── 07 - Pandas Groupby Method.ipynb ├── 08 - How To Concatenate DataFrames in Pandas.ipynb ├── 09 - How To Merge DataFrames in Pandas.ipynb ├── 10 - How To Join DataFrames in Pandas.ipynb └── 11 - Common Operations in Pandas.ipynb └── stock_prices ├── stock_prices.csv ├── stock_prices.json └── stock_prices.xlsx /finished-files/.ipynb_checkpoints/07 - Pandas Groupby Method (Finished)-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Problem 1\n", 8 | "Import NumPy under the alias `np`." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 1, 14 | "metadata": {}, 15 | "outputs": [], 16 | "source": [ 17 | "import numpy as np" 18 | ] 19 | }, 20 | { 21 | "cell_type": "markdown", 22 | "metadata": {}, 23 | "source": [ 24 | "# Problem 2\n", 25 | "Import pandas under the alias `pd`." 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": 2, 31 | "metadata": {}, 32 | "outputs": [], 33 | "source": [ 34 | "import pandas as pd" 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "metadata": {}, 40 | "source": [ 41 | "# Problem 3\n", 42 | "We will again be using salesperson data to test your knowledge of the `groupby` method. Given the dataset `data`, print a new DataFrame that shows the mean sales per salesperson, grouped by `Organization`." 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 3, 48 | "metadata": {}, 49 | "outputs": [ 50 | { 51 | "data": { 52 | "text/html": [ 53 | "
\n", 54 | "\n", 67 | "\n", 68 | " \n", 69 | " \n", 70 | " \n", 71 | " \n", 72 | " \n", 73 | " \n", 74 | " \n", 75 | " \n", 76 | " \n", 77 | " \n", 78 | " \n", 79 | " \n", 80 | " \n", 81 | " \n", 82 | " \n", 83 | " \n", 84 | " \n", 85 | " \n", 86 | " \n", 87 | " \n", 88 | " \n", 89 | " \n", 90 | " \n", 91 | " \n", 92 | " \n", 93 | " \n", 94 | " \n", 95 | " \n", 96 | " \n", 97 | " \n", 98 | " \n", 99 | " \n", 100 | " \n", 101 | " \n", 102 | " \n", 103 | " \n", 104 | " \n", 105 | " \n", 106 | " \n", 107 | " \n", 108 | " \n", 109 | " \n", 110 | " \n", 111 | " \n", 112 | " \n", 113 | " \n", 114 | "
OrganizationSalesperson NameSales
0Coca-ColaNick200
1Coca-ColaJoel120
2PepsiTaylor125
3PepsiJosiah250
4Dr. PepperJosh150
5Dr. PepperMicaiah500
\n", 115 | "
" 116 | ], 117 | "text/plain": [ 118 | " Organization Salesperson Name Sales\n", 119 | "0 Coca-Cola Nick 200\n", 120 | "1 Coca-Cola Joel 120\n", 121 | "2 Pepsi Taylor 125\n", 122 | "3 Pepsi Josiah 250\n", 123 | "4 Dr. Pepper Josh 150\n", 124 | "5 Dr. Pepper Micaiah 500" 125 | ] 126 | }, 127 | "execution_count": 3, 128 | "metadata": {}, 129 | "output_type": "execute_result" 130 | } 131 | ], 132 | "source": [ 133 | "data = pd.DataFrame([ ['Coca-Cola', 'Nick', 200],\n", 134 | "\n", 135 | " ['Coca-Cola', 'Joel', 120],\n", 136 | "\n", 137 | " ['Pepsi','Taylor', 125],\n", 138 | "\n", 139 | " ['Pepsi','Josiah', 250],\n", 140 | "\n", 141 | " ['Dr. Pepper','Josh', 150],\n", 142 | "\n", 143 | " ['Dr. Pepper','Micaiah', 500]], \n", 144 | " columns = ['Organization', 'Salesperson Name', 'Sales'])\n", 145 | "\n", 146 | "data" 147 | ] 148 | }, 149 | { 150 | "cell_type": "code", 151 | "execution_count": 4, 152 | "metadata": {}, 153 | "outputs": [ 154 | { 155 | "data": { 156 | "text/html": [ 157 | "
\n", 158 | "\n", 171 | "\n", 172 | " \n", 173 | " \n", 174 | " \n", 175 | " \n", 176 | " \n", 177 | " \n", 178 | " \n", 179 | " \n", 180 | " \n", 181 | " \n", 182 | " \n", 183 | " \n", 184 | " \n", 185 | " \n", 186 | " \n", 187 | " \n", 188 | " \n", 189 | " \n", 190 | " \n", 191 | " \n", 192 | " \n", 193 | " \n", 194 | " \n", 195 | " \n", 196 | "
Sales
Organization
Coca-Cola160.0
Dr. Pepper325.0
Pepsi187.5
\n", 197 | "
" 198 | ], 199 | "text/plain": [ 200 | " Sales\n", 201 | "Organization \n", 202 | "Coca-Cola 160.0\n", 203 | "Dr. Pepper 325.0\n", 204 | "Pepsi 187.5" 205 | ] 206 | }, 207 | "execution_count": 4, 208 | "metadata": {}, 209 | "output_type": "execute_result" 210 | } 211 | ], 212 | "source": [ 213 | "#Solution goes here\n", 214 | "data.groupby('Organization').mean()" 215 | ] 216 | }, 217 | { 218 | "cell_type": "markdown", 219 | "metadata": {}, 220 | "source": [ 221 | "# Problem 4\n", 222 | "Given the dataset `data`, print a new DataFrame that shows the total sales for each `Organization`." 223 | ] 224 | }, 225 | { 226 | "cell_type": "code", 227 | "execution_count": 5, 228 | "metadata": {}, 229 | "outputs": [ 230 | { 231 | "data": { 232 | "text/html": [ 233 | "
\n", 234 | "\n", 247 | "\n", 248 | " \n", 249 | " \n", 250 | " \n", 251 | " \n", 252 | " \n", 253 | " \n", 254 | " \n", 255 | " \n", 256 | " \n", 257 | " \n", 258 | " \n", 259 | " \n", 260 | " \n", 261 | " \n", 262 | " \n", 263 | " \n", 264 | " \n", 265 | " \n", 266 | " \n", 267 | " \n", 268 | " \n", 269 | " \n", 270 | " \n", 271 | " \n", 272 | "
Sales
Organization
Coca-Cola320
Dr. Pepper650
Pepsi375
\n", 273 | "
" 274 | ], 275 | "text/plain": [ 276 | " Sales\n", 277 | "Organization \n", 278 | "Coca-Cola 320\n", 279 | "Dr. Pepper 650\n", 280 | "Pepsi 375" 281 | ] 282 | }, 283 | "execution_count": 5, 284 | "metadata": {}, 285 | "output_type": "execute_result" 286 | } 287 | ], 288 | "source": [ 289 | "data.groupby('Organization').sum()" 290 | ] 291 | }, 292 | { 293 | "cell_type": "markdown", 294 | "metadata": {}, 295 | "source": [ 296 | "# Problem 5\n", 297 | "Given the dataset data, print a new DataFrame that applies the describe method to each organization." 298 | ] 299 | }, 300 | { 301 | "cell_type": "code", 302 | "execution_count": 6, 303 | "metadata": {}, 304 | "outputs": [ 305 | { 306 | "data": { 307 | "text/html": [ 308 | "
\n", 309 | "\n", 326 | "\n", 327 | " \n", 328 | " \n", 329 | " \n", 330 | " \n", 331 | " \n", 332 | " \n", 333 | " \n", 334 | " \n", 335 | " \n", 336 | " \n", 337 | " \n", 338 | " \n", 339 | " \n", 340 | " \n", 341 | " \n", 342 | " \n", 343 | " \n", 344 | " \n", 345 | " \n", 346 | " \n", 347 | " \n", 348 | " \n", 349 | " \n", 350 | " \n", 351 | " \n", 352 | " \n", 353 | " \n", 354 | " \n", 355 | " \n", 356 | " \n", 357 | " \n", 358 | " \n", 359 | " \n", 360 | " \n", 361 | " \n", 362 | " \n", 363 | " \n", 364 | " \n", 365 | " \n", 366 | " \n", 367 | " \n", 368 | " \n", 369 | " \n", 370 | " \n", 371 | " \n", 372 | " \n", 373 | " \n", 374 | " \n", 375 | " \n", 376 | " \n", 377 | " \n", 378 | " \n", 379 | " \n", 380 | " \n", 381 | " \n", 382 | " \n", 383 | " \n", 384 | " \n", 385 | " \n", 386 | " \n", 387 | " \n", 388 | " \n", 389 | " \n", 390 | "
Sales
countmeanstdmin25%50%75%max
Organization
Coca-Cola2.0160.056.568542120.0140.00160.0180.00200.0
Dr. Pepper2.0325.0247.487373150.0237.50325.0412.50500.0
Pepsi2.0187.588.388348125.0156.25187.5218.75250.0
\n", 391 | "
" 392 | ], 393 | "text/plain": [ 394 | " Sales \n", 395 | " count mean std min 25% 50% 75% max\n", 396 | "Organization \n", 397 | "Coca-Cola 2.0 160.0 56.568542 120.0 140.00 160.0 180.00 200.0\n", 398 | "Dr. Pepper 2.0 325.0 247.487373 150.0 237.50 325.0 412.50 500.0\n", 399 | "Pepsi 2.0 187.5 88.388348 125.0 156.25 187.5 218.75 250.0" 400 | ] 401 | }, 402 | "execution_count": 6, 403 | "metadata": {}, 404 | "output_type": "execute_result" 405 | } 406 | ], 407 | "source": [ 408 | "data.groupby('Organization').describe()" 409 | ] 410 | }, 411 | { 412 | "cell_type": "code", 413 | "execution_count": null, 414 | "metadata": {}, 415 | "outputs": [], 416 | "source": [] 417 | }, 418 | { 419 | "cell_type": "code", 420 | "execution_count": null, 421 | "metadata": {}, 422 | "outputs": [], 423 | "source": [] 424 | }, 425 | { 426 | "cell_type": "code", 427 | "execution_count": null, 428 | "metadata": {}, 429 | "outputs": [], 430 | "source": [] 431 | } 432 | ], 433 | "metadata": { 434 | "kernelspec": { 435 | "display_name": "Python 3", 436 | "language": "python", 437 | "name": "python3" 438 | }, 439 | "language_info": { 440 | "codemirror_mode": { 441 | "name": "ipython", 442 | "version": 3 443 | }, 444 | "file_extension": ".py", 445 | "mimetype": "text/x-python", 446 | "name": "python", 447 | "nbconvert_exporter": "python", 448 | "pygments_lexer": "ipython3", 449 | "version": "3.8.2" 450 | } 451 | }, 452 | "nbformat": 4, 453 | "nbformat_minor": 4 454 | } 455 | -------------------------------------------------------------------------------- /finished-files/.ipynb_checkpoints/11 - Common Operations in Pandas (Finished)-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Problem 1\n", 8 | "Import NumPy under the alias `np`." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": null, 14 | "metadata": {}, 15 | "outputs": [], 16 | "source": [] 17 | }, 18 | { 19 | "cell_type": "markdown", 20 | "metadata": {}, 21 | "source": [ 22 | "# Problem 2\n", 23 | "Import pandas under the alias `pd`." 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": null, 29 | "metadata": {}, 30 | "outputs": [], 31 | "source": [] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "metadata": {}, 36 | "source": [ 37 | "# Problem 3\n", 38 | "Given the pandas Series `my_series`, generate a NumPy array that contains only the unique values from `my_series`. Assign this new array to a variable called `my_array`. Print `my_array` to ensure that the operation has been executed successfully." 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": null, 44 | "metadata": {}, 45 | "outputs": [], 46 | "source": [ 47 | "my_series = pd.Series([1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9])\n", 48 | "my_series" 49 | ] 50 | }, 51 | { 52 | "cell_type": "code", 53 | "execution_count": null, 54 | "metadata": {}, 55 | "outputs": [], 56 | "source": [ 57 | "#Solution goes here" 58 | ] 59 | }, 60 | { 61 | "cell_type": "markdown", 62 | "metadata": {}, 63 | "source": [ 64 | "# Problem 4\n", 65 | "Given the pandas DataFrame `my_data_frame`, generate a NumPy array that contains only the unique values from the second column. Assign this new array to a variable called `another_array`. Print `another_array` to ensure the operation has been executed successfully." 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "execution_count": null, 71 | "metadata": {}, 72 | "outputs": [], 73 | "source": [ 74 | "my_data_frame = pd.DataFrame(np.random.randn(3,5))\n", 75 | "my_data_frame" 76 | ] 77 | }, 78 | { 79 | "cell_type": "code", 80 | "execution_count": null, 81 | "metadata": {}, 82 | "outputs": [], 83 | "source": [ 84 | "#Solution goes here" 85 | ] 86 | }, 87 | { 88 | "cell_type": "markdown", 89 | "metadata": {}, 90 | "source": [ 91 | "# Problem 5\n", 92 | "Count the occurence of every element within the `my_series` variable that was created earlier in these practice problems." 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": null, 98 | "metadata": {}, 99 | "outputs": [], 100 | "source": [] 101 | }, 102 | { 103 | "cell_type": "markdown", 104 | "metadata": {}, 105 | "source": [ 106 | "# Problem 6\n", 107 | "Given the function `triple_digit`, apply this to every element within `my_series`." 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": null, 113 | "metadata": {}, 114 | "outputs": [], 115 | "source": [ 116 | "def triple_digit(x):\n", 117 | " return x + x*10 + x*100" 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": null, 123 | "metadata": {}, 124 | "outputs": [], 125 | "source": [ 126 | "#Solution goes here" 127 | ] 128 | }, 129 | { 130 | "cell_type": "markdown", 131 | "metadata": {}, 132 | "source": [ 133 | "# Problem 7\n", 134 | "Sort the `my_data_frame` variable that we created earlier based on the contents of its second column." 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": null, 140 | "metadata": {}, 141 | "outputs": [], 142 | "source": [] 143 | } 144 | ], 145 | "metadata": { 146 | "kernelspec": { 147 | "display_name": "Python 3", 148 | "language": "python", 149 | "name": "python3" 150 | }, 151 | "language_info": { 152 | "codemirror_mode": { 153 | "name": "ipython", 154 | "version": 3 155 | }, 156 | "file_extension": ".py", 157 | "mimetype": "text/x-python", 158 | "name": "python", 159 | "nbconvert_exporter": "python", 160 | "pygments_lexer": "ipython3", 161 | "version": "3.8.2" 162 | } 163 | }, 164 | "nbformat": 4, 165 | "nbformat_minor": 4 166 | } 167 | -------------------------------------------------------------------------------- /finished-files/01 - NumPy Arrays (Finished).ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Problem 1\n", 8 | "Import the NumPy library under the alias `np`." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 1, 14 | "metadata": {}, 15 | "outputs": [], 16 | "source": [ 17 | "import numpy as np" 18 | ] 19 | }, 20 | { 21 | "cell_type": "markdown", 22 | "metadata": {}, 23 | "source": [ 24 | "# Problem 2\n", 25 | "Create a NumPy array called `my_array` that contains the following elements: `1`, `3`, and `5`." 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": 2, 31 | "metadata": {}, 32 | "outputs": [], 33 | "source": [ 34 | "my_array = np.array([1, 3, 5])" 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "metadata": {}, 40 | "source": [ 41 | "# Problem 3\n", 42 | "Create a two-dimensional NumPy array with 9 elements. The array should be called `my_matrix` and should have 3 columns and three rows. The matrix can contain whatever values you'd like. " 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 3, 48 | "metadata": {}, 49 | "outputs": [], 50 | "source": [ 51 | "my_matrix = np.array([[1, 2, 3],[4, 5, 6],[7, 8, 9]])" 52 | ] 53 | }, 54 | { 55 | "cell_type": "markdown", 56 | "metadata": {}, 57 | "source": [ 58 | "# Problem 4\n", 59 | "Use NumPy's `arange` method to generate the following output:\n", 60 | "\n", 61 | "`array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,\n", 62 | " 17, 18, 19, 20])`" 63 | ] 64 | }, 65 | { 66 | "cell_type": "code", 67 | "execution_count": 4, 68 | "metadata": {}, 69 | "outputs": [ 70 | { 71 | "data": { 72 | "text/plain": [ 73 | "array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,\n", 74 | " 17, 18, 19, 20])" 75 | ] 76 | }, 77 | "execution_count": 4, 78 | "metadata": {}, 79 | "output_type": "execute_result" 80 | } 81 | ], 82 | "source": [ 83 | "np.arange(0, 21)" 84 | ] 85 | }, 86 | { 87 | "cell_type": "markdown", 88 | "metadata": {}, 89 | "source": [ 90 | "# Problem 5\n", 91 | "Use NumPy's `arange` method to generate the following output:\n", 92 | "\n", 93 | "`array([ 1, 4, 7, 10, 13])`\n", 94 | "\n", 95 | "Hint: You will need to use `arange`'s third argument." 96 | ] 97 | }, 98 | { 99 | "cell_type": "code", 100 | "execution_count": 5, 101 | "metadata": {}, 102 | "outputs": [ 103 | { 104 | "data": { 105 | "text/plain": [ 106 | "array([ 1, 4, 7, 10, 13])" 107 | ] 108 | }, 109 | "execution_count": 5, 110 | "metadata": {}, 111 | "output_type": "execute_result" 112 | } 113 | ], 114 | "source": [ 115 | "np.arange(1,15,3)" 116 | ] 117 | }, 118 | { 119 | "cell_type": "markdown", 120 | "metadata": {}, 121 | "source": [ 122 | "# Problem 6\n", 123 | "Generate a NumPy array that contains 20 zeros." 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": 6, 129 | "metadata": {}, 130 | "outputs": [ 131 | { 132 | "data": { 133 | "text/plain": [ 134 | "array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n", 135 | " 0., 0., 0.])" 136 | ] 137 | }, 138 | "execution_count": 6, 139 | "metadata": {}, 140 | "output_type": "execute_result" 141 | } 142 | ], 143 | "source": [ 144 | "np.zeros(20)" 145 | ] 146 | }, 147 | { 148 | "cell_type": "markdown", 149 | "metadata": {}, 150 | "source": [ 151 | "# Problem 7\n", 152 | "Generate a NumPy array that contains 50 ones." 153 | ] 154 | }, 155 | { 156 | "cell_type": "code", 157 | "execution_count": 7, 158 | "metadata": {}, 159 | "outputs": [ 160 | { 161 | "data": { 162 | "text/plain": [ 163 | "array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,\n", 164 | " 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,\n", 165 | " 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])" 166 | ] 167 | }, 168 | "execution_count": 7, 169 | "metadata": {}, 170 | "output_type": "execute_result" 171 | } 172 | ], 173 | "source": [ 174 | "np.ones(50)" 175 | ] 176 | }, 177 | { 178 | "cell_type": "markdown", 179 | "metadata": {}, 180 | "source": [ 181 | "# Problem 8\n", 182 | "Using NumPy, divide the space between 0 and 100 into 1000 even intervals." 183 | ] 184 | }, 185 | { 186 | "cell_type": "code", 187 | "execution_count": 8, 188 | "metadata": {}, 189 | "outputs": [ 190 | { 191 | "data": { 192 | "text/plain": [ 193 | "array([ 0. , 0.1001001 , 0.2002002 , 0.3003003 ,\n", 194 | " 0.4004004 , 0.5005005 , 0.6006006 , 0.7007007 ,\n", 195 | " 0.8008008 , 0.9009009 , 1.001001 , 1.1011011 ,\n", 196 | " 1.2012012 , 1.3013013 , 1.4014014 , 1.5015015 ,\n", 197 | " 1.6016016 , 1.7017017 , 1.8018018 , 1.9019019 ,\n", 198 | " 2.002002 , 2.1021021 , 2.2022022 , 2.3023023 ,\n", 199 | " 2.4024024 , 2.5025025 , 2.6026026 , 2.7027027 ,\n", 200 | " 2.8028028 , 2.9029029 , 3.003003 , 3.1031031 ,\n", 201 | " 3.2032032 , 3.3033033 , 3.4034034 , 3.5035035 ,\n", 202 | " 3.6036036 , 3.7037037 , 3.8038038 , 3.9039039 ,\n", 203 | " 4.004004 , 4.1041041 , 4.2042042 , 4.3043043 ,\n", 204 | " 4.4044044 , 4.5045045 , 4.6046046 , 4.7047047 ,\n", 205 | " 4.8048048 , 4.9049049 , 5.00500501, 5.10510511,\n", 206 | " 5.20520521, 5.30530531, 5.40540541, 5.50550551,\n", 207 | " 5.60560561, 5.70570571, 5.80580581, 5.90590591,\n", 208 | " 6.00600601, 6.10610611, 6.20620621, 6.30630631,\n", 209 | " 6.40640641, 6.50650651, 6.60660661, 6.70670671,\n", 210 | " 6.80680681, 6.90690691, 7.00700701, 7.10710711,\n", 211 | " 7.20720721, 7.30730731, 7.40740741, 7.50750751,\n", 212 | " 7.60760761, 7.70770771, 7.80780781, 7.90790791,\n", 213 | " 8.00800801, 8.10810811, 8.20820821, 8.30830831,\n", 214 | " 8.40840841, 8.50850851, 8.60860861, 8.70870871,\n", 215 | " 8.80880881, 8.90890891, 9.00900901, 9.10910911,\n", 216 | " 9.20920921, 9.30930931, 9.40940941, 9.50950951,\n", 217 | " 9.60960961, 9.70970971, 9.80980981, 9.90990991,\n", 218 | " 10.01001001, 10.11011011, 10.21021021, 10.31031031,\n", 219 | " 10.41041041, 10.51051051, 10.61061061, 10.71071071,\n", 220 | " 10.81081081, 10.91091091, 11.01101101, 11.11111111,\n", 221 | " 11.21121121, 11.31131131, 11.41141141, 11.51151151,\n", 222 | " 11.61161161, 11.71171171, 11.81181181, 11.91191191,\n", 223 | " 12.01201201, 12.11211211, 12.21221221, 12.31231231,\n", 224 | " 12.41241241, 12.51251251, 12.61261261, 12.71271271,\n", 225 | " 12.81281281, 12.91291291, 13.01301301, 13.11311311,\n", 226 | " 13.21321321, 13.31331331, 13.41341341, 13.51351351,\n", 227 | " 13.61361361, 13.71371371, 13.81381381, 13.91391391,\n", 228 | " 14.01401401, 14.11411411, 14.21421421, 14.31431431,\n", 229 | " 14.41441441, 14.51451451, 14.61461461, 14.71471471,\n", 230 | " 14.81481481, 14.91491491, 15.01501502, 15.11511512,\n", 231 | " 15.21521522, 15.31531532, 15.41541542, 15.51551552,\n", 232 | " 15.61561562, 15.71571572, 15.81581582, 15.91591592,\n", 233 | " 16.01601602, 16.11611612, 16.21621622, 16.31631632,\n", 234 | " 16.41641642, 16.51651652, 16.61661662, 16.71671672,\n", 235 | " 16.81681682, 16.91691692, 17.01701702, 17.11711712,\n", 236 | " 17.21721722, 17.31731732, 17.41741742, 17.51751752,\n", 237 | " 17.61761762, 17.71771772, 17.81781782, 17.91791792,\n", 238 | " 18.01801802, 18.11811812, 18.21821822, 18.31831832,\n", 239 | " 18.41841842, 18.51851852, 18.61861862, 18.71871872,\n", 240 | " 18.81881882, 18.91891892, 19.01901902, 19.11911912,\n", 241 | " 19.21921922, 19.31931932, 19.41941942, 19.51951952,\n", 242 | " 19.61961962, 19.71971972, 19.81981982, 19.91991992,\n", 243 | " 20.02002002, 20.12012012, 20.22022022, 20.32032032,\n", 244 | " 20.42042042, 20.52052052, 20.62062062, 20.72072072,\n", 245 | " 20.82082082, 20.92092092, 21.02102102, 21.12112112,\n", 246 | " 21.22122122, 21.32132132, 21.42142142, 21.52152152,\n", 247 | " 21.62162162, 21.72172172, 21.82182182, 21.92192192,\n", 248 | " 22.02202202, 22.12212212, 22.22222222, 22.32232232,\n", 249 | " 22.42242242, 22.52252252, 22.62262262, 22.72272272,\n", 250 | " 22.82282282, 22.92292292, 23.02302302, 23.12312312,\n", 251 | " 23.22322322, 23.32332332, 23.42342342, 23.52352352,\n", 252 | " 23.62362362, 23.72372372, 23.82382382, 23.92392392,\n", 253 | " 24.02402402, 24.12412412, 24.22422422, 24.32432432,\n", 254 | " 24.42442442, 24.52452452, 24.62462462, 24.72472472,\n", 255 | " 24.82482482, 24.92492492, 25.02502503, 25.12512513,\n", 256 | " 25.22522523, 25.32532533, 25.42542543, 25.52552553,\n", 257 | " 25.62562563, 25.72572573, 25.82582583, 25.92592593,\n", 258 | " 26.02602603, 26.12612613, 26.22622623, 26.32632633,\n", 259 | " 26.42642643, 26.52652653, 26.62662663, 26.72672673,\n", 260 | " 26.82682683, 26.92692693, 27.02702703, 27.12712713,\n", 261 | " 27.22722723, 27.32732733, 27.42742743, 27.52752753,\n", 262 | " 27.62762763, 27.72772773, 27.82782783, 27.92792793,\n", 263 | " 28.02802803, 28.12812813, 28.22822823, 28.32832833,\n", 264 | " 28.42842843, 28.52852853, 28.62862863, 28.72872873,\n", 265 | " 28.82882883, 28.92892893, 29.02902903, 29.12912913,\n", 266 | " 29.22922923, 29.32932933, 29.42942943, 29.52952953,\n", 267 | " 29.62962963, 29.72972973, 29.82982983, 29.92992993,\n", 268 | " 30.03003003, 30.13013013, 30.23023023, 30.33033033,\n", 269 | " 30.43043043, 30.53053053, 30.63063063, 30.73073073,\n", 270 | " 30.83083083, 30.93093093, 31.03103103, 31.13113113,\n", 271 | " 31.23123123, 31.33133133, 31.43143143, 31.53153153,\n", 272 | " 31.63163163, 31.73173173, 31.83183183, 31.93193193,\n", 273 | " 32.03203203, 32.13213213, 32.23223223, 32.33233233,\n", 274 | " 32.43243243, 32.53253253, 32.63263263, 32.73273273,\n", 275 | " 32.83283283, 32.93293293, 33.03303303, 33.13313313,\n", 276 | " 33.23323323, 33.33333333, 33.43343343, 33.53353353,\n", 277 | " 33.63363363, 33.73373373, 33.83383383, 33.93393393,\n", 278 | " 34.03403403, 34.13413413, 34.23423423, 34.33433433,\n", 279 | " 34.43443443, 34.53453453, 34.63463463, 34.73473473,\n", 280 | " 34.83483483, 34.93493493, 35.03503504, 35.13513514,\n", 281 | " 35.23523524, 35.33533534, 35.43543544, 35.53553554,\n", 282 | " 35.63563564, 35.73573574, 35.83583584, 35.93593594,\n", 283 | " 36.03603604, 36.13613614, 36.23623624, 36.33633634,\n", 284 | " 36.43643644, 36.53653654, 36.63663664, 36.73673674,\n", 285 | " 36.83683684, 36.93693694, 37.03703704, 37.13713714,\n", 286 | " 37.23723724, 37.33733734, 37.43743744, 37.53753754,\n", 287 | " 37.63763764, 37.73773774, 37.83783784, 37.93793794,\n", 288 | " 38.03803804, 38.13813814, 38.23823824, 38.33833834,\n", 289 | " 38.43843844, 38.53853854, 38.63863864, 38.73873874,\n", 290 | " 38.83883884, 38.93893894, 39.03903904, 39.13913914,\n", 291 | " 39.23923924, 39.33933934, 39.43943944, 39.53953954,\n", 292 | " 39.63963964, 39.73973974, 39.83983984, 39.93993994,\n", 293 | " 40.04004004, 40.14014014, 40.24024024, 40.34034034,\n", 294 | " 40.44044044, 40.54054054, 40.64064064, 40.74074074,\n", 295 | " 40.84084084, 40.94094094, 41.04104104, 41.14114114,\n", 296 | " 41.24124124, 41.34134134, 41.44144144, 41.54154154,\n", 297 | " 41.64164164, 41.74174174, 41.84184184, 41.94194194,\n", 298 | " 42.04204204, 42.14214214, 42.24224224, 42.34234234,\n", 299 | " 42.44244244, 42.54254254, 42.64264264, 42.74274274,\n", 300 | " 42.84284284, 42.94294294, 43.04304304, 43.14314314,\n", 301 | " 43.24324324, 43.34334334, 43.44344344, 43.54354354,\n", 302 | " 43.64364364, 43.74374374, 43.84384384, 43.94394394,\n", 303 | " 44.04404404, 44.14414414, 44.24424424, 44.34434434,\n", 304 | " 44.44444444, 44.54454454, 44.64464464, 44.74474474,\n", 305 | " 44.84484484, 44.94494494, 45.04504505, 45.14514515,\n", 306 | " 45.24524525, 45.34534535, 45.44544545, 45.54554555,\n", 307 | " 45.64564565, 45.74574575, 45.84584585, 45.94594595,\n", 308 | " 46.04604605, 46.14614615, 46.24624625, 46.34634635,\n", 309 | " 46.44644645, 46.54654655, 46.64664665, 46.74674675,\n", 310 | " 46.84684685, 46.94694695, 47.04704705, 47.14714715,\n", 311 | " 47.24724725, 47.34734735, 47.44744745, 47.54754755,\n", 312 | " 47.64764765, 47.74774775, 47.84784785, 47.94794795,\n", 313 | " 48.04804805, 48.14814815, 48.24824825, 48.34834835,\n", 314 | " 48.44844845, 48.54854855, 48.64864865, 48.74874875,\n", 315 | " 48.84884885, 48.94894895, 49.04904905, 49.14914915,\n", 316 | " 49.24924925, 49.34934935, 49.44944945, 49.54954955,\n", 317 | " 49.64964965, 49.74974975, 49.84984985, 49.94994995,\n", 318 | " 50.05005005, 50.15015015, 50.25025025, 50.35035035,\n", 319 | " 50.45045045, 50.55055055, 50.65065065, 50.75075075,\n", 320 | " 50.85085085, 50.95095095, 51.05105105, 51.15115115,\n", 321 | " 51.25125125, 51.35135135, 51.45145145, 51.55155155,\n", 322 | " 51.65165165, 51.75175175, 51.85185185, 51.95195195,\n", 323 | " 52.05205205, 52.15215215, 52.25225225, 52.35235235,\n", 324 | " 52.45245245, 52.55255255, 52.65265265, 52.75275275,\n", 325 | " 52.85285285, 52.95295295, 53.05305305, 53.15315315,\n", 326 | " 53.25325325, 53.35335335, 53.45345345, 53.55355355,\n", 327 | " 53.65365365, 53.75375375, 53.85385385, 53.95395395,\n", 328 | " 54.05405405, 54.15415415, 54.25425425, 54.35435435,\n", 329 | " 54.45445445, 54.55455455, 54.65465465, 54.75475475,\n", 330 | " 54.85485485, 54.95495495, 55.05505506, 55.15515516,\n", 331 | " 55.25525526, 55.35535536, 55.45545546, 55.55555556,\n", 332 | " 55.65565566, 55.75575576, 55.85585586, 55.95595596,\n", 333 | " 56.05605606, 56.15615616, 56.25625626, 56.35635636,\n", 334 | " 56.45645646, 56.55655656, 56.65665666, 56.75675676,\n", 335 | " 56.85685686, 56.95695696, 57.05705706, 57.15715716,\n", 336 | " 57.25725726, 57.35735736, 57.45745746, 57.55755756,\n", 337 | " 57.65765766, 57.75775776, 57.85785786, 57.95795796,\n", 338 | " 58.05805806, 58.15815816, 58.25825826, 58.35835836,\n", 339 | " 58.45845846, 58.55855856, 58.65865866, 58.75875876,\n", 340 | " 58.85885886, 58.95895896, 59.05905906, 59.15915916,\n", 341 | " 59.25925926, 59.35935936, 59.45945946, 59.55955956,\n", 342 | " 59.65965966, 59.75975976, 59.85985986, 59.95995996,\n", 343 | " 60.06006006, 60.16016016, 60.26026026, 60.36036036,\n", 344 | " 60.46046046, 60.56056056, 60.66066066, 60.76076076,\n", 345 | " 60.86086086, 60.96096096, 61.06106106, 61.16116116,\n", 346 | " 61.26126126, 61.36136136, 61.46146146, 61.56156156,\n", 347 | " 61.66166166, 61.76176176, 61.86186186, 61.96196196,\n", 348 | " 62.06206206, 62.16216216, 62.26226226, 62.36236236,\n", 349 | " 62.46246246, 62.56256256, 62.66266266, 62.76276276,\n", 350 | " 62.86286286, 62.96296296, 63.06306306, 63.16316316,\n", 351 | " 63.26326326, 63.36336336, 63.46346346, 63.56356356,\n", 352 | " 63.66366366, 63.76376376, 63.86386386, 63.96396396,\n", 353 | " 64.06406406, 64.16416416, 64.26426426, 64.36436436,\n", 354 | " 64.46446446, 64.56456456, 64.66466466, 64.76476476,\n", 355 | " 64.86486486, 64.96496496, 65.06506507, 65.16516517,\n", 356 | " 65.26526527, 65.36536537, 65.46546547, 65.56556557,\n", 357 | " 65.66566567, 65.76576577, 65.86586587, 65.96596597,\n", 358 | " 66.06606607, 66.16616617, 66.26626627, 66.36636637,\n", 359 | " 66.46646647, 66.56656657, 66.66666667, 66.76676677,\n", 360 | " 66.86686687, 66.96696697, 67.06706707, 67.16716717,\n", 361 | " 67.26726727, 67.36736737, 67.46746747, 67.56756757,\n", 362 | " 67.66766767, 67.76776777, 67.86786787, 67.96796797,\n", 363 | " 68.06806807, 68.16816817, 68.26826827, 68.36836837,\n", 364 | " 68.46846847, 68.56856857, 68.66866867, 68.76876877,\n", 365 | " 68.86886887, 68.96896897, 69.06906907, 69.16916917,\n", 366 | " 69.26926927, 69.36936937, 69.46946947, 69.56956957,\n", 367 | " 69.66966967, 69.76976977, 69.86986987, 69.96996997,\n", 368 | " 70.07007007, 70.17017017, 70.27027027, 70.37037037,\n", 369 | " 70.47047047, 70.57057057, 70.67067067, 70.77077077,\n", 370 | " 70.87087087, 70.97097097, 71.07107107, 71.17117117,\n", 371 | " 71.27127127, 71.37137137, 71.47147147, 71.57157157,\n", 372 | " 71.67167167, 71.77177177, 71.87187187, 71.97197197,\n", 373 | " 72.07207207, 72.17217217, 72.27227227, 72.37237237,\n", 374 | " 72.47247247, 72.57257257, 72.67267267, 72.77277277,\n", 375 | " 72.87287287, 72.97297297, 73.07307307, 73.17317317,\n", 376 | " 73.27327327, 73.37337337, 73.47347347, 73.57357357,\n", 377 | " 73.67367367, 73.77377377, 73.87387387, 73.97397397,\n", 378 | " 74.07407407, 74.17417417, 74.27427427, 74.37437437,\n", 379 | " 74.47447447, 74.57457457, 74.67467467, 74.77477477,\n", 380 | " 74.87487487, 74.97497497, 75.07507508, 75.17517518,\n", 381 | " 75.27527528, 75.37537538, 75.47547548, 75.57557558,\n", 382 | " 75.67567568, 75.77577578, 75.87587588, 75.97597598,\n", 383 | " 76.07607608, 76.17617618, 76.27627628, 76.37637638,\n", 384 | " 76.47647648, 76.57657658, 76.67667668, 76.77677678,\n", 385 | " 76.87687688, 76.97697698, 77.07707708, 77.17717718,\n", 386 | " 77.27727728, 77.37737738, 77.47747748, 77.57757758,\n", 387 | " 77.67767768, 77.77777778, 77.87787788, 77.97797798,\n", 388 | " 78.07807808, 78.17817818, 78.27827828, 78.37837838,\n", 389 | " 78.47847848, 78.57857858, 78.67867868, 78.77877878,\n", 390 | " 78.87887888, 78.97897898, 79.07907908, 79.17917918,\n", 391 | " 79.27927928, 79.37937938, 79.47947948, 79.57957958,\n", 392 | " 79.67967968, 79.77977978, 79.87987988, 79.97997998,\n", 393 | " 80.08008008, 80.18018018, 80.28028028, 80.38038038,\n", 394 | " 80.48048048, 80.58058058, 80.68068068, 80.78078078,\n", 395 | " 80.88088088, 80.98098098, 81.08108108, 81.18118118,\n", 396 | " 81.28128128, 81.38138138, 81.48148148, 81.58158158,\n", 397 | " 81.68168168, 81.78178178, 81.88188188, 81.98198198,\n", 398 | " 82.08208208, 82.18218218, 82.28228228, 82.38238238,\n", 399 | " 82.48248248, 82.58258258, 82.68268268, 82.78278278,\n", 400 | " 82.88288288, 82.98298298, 83.08308308, 83.18318318,\n", 401 | " 83.28328328, 83.38338338, 83.48348348, 83.58358358,\n", 402 | " 83.68368368, 83.78378378, 83.88388388, 83.98398398,\n", 403 | " 84.08408408, 84.18418418, 84.28428428, 84.38438438,\n", 404 | " 84.48448448, 84.58458458, 84.68468468, 84.78478478,\n", 405 | " 84.88488488, 84.98498498, 85.08508509, 85.18518519,\n", 406 | " 85.28528529, 85.38538539, 85.48548549, 85.58558559,\n", 407 | " 85.68568569, 85.78578579, 85.88588589, 85.98598599,\n", 408 | " 86.08608609, 86.18618619, 86.28628629, 86.38638639,\n", 409 | " 86.48648649, 86.58658659, 86.68668669, 86.78678679,\n", 410 | " 86.88688689, 86.98698699, 87.08708709, 87.18718719,\n", 411 | " 87.28728729, 87.38738739, 87.48748749, 87.58758759,\n", 412 | " 87.68768769, 87.78778779, 87.88788789, 87.98798799,\n", 413 | " 88.08808809, 88.18818819, 88.28828829, 88.38838839,\n", 414 | " 88.48848849, 88.58858859, 88.68868869, 88.78878879,\n", 415 | " 88.88888889, 88.98898899, 89.08908909, 89.18918919,\n", 416 | " 89.28928929, 89.38938939, 89.48948949, 89.58958959,\n", 417 | " 89.68968969, 89.78978979, 89.88988989, 89.98998999,\n", 418 | " 90.09009009, 90.19019019, 90.29029029, 90.39039039,\n", 419 | " 90.49049049, 90.59059059, 90.69069069, 90.79079079,\n", 420 | " 90.89089089, 90.99099099, 91.09109109, 91.19119119,\n", 421 | " 91.29129129, 91.39139139, 91.49149149, 91.59159159,\n", 422 | " 91.69169169, 91.79179179, 91.89189189, 91.99199199,\n", 423 | " 92.09209209, 92.19219219, 92.29229229, 92.39239239,\n", 424 | " 92.49249249, 92.59259259, 92.69269269, 92.79279279,\n", 425 | " 92.89289289, 92.99299299, 93.09309309, 93.19319319,\n", 426 | " 93.29329329, 93.39339339, 93.49349349, 93.59359359,\n", 427 | " 93.69369369, 93.79379379, 93.89389389, 93.99399399,\n", 428 | " 94.09409409, 94.19419419, 94.29429429, 94.39439439,\n", 429 | " 94.49449449, 94.59459459, 94.69469469, 94.79479479,\n", 430 | " 94.89489489, 94.99499499, 95.0950951 , 95.1951952 ,\n", 431 | " 95.2952953 , 95.3953954 , 95.4954955 , 95.5955956 ,\n", 432 | " 95.6956957 , 95.7957958 , 95.8958959 , 95.995996 ,\n", 433 | " 96.0960961 , 96.1961962 , 96.2962963 , 96.3963964 ,\n", 434 | " 96.4964965 , 96.5965966 , 96.6966967 , 96.7967968 ,\n", 435 | " 96.8968969 , 96.996997 , 97.0970971 , 97.1971972 ,\n", 436 | " 97.2972973 , 97.3973974 , 97.4974975 , 97.5975976 ,\n", 437 | " 97.6976977 , 97.7977978 , 97.8978979 , 97.997998 ,\n", 438 | " 98.0980981 , 98.1981982 , 98.2982983 , 98.3983984 ,\n", 439 | " 98.4984985 , 98.5985986 , 98.6986987 , 98.7987988 ,\n", 440 | " 98.8988989 , 98.998999 , 99.0990991 , 99.1991992 ,\n", 441 | " 99.2992993 , 99.3993994 , 99.4994995 , 99.5995996 ,\n", 442 | " 99.6996997 , 99.7997998 , 99.8998999 , 100. ])" 443 | ] 444 | }, 445 | "execution_count": 8, 446 | "metadata": {}, 447 | "output_type": "execute_result" 448 | } 449 | ], 450 | "source": [ 451 | "np.linspace(0,100,1000)" 452 | ] 453 | }, 454 | { 455 | "cell_type": "markdown", 456 | "metadata": {}, 457 | "source": [ 458 | "# Problem 9\n", 459 | "Create a 10x10 identity matrix using NumPy." 460 | ] 461 | }, 462 | { 463 | "cell_type": "code", 464 | "execution_count": 9, 465 | "metadata": {}, 466 | "outputs": [ 467 | { 468 | "data": { 469 | "text/plain": [ 470 | "array([[1., 0., 0., 0., 0., 0., 0., 0., 0., 0.],\n", 471 | " [0., 1., 0., 0., 0., 0., 0., 0., 0., 0.],\n", 472 | " [0., 0., 1., 0., 0., 0., 0., 0., 0., 0.],\n", 473 | " [0., 0., 0., 1., 0., 0., 0., 0., 0., 0.],\n", 474 | " [0., 0., 0., 0., 1., 0., 0., 0., 0., 0.],\n", 475 | " [0., 0., 0., 0., 0., 1., 0., 0., 0., 0.],\n", 476 | " [0., 0., 0., 0., 0., 0., 1., 0., 0., 0.],\n", 477 | " [0., 0., 0., 0., 0., 0., 0., 1., 0., 0.],\n", 478 | " [0., 0., 0., 0., 0., 0., 0., 0., 1., 0.],\n", 479 | " [0., 0., 0., 0., 0., 0., 0., 0., 0., 1.]])" 480 | ] 481 | }, 482 | "execution_count": 9, 483 | "metadata": {}, 484 | "output_type": "execute_result" 485 | } 486 | ], 487 | "source": [ 488 | "np.eye(10)" 489 | ] 490 | }, 491 | { 492 | "cell_type": "markdown", 493 | "metadata": {}, 494 | "source": [ 495 | "# Problem 10\n", 496 | "Returns a random sample of numbers with 10 values where each value is between 0 and 1." 497 | ] 498 | }, 499 | { 500 | "cell_type": "code", 501 | "execution_count": 10, 502 | "metadata": {}, 503 | "outputs": [ 504 | { 505 | "data": { 506 | "text/plain": [ 507 | "array([0.19170402, 0.55645186, 0.65700129, 0.1648909 , 0.58771596,\n", 508 | " 0.78439065, 0.06312085, 0.46611294, 0.57032727, 0.31190655])" 509 | ] 510 | }, 511 | "execution_count": 10, 512 | "metadata": {}, 513 | "output_type": "execute_result" 514 | } 515 | ], 516 | "source": [ 517 | "np.random.rand(10)" 518 | ] 519 | }, 520 | { 521 | "cell_type": "markdown", 522 | "metadata": {}, 523 | "source": [ 524 | "# Problem 11\n", 525 | "Returns a random sample of numbers with 10 values where each value is between 0 and 10.\n", 526 | "\n", 527 | "Hint: Use the `random.rand` method combined with a multiplication operation." 528 | ] 529 | }, 530 | { 531 | "cell_type": "code", 532 | "execution_count": 11, 533 | "metadata": {}, 534 | "outputs": [ 535 | { 536 | "data": { 537 | "text/plain": [ 538 | "array([1.80533202, 8.3994994 , 1.57603441, 9.13256339, 9.97815142,\n", 539 | " 4.7302086 , 3.80373864, 4.678893 , 0.96672324, 8.55569928])" 540 | ] 541 | }, 542 | "execution_count": 11, 543 | "metadata": {}, 544 | "output_type": "execute_result" 545 | } 546 | ], 547 | "source": [ 548 | "np.random.rand(10)*10" 549 | ] 550 | }, 551 | { 552 | "cell_type": "markdown", 553 | "metadata": {}, 554 | "source": [ 555 | "# Problem 12\n", 556 | "Generate a random sample of 15 numbers from a normal distribution." 557 | ] 558 | }, 559 | { 560 | "cell_type": "code", 561 | "execution_count": 12, 562 | "metadata": {}, 563 | "outputs": [ 564 | { 565 | "data": { 566 | "text/plain": [ 567 | "array([-0.34623648, 0.31064557, -0.4459493 , -1.40253534, 0.49850674,\n", 568 | " -0.29975628, 1.21338415, -0.484629 , -0.4221513 , 1.01339043,\n", 569 | " 1.00563727, 0.73421987, -0.62300471, 0.84863864, 0.32504362])" 570 | ] 571 | }, 572 | "execution_count": 12, 573 | "metadata": {}, 574 | "output_type": "execute_result" 575 | } 576 | ], 577 | "source": [ 578 | "np.random.randn(15)" 579 | ] 580 | }, 581 | { 582 | "cell_type": "markdown", 583 | "metadata": {}, 584 | "source": [ 585 | "# Problem 13\n", 586 | "Generate a random sample of 7 integers that range between 5 and 10." 587 | ] 588 | }, 589 | { 590 | "cell_type": "code", 591 | "execution_count": 13, 592 | "metadata": {}, 593 | "outputs": [ 594 | { 595 | "data": { 596 | "text/plain": [ 597 | "array([6, 5, 7, 7, 5, 8, 8])" 598 | ] 599 | }, 600 | "execution_count": 13, 601 | "metadata": {}, 602 | "output_type": "execute_result" 603 | } 604 | ], 605 | "source": [ 606 | "np.random.randint(5, 10, 7)" 607 | ] 608 | }, 609 | { 610 | "cell_type": "markdown", 611 | "metadata": {}, 612 | "source": [ 613 | "# Problem 14\n", 614 | "Reshape the following one-dimensional NumPy array into a two-dimensional Numpy array with 3 rows and 3 columns." 615 | ] 616 | }, 617 | { 618 | "cell_type": "code", 619 | "execution_count": 14, 620 | "metadata": {}, 621 | "outputs": [ 622 | { 623 | "data": { 624 | "text/plain": [ 625 | "array([[0, 1, 2],\n", 626 | " [3, 4, 5],\n", 627 | " [6, 7, 8]])" 628 | ] 629 | }, 630 | "execution_count": 14, 631 | "metadata": {}, 632 | "output_type": "execute_result" 633 | } 634 | ], 635 | "source": [ 636 | "arr = np.array([0,1,2,3,4,5,6,7,8])\n", 637 | "arr.reshape(3,3)" 638 | ] 639 | }, 640 | { 641 | "cell_type": "markdown", 642 | "metadata": {}, 643 | "source": [ 644 | "# Problem 15\n", 645 | "Print the minimum and maximum values of the following NumPy array." 646 | ] 647 | }, 648 | { 649 | "cell_type": "code", 650 | "execution_count": 15, 651 | "metadata": {}, 652 | "outputs": [], 653 | "source": [ 654 | "arr = np.array([0,1,2,3,4,5,6,7,8])" 655 | ] 656 | }, 657 | { 658 | "cell_type": "code", 659 | "execution_count": 16, 660 | "metadata": {}, 661 | "outputs": [ 662 | { 663 | "data": { 664 | "text/plain": [ 665 | "0" 666 | ] 667 | }, 668 | "execution_count": 16, 669 | "metadata": {}, 670 | "output_type": "execute_result" 671 | } 672 | ], 673 | "source": [ 674 | "#Print the minimum value here.\n", 675 | "arr.min()" 676 | ] 677 | }, 678 | { 679 | "cell_type": "code", 680 | "execution_count": 17, 681 | "metadata": {}, 682 | "outputs": [ 683 | { 684 | "data": { 685 | "text/plain": [ 686 | "8" 687 | ] 688 | }, 689 | "execution_count": 17, 690 | "metadata": {}, 691 | "output_type": "execute_result" 692 | } 693 | ], 694 | "source": [ 695 | "#Print the maximum value here.\n", 696 | "arr.max()" 697 | ] 698 | }, 699 | { 700 | "cell_type": "markdown", 701 | "metadata": {}, 702 | "source": [ 703 | "# Problem 16\n", 704 | "For the following NumPy array, print the index of the minimum and maximum values." 705 | ] 706 | }, 707 | { 708 | "cell_type": "code", 709 | "execution_count": 18, 710 | "metadata": {}, 711 | "outputs": [], 712 | "source": [ 713 | "my_array = np.array([6, 7, 0, 2])" 714 | ] 715 | }, 716 | { 717 | "cell_type": "code", 718 | "execution_count": 19, 719 | "metadata": {}, 720 | "outputs": [ 721 | { 722 | "data": { 723 | "text/plain": [ 724 | "2" 725 | ] 726 | }, 727 | "execution_count": 19, 728 | "metadata": {}, 729 | "output_type": "execute_result" 730 | } 731 | ], 732 | "source": [ 733 | "#Print the minimum value's index here.\n", 734 | "my_array.argmin()" 735 | ] 736 | }, 737 | { 738 | "cell_type": "code", 739 | "execution_count": 20, 740 | "metadata": {}, 741 | "outputs": [ 742 | { 743 | "data": { 744 | "text/plain": [ 745 | "1" 746 | ] 747 | }, 748 | "execution_count": 20, 749 | "metadata": {}, 750 | "output_type": "execute_result" 751 | } 752 | ], 753 | "source": [ 754 | "#Print the maximum value's index here.\n", 755 | "my_array.argmax()" 756 | ] 757 | } 758 | ], 759 | "metadata": { 760 | "kernelspec": { 761 | "display_name": "Python 3", 762 | "language": "python", 763 | "name": "python3" 764 | }, 765 | "language_info": { 766 | "codemirror_mode": { 767 | "name": "ipython", 768 | "version": 3 769 | }, 770 | "file_extension": ".py", 771 | "mimetype": "text/x-python", 772 | "name": "python", 773 | "nbconvert_exporter": "python", 774 | "pygments_lexer": "ipython3", 775 | "version": "3.7.6" 776 | } 777 | }, 778 | "nbformat": 4, 779 | "nbformat_minor": 4 780 | } 781 | -------------------------------------------------------------------------------- /finished-files/02 - NumPy Methods and Operations (Finished).ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Problem 1\n", 8 | "Import the NumPy library under the alias `np`." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 1, 14 | "metadata": {}, 15 | "outputs": [], 16 | "source": [ 17 | "import numpy as np" 18 | ] 19 | }, 20 | { 21 | "cell_type": "markdown", 22 | "metadata": {}, 23 | "source": [ 24 | "# Problem 2\n", 25 | "Add `2` to every element of the following NumPy array." 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": 2, 31 | "metadata": {}, 32 | "outputs": [ 33 | { 34 | "data": { 35 | "text/plain": [ 36 | "array([ 4, 5, 6, 11, 9, 7, 10, 4])" 37 | ] 38 | }, 39 | "execution_count": 2, 40 | "metadata": {}, 41 | "output_type": "execute_result" 42 | } 43 | ], 44 | "source": [ 45 | "arr = np.array([2,3,4,9,7,5,8,2])\n", 46 | "arr+2" 47 | ] 48 | }, 49 | { 50 | "cell_type": "markdown", 51 | "metadata": {}, 52 | "source": [ 53 | "# Problem 3\n", 54 | "Double the value of every element in `arr` by adding it to itself." 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": 3, 60 | "metadata": {}, 61 | "outputs": [ 62 | { 63 | "data": { 64 | "text/plain": [ 65 | "array([ 4, 6, 8, 18, 14, 10, 16, 4])" 66 | ] 67 | }, 68 | "execution_count": 3, 69 | "metadata": {}, 70 | "output_type": "execute_result" 71 | } 72 | ], 73 | "source": [ 74 | "arr + arr" 75 | ] 76 | }, 77 | { 78 | "cell_type": "markdown", 79 | "metadata": {}, 80 | "source": [ 81 | "# Problem 4\n", 82 | "Create an array of zeros by subtracting `arr` from itself." 83 | ] 84 | }, 85 | { 86 | "cell_type": "code", 87 | "execution_count": 4, 88 | "metadata": {}, 89 | "outputs": [ 90 | { 91 | "data": { 92 | "text/plain": [ 93 | "array([0, 0, 0, 0, 0, 0, 0, 0])" 94 | ] 95 | }, 96 | "execution_count": 4, 97 | "metadata": {}, 98 | "output_type": "execute_result" 99 | } 100 | ], 101 | "source": [ 102 | "arr - arr" 103 | ] 104 | }, 105 | { 106 | "cell_type": "markdown", 107 | "metadata": {}, 108 | "source": [ 109 | "# Problem 5\n", 110 | "Multiply every element in `arr` by 6." 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": 5, 116 | "metadata": {}, 117 | "outputs": [ 118 | { 119 | "data": { 120 | "text/plain": [ 121 | "array([12, 18, 24, 54, 42, 30, 48, 12])" 122 | ] 123 | }, 124 | "execution_count": 5, 125 | "metadata": {}, 126 | "output_type": "execute_result" 127 | } 128 | ], 129 | "source": [ 130 | "arr * 6" 131 | ] 132 | }, 133 | { 134 | "cell_type": "markdown", 135 | "metadata": {}, 136 | "source": [ 137 | "# Problem 6\n", 138 | "Divide every element in `arr` by 4." 139 | ] 140 | }, 141 | { 142 | "cell_type": "code", 143 | "execution_count": 6, 144 | "metadata": {}, 145 | "outputs": [ 146 | { 147 | "data": { 148 | "text/plain": [ 149 | "array([0.5 , 0.75, 1. , 2.25, 1.75, 1.25, 2. , 0.5 ])" 150 | ] 151 | }, 152 | "execution_count": 6, 153 | "metadata": {}, 154 | "output_type": "execute_result" 155 | } 156 | ], 157 | "source": [ 158 | "arr / 4" 159 | ] 160 | }, 161 | { 162 | "cell_type": "markdown", 163 | "metadata": {}, 164 | "source": [ 165 | "# Problem 7\n", 166 | "Create an array of ones by dividing every element in `arr` by itself." 167 | ] 168 | }, 169 | { 170 | "cell_type": "code", 171 | "execution_count": 7, 172 | "metadata": {}, 173 | "outputs": [ 174 | { 175 | "data": { 176 | "text/plain": [ 177 | "array([1., 1., 1., 1., 1., 1., 1., 1.])" 178 | ] 179 | }, 180 | "execution_count": 7, 181 | "metadata": {}, 182 | "output_type": "execute_result" 183 | } 184 | ], 185 | "source": [ 186 | "arr / arr" 187 | ] 188 | }, 189 | { 190 | "cell_type": "markdown", 191 | "metadata": {}, 192 | "source": [ 193 | "# Problem 8\n", 194 | "Calculate the square root of every element in `arr`. Do not use the `**` operator." 195 | ] 196 | }, 197 | { 198 | "cell_type": "code", 199 | "execution_count": 8, 200 | "metadata": {}, 201 | "outputs": [ 202 | { 203 | "data": { 204 | "text/plain": [ 205 | "array([1.41421356, 1.73205081, 2. , 3. , 2.64575131,\n", 206 | " 2.23606798, 2.82842712, 1.41421356])" 207 | ] 208 | }, 209 | "execution_count": 8, 210 | "metadata": {}, 211 | "output_type": "execute_result" 212 | } 213 | ], 214 | "source": [ 215 | "np.sqrt(arr)" 216 | ] 217 | } 218 | ], 219 | "metadata": { 220 | "kernelspec": { 221 | "display_name": "Python 3", 222 | "language": "python", 223 | "name": "python3" 224 | }, 225 | "language_info": { 226 | "codemirror_mode": { 227 | "name": "ipython", 228 | "version": 3 229 | }, 230 | "file_extension": ".py", 231 | "mimetype": "text/x-python", 232 | "name": "python", 233 | "nbconvert_exporter": "python", 234 | "pygments_lexer": "ipython3", 235 | "version": "3.7.6" 236 | } 237 | }, 238 | "nbformat": 4, 239 | "nbformat_minor": 4 240 | } 241 | -------------------------------------------------------------------------------- /finished-files/03 - NumPy Indexing and Assignment (Finished).ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Problem 1\n", 8 | "Import the NumPy library under the alias `np`." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 1, 14 | "metadata": {}, 15 | "outputs": [], 16 | "source": [ 17 | "import numpy as np" 18 | ] 19 | }, 20 | { 21 | "cell_type": "markdown", 22 | "metadata": {}, 23 | "source": [ 24 | "# Problem 2\n", 25 | "Given the following NumPy array, return the first element and the last element." 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": 2, 31 | "metadata": {}, 32 | "outputs": [], 33 | "source": [ 34 | "arr = np.array([8,2,4,9,7,3,8,1])" 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": 3, 40 | "metadata": {}, 41 | "outputs": [ 42 | { 43 | "data": { 44 | "text/plain": [ 45 | "8" 46 | ] 47 | }, 48 | "execution_count": 3, 49 | "metadata": {}, 50 | "output_type": "execute_result" 51 | } 52 | ], 53 | "source": [ 54 | "#Return the first element here\n", 55 | "arr[0]" 56 | ] 57 | }, 58 | { 59 | "cell_type": "code", 60 | "execution_count": 4, 61 | "metadata": {}, 62 | "outputs": [ 63 | { 64 | "data": { 65 | "text/plain": [ 66 | "1" 67 | ] 68 | }, 69 | "execution_count": 4, 70 | "metadata": {}, 71 | "output_type": "execute_result" 72 | } 73 | ], 74 | "source": [ 75 | "#Returns the last element here\n", 76 | "arr[-1]" 77 | ] 78 | }, 79 | { 80 | "cell_type": "markdown", 81 | "metadata": {}, 82 | "source": [ 83 | "# Problem 3\n", 84 | "Given the following NumPy array, return the entire array except for the last element." 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": 5, 90 | "metadata": {}, 91 | "outputs": [], 92 | "source": [ 93 | "new_arr = np.array([1,6,4,8,7,5,2,1,4,5,6,1,4,5,6,2,1])" 94 | ] 95 | }, 96 | { 97 | "cell_type": "code", 98 | "execution_count": 6, 99 | "metadata": {}, 100 | "outputs": [ 101 | { 102 | "data": { 103 | "text/plain": [ 104 | "array([1, 6, 4, 8, 7, 5, 2, 1, 4, 5, 6, 1, 4, 5, 6, 2])" 105 | ] 106 | }, 107 | "execution_count": 6, 108 | "metadata": {}, 109 | "output_type": "execute_result" 110 | } 111 | ], 112 | "source": [ 113 | "#Place your solution here\n", 114 | "new_arr[:-1]" 115 | ] 116 | }, 117 | { 118 | "cell_type": "markdown", 119 | "metadata": {}, 120 | "source": [ 121 | "# Problem 4\n", 122 | "Change the second element of `this_arr` to `4`." 123 | ] 124 | }, 125 | { 126 | "cell_type": "code", 127 | "execution_count": 7, 128 | "metadata": {}, 129 | "outputs": [], 130 | "source": [ 131 | "this_arr = np.array([2,4,89,7,5,4,2,6,4,5,78,1,6,9,7,456,12,45])" 132 | ] 133 | }, 134 | { 135 | "cell_type": "code", 136 | "execution_count": 8, 137 | "metadata": {}, 138 | "outputs": [], 139 | "source": [ 140 | "#Place your solution here\n", 141 | "this_arr[1] = 4" 142 | ] 143 | }, 144 | { 145 | "cell_type": "markdown", 146 | "metadata": {}, 147 | "source": [ 148 | "# Problem 5\n", 149 | "Given the array `original_array`, create a reference to that array called `reference_array`. Change the second element of `reference_array` to `16` and then print `original_array` to verify that it modified the original data structure." 150 | ] 151 | }, 152 | { 153 | "cell_type": "code", 154 | "execution_count": 9, 155 | "metadata": {}, 156 | "outputs": [], 157 | "source": [ 158 | "original_array = np.array([12,45,86,79,45,26,13,46,28])" 159 | ] 160 | }, 161 | { 162 | "cell_type": "code", 163 | "execution_count": 10, 164 | "metadata": {}, 165 | "outputs": [ 166 | { 167 | "data": { 168 | "text/plain": [ 169 | "array([12, 16, 86, 79, 45, 26, 13, 46, 28])" 170 | ] 171 | }, 172 | "execution_count": 10, 173 | "metadata": {}, 174 | "output_type": "execute_result" 175 | } 176 | ], 177 | "source": [ 178 | "#Solution goes here\n", 179 | "reference_array = original_array\n", 180 | "reference_array[1] = 16\n", 181 | "original_array" 182 | ] 183 | }, 184 | { 185 | "cell_type": "markdown", 186 | "metadata": {}, 187 | "source": [ 188 | "# Problem 6\n", 189 | "Given the array `first_array`, create a copy of the array called `copy_array`. Change the third element of `copy_array` to `42` and then print `first_array` to verify that its elements remain unchanged." 190 | ] 191 | }, 192 | { 193 | "cell_type": "code", 194 | "execution_count": 11, 195 | "metadata": {}, 196 | "outputs": [], 197 | "source": [ 198 | "first_array = np.array([16,45,75,16,43,45,78,19,23,46,79,58])" 199 | ] 200 | }, 201 | { 202 | "cell_type": "code", 203 | "execution_count": 12, 204 | "metadata": {}, 205 | "outputs": [ 206 | { 207 | "data": { 208 | "text/plain": [ 209 | "array([16, 45, 75, 16, 43, 45, 78, 19, 23, 46, 79, 58])" 210 | ] 211 | }, 212 | "execution_count": 12, 213 | "metadata": {}, 214 | "output_type": "execute_result" 215 | } 216 | ], 217 | "source": [ 218 | "#Solution goes here\n", 219 | "copy_array = first_array.copy()\n", 220 | "\n", 221 | "copy_array[2] = 42\n", 222 | "first_array" 223 | ] 224 | }, 225 | { 226 | "cell_type": "markdown", 227 | "metadata": {}, 228 | "source": [ 229 | "# Problem 7\n", 230 | "Given the two-dimensional array `matrix`, print the value `35`." 231 | ] 232 | }, 233 | { 234 | "cell_type": "code", 235 | "execution_count": 13, 236 | "metadata": {}, 237 | "outputs": [], 238 | "source": [ 239 | "matrix = np.array([[15, 120, 115],[230, 35, 130],[335, 420, 425]])" 240 | ] 241 | }, 242 | { 243 | "cell_type": "code", 244 | "execution_count": 14, 245 | "metadata": {}, 246 | "outputs": [ 247 | { 248 | "data": { 249 | "text/plain": [ 250 | "35" 251 | ] 252 | }, 253 | "execution_count": 14, 254 | "metadata": {}, 255 | "output_type": "execute_result" 256 | } 257 | ], 258 | "source": [ 259 | "#Solution goes here\n", 260 | "matrix[1][1]" 261 | ] 262 | }, 263 | { 264 | "cell_type": "markdown", 265 | "metadata": {}, 266 | "source": [ 267 | "# Problem 8\n", 268 | "Given the array `integer_array`, print a NumPy array of Boolean values that indicate whether the corresponding values in `integer_array` are greater than 4." 269 | ] 270 | }, 271 | { 272 | "cell_type": "code", 273 | "execution_count": 15, 274 | "metadata": {}, 275 | "outputs": [], 276 | "source": [ 277 | "integer_array = np.array([2,6,4,9,8,5,3,1,2,5,4,8,7,5,6])" 278 | ] 279 | }, 280 | { 281 | "cell_type": "code", 282 | "execution_count": 16, 283 | "metadata": {}, 284 | "outputs": [ 285 | { 286 | "data": { 287 | "text/plain": [ 288 | "array([False, True, False, True, True, True, False, False, False,\n", 289 | " True, False, True, True, True, True])" 290 | ] 291 | }, 292 | "execution_count": 16, 293 | "metadata": {}, 294 | "output_type": "execute_result" 295 | } 296 | ], 297 | "source": [ 298 | "#Solution goes here\n", 299 | "integer_array > 4" 300 | ] 301 | }, 302 | { 303 | "cell_type": "markdown", 304 | "metadata": {}, 305 | "source": [ 306 | "# Problem \n", 307 | "Given the same array `integer_array`, print a new NumPy array that only includes the values from `integer_array` that are less then `6`." 308 | ] 309 | }, 310 | { 311 | "cell_type": "code", 312 | "execution_count": 17, 313 | "metadata": {}, 314 | "outputs": [ 315 | { 316 | "data": { 317 | "text/plain": [ 318 | "array([2, 4, 5, 3, 1, 2, 5, 4, 5])" 319 | ] 320 | }, 321 | "execution_count": 17, 322 | "metadata": {}, 323 | "output_type": "execute_result" 324 | } 325 | ], 326 | "source": [ 327 | "integer_array[integer_array < 6]" 328 | ] 329 | } 330 | ], 331 | "metadata": { 332 | "kernelspec": { 333 | "display_name": "Python 3", 334 | "language": "python", 335 | "name": "python3" 336 | }, 337 | "language_info": { 338 | "codemirror_mode": { 339 | "name": "ipython", 340 | "version": 3 341 | }, 342 | "file_extension": ".py", 343 | "mimetype": "text/x-python", 344 | "name": "python", 345 | "nbconvert_exporter": "python", 346 | "pygments_lexer": "ipython3", 347 | "version": "3.7.6" 348 | } 349 | }, 350 | "nbformat": 4, 351 | "nbformat_minor": 4 352 | } 353 | -------------------------------------------------------------------------------- /finished-files/04 - Pandas Series (Finished).ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Problem 1\n", 8 | "Import the NumPy library under the alias `np` and import the pandas library under the alias `pd`." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 1, 14 | "metadata": {}, 15 | "outputs": [], 16 | "source": [ 17 | "import numpy as np\n", 18 | "import pandas as pd" 19 | ] 20 | }, 21 | { 22 | "cell_type": "markdown", 23 | "metadata": {}, 24 | "source": [ 25 | "# Problem 2\n", 26 | "Turn the variable `this_list` into a pandas Series. Name the Series `this_series`." 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": 2, 32 | "metadata": {}, 33 | "outputs": [], 34 | "source": [ 35 | "this_list = ['a', 'b', 'c']" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": 3, 41 | "metadata": {}, 42 | "outputs": [], 43 | "source": [ 44 | "#Solution goes here\n", 45 | "this_series = pd.Series(this_list)" 46 | ] 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "metadata": {}, 51 | "source": [ 52 | "# Problem 3\n", 53 | "Given the variable `labels`, overwirte the `this_series` variable you just created with a new version of `this_series` that has `labels` as its index." 54 | ] 55 | }, 56 | { 57 | "cell_type": "code", 58 | "execution_count": 4, 59 | "metadata": {}, 60 | "outputs": [], 61 | "source": [ 62 | "labels = ['first', 'second', 'third']" 63 | ] 64 | }, 65 | { 66 | "cell_type": "code", 67 | "execution_count": 5, 68 | "metadata": {}, 69 | "outputs": [], 70 | "source": [ 71 | "#Solution goes here\n", 72 | "this_series = pd.Series(this_list, index=labels)" 73 | ] 74 | }, 75 | { 76 | "cell_type": "markdown", 77 | "metadata": {}, 78 | "source": [ 79 | "# Problem 4\n", 80 | "Given the dictionary `new_dict`, turn it into a pandas Seris named `new_series`." 81 | ] 82 | }, 83 | { 84 | "cell_type": "code", 85 | "execution_count": 6, 86 | "metadata": {}, 87 | "outputs": [], 88 | "source": [ 89 | "new_dict = {\"brand\": \"Ford\",\"model\": \"Mustang\",\"year\": 1964}" 90 | ] 91 | }, 92 | { 93 | "cell_type": "code", 94 | "execution_count": 7, 95 | "metadata": {}, 96 | "outputs": [], 97 | "source": [ 98 | "#Solution goes here\n", 99 | "new_series = pd.Series(new_dict)" 100 | ] 101 | } 102 | ], 103 | "metadata": { 104 | "kernelspec": { 105 | "display_name": "Python 3", 106 | "language": "python", 107 | "name": "python3" 108 | }, 109 | "language_info": { 110 | "codemirror_mode": { 111 | "name": "ipython", 112 | "version": 3 113 | }, 114 | "file_extension": ".py", 115 | "mimetype": "text/x-python", 116 | "name": "python", 117 | "nbconvert_exporter": "python", 118 | "pygments_lexer": "ipython3", 119 | "version": "3.7.6" 120 | } 121 | }, 122 | "nbformat": 4, 123 | "nbformat_minor": 4 124 | } 125 | -------------------------------------------------------------------------------- /finished-files/05 - Pandas DataFrames (Finished).ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Problem 1\n", 8 | "Import NumPy under the alias `np`." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 1, 14 | "metadata": {}, 15 | "outputs": [], 16 | "source": [ 17 | "import numpy as np" 18 | ] 19 | }, 20 | { 21 | "cell_type": "markdown", 22 | "metadata": {}, 23 | "source": [ 24 | "# Problem 2\n", 25 | "Import pandas under the alias `pd`." 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": 2, 31 | "metadata": {}, 32 | "outputs": [], 33 | "source": [ 34 | "import pandas as pd" 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "metadata": {}, 40 | "source": [ 41 | "# Problem 3\n", 42 | "Given the following NumPy array `data`, create a pandas DataFrame named `first_data_frame` that contains the same elements. Print the DataFrame to make sure the operation executed successfully." 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 8, 48 | "metadata": {}, 49 | "outputs": [], 50 | "source": [ 51 | "data = np.round(np.random.randn(5,5),1)" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": 9, 57 | "metadata": {}, 58 | "outputs": [], 59 | "source": [ 60 | "#Solution goes here\n", 61 | "first_data_frame = pd.DataFrame(data)\n", 62 | "first_data_frame" 63 | ] 64 | }, 65 | { 66 | "cell_type": "markdown", 67 | "metadata": {}, 68 | "source": [ 69 | "# Problem 4\n", 70 | "Assign the values of `row_labels` to the index of `first_data_frame`. Print the DataFrame to make sure the operation executed successfully.\n", 71 | "\n", 72 | "Hint: It will be easier to overwrite `first_data_frame` by using another `pd.DataFrame` method." 73 | ] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "execution_count": 10, 78 | "metadata": {}, 79 | "outputs": [], 80 | "source": [ 81 | "row_labels = ['one','two','three','four','five']" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": 14, 87 | "metadata": {}, 88 | "outputs": [ 89 | { 90 | "data": { 91 | "text/html": [ 92 | "
\n", 93 | "\n", 106 | "\n", 107 | " \n", 108 | " \n", 109 | " \n", 110 | " \n", 111 | " \n", 112 | " \n", 113 | " \n", 114 | " \n", 115 | " \n", 116 | " \n", 117 | " \n", 118 | " \n", 119 | " \n", 120 | " \n", 121 | " \n", 122 | " \n", 123 | " \n", 124 | " \n", 125 | " \n", 126 | " \n", 127 | " \n", 128 | " \n", 129 | " \n", 130 | " \n", 131 | " \n", 132 | " \n", 133 | " \n", 134 | " \n", 135 | " \n", 136 | " \n", 137 | " \n", 138 | " \n", 139 | " \n", 140 | " \n", 141 | " \n", 142 | " \n", 143 | " \n", 144 | " \n", 145 | " \n", 146 | " \n", 147 | " \n", 148 | " \n", 149 | " \n", 150 | " \n", 151 | " \n", 152 | " \n", 153 | " \n", 154 | " \n", 155 | " \n", 156 | " \n", 157 | " \n", 158 | " \n", 159 | "
01234
one-1.91.80.60.01.1
two2.3-2.1-0.3-1.8-0.6
three0.70.4-1.0-0.70.3
four0.80.5-0.70.00.2
five1.71.0-1.31.81.3
\n", 160 | "
" 161 | ], 162 | "text/plain": [ 163 | " 0 1 2 3 4\n", 164 | "one -1.9 1.8 0.6 0.0 1.1\n", 165 | "two 2.3 -2.1 -0.3 -1.8 -0.6\n", 166 | "three 0.7 0.4 -1.0 -0.7 0.3\n", 167 | "four 0.8 0.5 -0.7 0.0 0.2\n", 168 | "five 1.7 1.0 -1.3 1.8 1.3" 169 | ] 170 | }, 171 | "execution_count": 14, 172 | "metadata": {}, 173 | "output_type": "execute_result" 174 | } 175 | ], 176 | "source": [ 177 | "#Solution goes here\n", 178 | "first_data_frame = pd.DataFrame(data,row_labels)\n", 179 | "first_data_frame" 180 | ] 181 | }, 182 | { 183 | "cell_type": "markdown", 184 | "metadata": {}, 185 | "source": [ 186 | "# Problem 5\n", 187 | "Assign the values of `column_labels` to the columns of `first_data_frame`. Note that there are two main ways to do this - you are free to chose the method of your choice. Print the DataFrame to make sure the operation executed successfully." 188 | ] 189 | }, 190 | { 191 | "cell_type": "code", 192 | "execution_count": 16, 193 | "metadata": {}, 194 | "outputs": [], 195 | "source": [ 196 | "column_labels = ['alpha','beta','charlie','delta','echo']" 197 | ] 198 | }, 199 | { 200 | "cell_type": "code", 201 | "execution_count": 17, 202 | "metadata": {}, 203 | "outputs": [ 204 | { 205 | "data": { 206 | "text/html": [ 207 | "
\n", 208 | "\n", 221 | "\n", 222 | " \n", 223 | " \n", 224 | " \n", 225 | " \n", 226 | " \n", 227 | " \n", 228 | " \n", 229 | " \n", 230 | " \n", 231 | " \n", 232 | " \n", 233 | " \n", 234 | " \n", 235 | " \n", 236 | " \n", 237 | " \n", 238 | " \n", 239 | " \n", 240 | " \n", 241 | " \n", 242 | " \n", 243 | " \n", 244 | " \n", 245 | " \n", 246 | " \n", 247 | " \n", 248 | " \n", 249 | " \n", 250 | " \n", 251 | " \n", 252 | " \n", 253 | " \n", 254 | " \n", 255 | " \n", 256 | " \n", 257 | " \n", 258 | " \n", 259 | " \n", 260 | " \n", 261 | " \n", 262 | " \n", 263 | " \n", 264 | " \n", 265 | " \n", 266 | " \n", 267 | " \n", 268 | " \n", 269 | " \n", 270 | " \n", 271 | " \n", 272 | " \n", 273 | " \n", 274 | "
alphabetacharliedeltaecho
one-1.91.80.60.01.1
two2.3-2.1-0.3-1.8-0.6
three0.70.4-1.0-0.70.3
four0.80.5-0.70.00.2
five1.71.0-1.31.81.3
\n", 275 | "
" 276 | ], 277 | "text/plain": [ 278 | " alpha beta charlie delta echo\n", 279 | "one -1.9 1.8 0.6 0.0 1.1\n", 280 | "two 2.3 -2.1 -0.3 -1.8 -0.6\n", 281 | "three 0.7 0.4 -1.0 -0.7 0.3\n", 282 | "four 0.8 0.5 -0.7 0.0 0.2\n", 283 | "five 1.7 1.0 -1.3 1.8 1.3" 284 | ] 285 | }, 286 | "execution_count": 17, 287 | "metadata": {}, 288 | "output_type": "execute_result" 289 | } 290 | ], 291 | "source": [ 292 | "#Solution goes here\n", 293 | "first_data_frame.columns = column_labels\n", 294 | "first_data_frame" 295 | ] 296 | }, 297 | { 298 | "cell_type": "markdown", 299 | "metadata": {}, 300 | "source": [ 301 | "# Problem 6\n", 302 | "Create a pandas Series named `my_series` that contains the values from row `alpha` of `first_data_frame`. Print `my_series` to make sure the operation executed successfully." 303 | ] 304 | }, 305 | { 306 | "cell_type": "code", 307 | "execution_count": 18, 308 | "metadata": {}, 309 | "outputs": [ 310 | { 311 | "data": { 312 | "text/plain": [ 313 | "one -1.9\n", 314 | "two 2.3\n", 315 | "three 0.7\n", 316 | "four 0.8\n", 317 | "five 1.7\n", 318 | "Name: alpha, dtype: float64" 319 | ] 320 | }, 321 | "execution_count": 18, 322 | "metadata": {}, 323 | "output_type": "execute_result" 324 | } 325 | ], 326 | "source": [ 327 | "#Solution goes here\n", 328 | "my_series = first_data_frame['alpha']\n", 329 | "my_series" 330 | ] 331 | }, 332 | { 333 | "cell_type": "markdown", 334 | "metadata": {}, 335 | "source": [ 336 | "# Problem 7\n", 337 | "Create a new DataFrame called `second_data_frame` that is equal to `first_data_frame` but without row `one`. Print `second_data_frame` to make sure the operation executed successfully." 338 | ] 339 | }, 340 | { 341 | "cell_type": "code", 342 | "execution_count": 19, 343 | "metadata": {}, 344 | "outputs": [ 345 | { 346 | "data": { 347 | "text/html": [ 348 | "
\n", 349 | "\n", 362 | "\n", 363 | " \n", 364 | " \n", 365 | " \n", 366 | " \n", 367 | " \n", 368 | " \n", 369 | " \n", 370 | " \n", 371 | " \n", 372 | " \n", 373 | " \n", 374 | " \n", 375 | " \n", 376 | " \n", 377 | " \n", 378 | " \n", 379 | " \n", 380 | " \n", 381 | " \n", 382 | " \n", 383 | " \n", 384 | " \n", 385 | " \n", 386 | " \n", 387 | " \n", 388 | " \n", 389 | " \n", 390 | " \n", 391 | " \n", 392 | " \n", 393 | " \n", 394 | " \n", 395 | " \n", 396 | " \n", 397 | " \n", 398 | " \n", 399 | " \n", 400 | " \n", 401 | " \n", 402 | " \n", 403 | " \n", 404 | " \n", 405 | " \n", 406 | " \n", 407 | "
alphabetacharliedeltaecho
two2.3-2.1-0.3-1.8-0.6
three0.70.4-1.0-0.70.3
four0.80.5-0.70.00.2
five1.71.0-1.31.81.3
\n", 408 | "
" 409 | ], 410 | "text/plain": [ 411 | " alpha beta charlie delta echo\n", 412 | "two 2.3 -2.1 -0.3 -1.8 -0.6\n", 413 | "three 0.7 0.4 -1.0 -0.7 0.3\n", 414 | "four 0.8 0.5 -0.7 0.0 0.2\n", 415 | "five 1.7 1.0 -1.3 1.8 1.3" 416 | ] 417 | }, 418 | "execution_count": 19, 419 | "metadata": {}, 420 | "output_type": "execute_result" 421 | } 422 | ], 423 | "source": [ 424 | "#Solution goes here\n", 425 | "second_data_frame = first_data_frame.drop('one')\n", 426 | "second_data_frame" 427 | ] 428 | }, 429 | { 430 | "cell_type": "markdown", 431 | "metadata": {}, 432 | "source": [ 433 | "# Problem 8\n", 434 | "Create a new DataFrame called `third_data_frame` that is equal to `second_data_frame`, but without row `charlie`. Print `third_data_frame` to make sure the operation executed successfully." 435 | ] 436 | }, 437 | { 438 | "cell_type": "code", 439 | "execution_count": 21, 440 | "metadata": {}, 441 | "outputs": [ 442 | { 443 | "data": { 444 | "text/html": [ 445 | "
\n", 446 | "\n", 459 | "\n", 460 | " \n", 461 | " \n", 462 | " \n", 463 | " \n", 464 | " \n", 465 | " \n", 466 | " \n", 467 | " \n", 468 | " \n", 469 | " \n", 470 | " \n", 471 | " \n", 472 | " \n", 473 | " \n", 474 | " \n", 475 | " \n", 476 | " \n", 477 | " \n", 478 | " \n", 479 | " \n", 480 | " \n", 481 | " \n", 482 | " \n", 483 | " \n", 484 | " \n", 485 | " \n", 486 | " \n", 487 | " \n", 488 | " \n", 489 | " \n", 490 | " \n", 491 | " \n", 492 | " \n", 493 | " \n", 494 | " \n", 495 | " \n", 496 | " \n", 497 | " \n", 498 | " \n", 499 | "
alphabetadeltaecho
two2.3-2.1-1.8-0.6
three0.70.4-0.70.3
four0.80.50.00.2
five1.71.01.81.3
\n", 500 | "
" 501 | ], 502 | "text/plain": [ 503 | " alpha beta delta echo\n", 504 | "two 2.3 -2.1 -1.8 -0.6\n", 505 | "three 0.7 0.4 -0.7 0.3\n", 506 | "four 0.8 0.5 0.0 0.2\n", 507 | "five 1.7 1.0 1.8 1.3" 508 | ] 509 | }, 510 | "execution_count": 21, 511 | "metadata": {}, 512 | "output_type": "execute_result" 513 | } 514 | ], 515 | "source": [ 516 | "#Solution goes here\n", 517 | "third_data_frame = second_data_frame.drop('charlie', axis=1)\n", 518 | "third_data_frame" 519 | ] 520 | }, 521 | { 522 | "cell_type": "markdown", 523 | "metadata": {}, 524 | "source": [ 525 | "# Problem 9\n", 526 | "Create a variable called `row_two` that is equal to row `two` from `third_data_frame`. Print `row_two` to make sure the operation executed successfully." 527 | ] 528 | }, 529 | { 530 | "cell_type": "code", 531 | "execution_count": 22, 532 | "metadata": {}, 533 | "outputs": [ 534 | { 535 | "data": { 536 | "text/plain": [ 537 | "alpha 2.3\n", 538 | "beta -2.1\n", 539 | "delta -1.8\n", 540 | "echo -0.6\n", 541 | "Name: two, dtype: float64" 542 | ] 543 | }, 544 | "execution_count": 22, 545 | "metadata": {}, 546 | "output_type": "execute_result" 547 | } 548 | ], 549 | "source": [ 550 | "#Solution goes here\n", 551 | "row_two = third_data_frame.loc['two']\n", 552 | "row_two" 553 | ] 554 | }, 555 | { 556 | "cell_type": "markdown", 557 | "metadata": {}, 558 | "source": [ 559 | "# Problem 10\n", 560 | "Print the shape of new_data." 561 | ] 562 | }, 563 | { 564 | "cell_type": "code", 565 | "execution_count": 24, 566 | "metadata": {}, 567 | "outputs": [], 568 | "source": [ 569 | "new_data = np.round(np.random.randn(5,5),1)" 570 | ] 571 | }, 572 | { 573 | "cell_type": "code", 574 | "execution_count": 26, 575 | "metadata": {}, 576 | "outputs": [ 577 | { 578 | "data": { 579 | "text/plain": [ 580 | "(5, 5)" 581 | ] 582 | }, 583 | "execution_count": 26, 584 | "metadata": {}, 585 | "output_type": "execute_result" 586 | } 587 | ], 588 | "source": [ 589 | "#Solution goes here\n", 590 | "new_data.shape" 591 | ] 592 | }, 593 | { 594 | "cell_type": "markdown", 595 | "metadata": {}, 596 | "source": [ 597 | "# Problem 11\n", 598 | "Print a DataFrame that contains boolean values that indicate whether the elements of `new_data` are greater than 1." 599 | ] 600 | }, 601 | { 602 | "cell_type": "code", 603 | "execution_count": 29, 604 | "metadata": {}, 605 | "outputs": [ 606 | { 607 | "data": { 608 | "text/html": [ 609 | "
\n", 610 | "\n", 623 | "\n", 624 | " \n", 625 | " \n", 626 | " \n", 627 | " \n", 628 | " \n", 629 | " \n", 630 | " \n", 631 | " \n", 632 | " \n", 633 | " \n", 634 | " \n", 635 | " \n", 636 | " \n", 637 | " \n", 638 | " \n", 639 | " \n", 640 | " \n", 641 | " \n", 642 | " \n", 643 | " \n", 644 | " \n", 645 | " \n", 646 | " \n", 647 | " \n", 648 | " \n", 649 | " \n", 650 | " \n", 651 | " \n", 652 | " \n", 653 | " \n", 654 | " \n", 655 | " \n", 656 | " \n", 657 | " \n", 658 | " \n", 659 | " \n", 660 | " \n", 661 | " \n", 662 | " \n", 663 | " \n", 664 | " \n", 665 | " \n", 666 | " \n", 667 | " \n", 668 | " \n", 669 | " \n", 670 | " \n", 671 | " \n", 672 | " \n", 673 | " \n", 674 | " \n", 675 | " \n", 676 | "
01234
0TrueTrueTrueFalseFalse
1FalseFalseFalseFalseTrue
2FalseFalseFalseTrueFalse
3TrueFalseFalseFalseFalse
4FalseFalseFalseTrueFalse
\n", 677 | "
" 678 | ], 679 | "text/plain": [ 680 | " 0 1 2 3 4\n", 681 | "0 True True True False False\n", 682 | "1 False False False False True\n", 683 | "2 False False False True False\n", 684 | "3 True False False False False\n", 685 | "4 False False False True False" 686 | ] 687 | }, 688 | "execution_count": 29, 689 | "metadata": {}, 690 | "output_type": "execute_result" 691 | } 692 | ], 693 | "source": [ 694 | "pd.DataFrame(new_data > 1)" 695 | ] 696 | }, 697 | { 698 | "cell_type": "markdown", 699 | "metadata": {}, 700 | "source": [ 701 | "# Problem 12\n", 702 | "Print a NumPy array that contains only the elements of `new_data` that are greater than 1." 703 | ] 704 | }, 705 | { 706 | "cell_type": "code", 707 | "execution_count": 32, 708 | "metadata": {}, 709 | "outputs": [ 710 | { 711 | "data": { 712 | "text/plain": [ 713 | "array([2.3, 1.5, 1.6, 1.2, 2.2, 1.1, 1.7])" 714 | ] 715 | }, 716 | "execution_count": 32, 717 | "metadata": {}, 718 | "output_type": "execute_result" 719 | } 720 | ], 721 | "source": [ 722 | "new_data[new_data > 1]" 723 | ] 724 | }, 725 | { 726 | "cell_type": "code", 727 | "execution_count": null, 728 | "metadata": {}, 729 | "outputs": [], 730 | "source": [] 731 | }, 732 | { 733 | "cell_type": "code", 734 | "execution_count": null, 735 | "metadata": {}, 736 | "outputs": [], 737 | "source": [] 738 | }, 739 | { 740 | "cell_type": "code", 741 | "execution_count": null, 742 | "metadata": {}, 743 | "outputs": [], 744 | "source": [] 745 | } 746 | ], 747 | "metadata": { 748 | "kernelspec": { 749 | "display_name": "Python 3", 750 | "language": "python", 751 | "name": "python3" 752 | }, 753 | "language_info": { 754 | "codemirror_mode": { 755 | "name": "ipython", 756 | "version": 3 757 | }, 758 | "file_extension": ".py", 759 | "mimetype": "text/x-python", 760 | "name": "python", 761 | "nbconvert_exporter": "python", 762 | "pygments_lexer": "ipython3", 763 | "version": "3.7.6" 764 | } 765 | }, 766 | "nbformat": 4, 767 | "nbformat_minor": 4 768 | } 769 | -------------------------------------------------------------------------------- /finished-files/06 - How To Deal With Missing Data in Pandas (Finished).ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Problem 1\n", 8 | "Import NumPy under the alias `np`." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 1, 14 | "metadata": {}, 15 | "outputs": [], 16 | "source": [ 17 | "import numpy as np" 18 | ] 19 | }, 20 | { 21 | "cell_type": "markdown", 22 | "metadata": {}, 23 | "source": [ 24 | "# Problem 2\n", 25 | "Import pandas under the alias `pd`." 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": 2, 31 | "metadata": {}, 32 | "outputs": [], 33 | "source": [ 34 | "import pandas as pd" 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "metadata": {}, 40 | "source": [ 41 | "# Problem 3\n", 42 | "Given the DataFrame `data`, remove all of its rows that contain null values using the pandas method discussed in the lesson." 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 3, 48 | "metadata": {}, 49 | "outputs": [], 50 | "source": [ 51 | "data = pd.DataFrame(np.array([[np.nan, 8, 12],[np.nan, 16, np.nan],[4, 13, 45]]))" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": 4, 57 | "metadata": {}, 58 | "outputs": [ 59 | { 60 | "data": { 61 | "text/html": [ 62 | "
\n", 63 | "\n", 76 | "\n", 77 | " \n", 78 | " \n", 79 | " \n", 80 | " \n", 81 | " \n", 82 | " \n", 83 | " \n", 84 | " \n", 85 | " \n", 86 | " \n", 87 | " \n", 88 | " \n", 89 | " \n", 90 | " \n", 91 | " \n", 92 | " \n", 93 | "
012
24.013.045.0
\n", 94 | "
" 95 | ], 96 | "text/plain": [ 97 | " 0 1 2\n", 98 | "2 4.0 13.0 45.0" 99 | ] 100 | }, 101 | "execution_count": 4, 102 | "metadata": {}, 103 | "output_type": "execute_result" 104 | } 105 | ], 106 | "source": [ 107 | "#Solution goes here\n", 108 | "data.dropna()" 109 | ] 110 | }, 111 | { 112 | "cell_type": "markdown", 113 | "metadata": {}, 114 | "source": [ 115 | "# Problem 4\n", 116 | "Given the DataFrame `data`, remove all of its columns that contain null values using the pandas method discussed in the lesson." 117 | ] 118 | }, 119 | { 120 | "cell_type": "code", 121 | "execution_count": 5, 122 | "metadata": {}, 123 | "outputs": [ 124 | { 125 | "data": { 126 | "text/html": [ 127 | "
\n", 128 | "\n", 141 | "\n", 142 | " \n", 143 | " \n", 144 | " \n", 145 | " \n", 146 | " \n", 147 | " \n", 148 | " \n", 149 | " \n", 150 | " \n", 151 | " \n", 152 | " \n", 153 | " \n", 154 | " \n", 155 | " \n", 156 | " \n", 157 | " \n", 158 | " \n", 159 | " \n", 160 | " \n", 161 | " \n", 162 | "
1
08.0
116.0
213.0
\n", 163 | "
" 164 | ], 165 | "text/plain": [ 166 | " 1\n", 167 | "0 8.0\n", 168 | "1 16.0\n", 169 | "2 13.0" 170 | ] 171 | }, 172 | "execution_count": 5, 173 | "metadata": {}, 174 | "output_type": "execute_result" 175 | } 176 | ], 177 | "source": [ 178 | "#Solution goes here\n", 179 | "data.dropna(axis=1)" 180 | ] 181 | }, 182 | { 183 | "cell_type": "markdown", 184 | "metadata": {}, 185 | "source": [ 186 | "# Problem 5\n", 187 | "Given the DataFrame `data`, replace all of its null values with `💩` (copy and paste it)." 188 | ] 189 | }, 190 | { 191 | "cell_type": "code", 192 | "execution_count": 6, 193 | "metadata": {}, 194 | "outputs": [ 195 | { 196 | "data": { 197 | "text/html": [ 198 | "
\n", 199 | "\n", 212 | "\n", 213 | " \n", 214 | " \n", 215 | " \n", 216 | " \n", 217 | " \n", 218 | " \n", 219 | " \n", 220 | " \n", 221 | " \n", 222 | " \n", 223 | " \n", 224 | " \n", 225 | " \n", 226 | " \n", 227 | " \n", 228 | " \n", 229 | " \n", 230 | " \n", 231 | " \n", 232 | " \n", 233 | " \n", 234 | " \n", 235 | " \n", 236 | " \n", 237 | " \n", 238 | " \n", 239 | " \n", 240 | " \n", 241 | "
012
0💩8.012
1💩16.0💩
2413.045
\n", 242 | "
" 243 | ], 244 | "text/plain": [ 245 | " 0 1 2\n", 246 | "0 💩 8.0 12\n", 247 | "1 💩 16.0 💩\n", 248 | "2 4 13.0 45" 249 | ] 250 | }, 251 | "execution_count": 6, 252 | "metadata": {}, 253 | "output_type": "execute_result" 254 | } 255 | ], 256 | "source": [ 257 | "data.fillna('💩')" 258 | ] 259 | }, 260 | { 261 | "cell_type": "markdown", 262 | "metadata": {}, 263 | "source": [ 264 | "# Problem 6\n", 265 | "Given the DataFrame `data`, replace all of its null values with the mean value across the entire DataFrame." 266 | ] 267 | }, 268 | { 269 | "cell_type": "code", 270 | "execution_count": 7, 271 | "metadata": {}, 272 | "outputs": [ 273 | { 274 | "data": { 275 | "text/html": [ 276 | "
\n", 277 | "\n", 290 | "\n", 291 | " \n", 292 | " \n", 293 | " \n", 294 | " \n", 295 | " \n", 296 | " \n", 297 | " \n", 298 | " \n", 299 | " \n", 300 | " \n", 301 | " \n", 302 | " \n", 303 | " \n", 304 | " \n", 305 | " \n", 306 | " \n", 307 | " \n", 308 | " \n", 309 | " \n", 310 | " \n", 311 | " \n", 312 | " \n", 313 | " \n", 314 | " \n", 315 | " \n", 316 | " \n", 317 | " \n", 318 | " \n", 319 | "
012
04.08.012.0
14.016.028.5
24.013.045.0
\n", 320 | "
" 321 | ], 322 | "text/plain": [ 323 | " 0 1 2\n", 324 | "0 4.0 8.0 12.0\n", 325 | "1 4.0 16.0 28.5\n", 326 | "2 4.0 13.0 45.0" 327 | ] 328 | }, 329 | "execution_count": 7, 330 | "metadata": {}, 331 | "output_type": "execute_result" 332 | } 333 | ], 334 | "source": [ 335 | "data.fillna(data.mean())" 336 | ] 337 | } 338 | ], 339 | "metadata": { 340 | "kernelspec": { 341 | "display_name": "Python 3", 342 | "language": "python", 343 | "name": "python3" 344 | }, 345 | "language_info": { 346 | "codemirror_mode": { 347 | "name": "ipython", 348 | "version": 3 349 | }, 350 | "file_extension": ".py", 351 | "mimetype": "text/x-python", 352 | "name": "python", 353 | "nbconvert_exporter": "python", 354 | "pygments_lexer": "ipython3", 355 | "version": "3.7.6" 356 | } 357 | }, 358 | "nbformat": 4, 359 | "nbformat_minor": 4 360 | } 361 | -------------------------------------------------------------------------------- /finished-files/07 - Pandas Groupby Method (Finished).ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Problem 1\n", 8 | "Import NumPy under the alias `np`." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 1, 14 | "metadata": {}, 15 | "outputs": [], 16 | "source": [ 17 | "import numpy as np" 18 | ] 19 | }, 20 | { 21 | "cell_type": "markdown", 22 | "metadata": {}, 23 | "source": [ 24 | "# Problem 2\n", 25 | "Import pandas under the alias `pd`." 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": 2, 31 | "metadata": {}, 32 | "outputs": [], 33 | "source": [ 34 | "import pandas as pd" 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "metadata": {}, 40 | "source": [ 41 | "# Problem 3\n", 42 | "We will again be using salesperson data to test your knowledge of the `groupby` method. Given the dataset `data`, print a new DataFrame that shows the mean sales per salesperson, grouped by `Organization`." 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 3, 48 | "metadata": {}, 49 | "outputs": [ 50 | { 51 | "data": { 52 | "text/html": [ 53 | "
\n", 54 | "\n", 67 | "\n", 68 | " \n", 69 | " \n", 70 | " \n", 71 | " \n", 72 | " \n", 73 | " \n", 74 | " \n", 75 | " \n", 76 | " \n", 77 | " \n", 78 | " \n", 79 | " \n", 80 | " \n", 81 | " \n", 82 | " \n", 83 | " \n", 84 | " \n", 85 | " \n", 86 | " \n", 87 | " \n", 88 | " \n", 89 | " \n", 90 | " \n", 91 | " \n", 92 | " \n", 93 | " \n", 94 | " \n", 95 | " \n", 96 | " \n", 97 | " \n", 98 | " \n", 99 | " \n", 100 | " \n", 101 | " \n", 102 | " \n", 103 | " \n", 104 | " \n", 105 | " \n", 106 | " \n", 107 | " \n", 108 | " \n", 109 | " \n", 110 | " \n", 111 | " \n", 112 | " \n", 113 | " \n", 114 | "
OrganizationSalesperson NameSales
0Coca-ColaNick200
1Coca-ColaJoel120
2PepsiTaylor125
3PepsiJosiah250
4Dr. PepperJosh150
5Dr. PepperMicaiah500
\n", 115 | "
" 116 | ], 117 | "text/plain": [ 118 | " Organization Salesperson Name Sales\n", 119 | "0 Coca-Cola Nick 200\n", 120 | "1 Coca-Cola Joel 120\n", 121 | "2 Pepsi Taylor 125\n", 122 | "3 Pepsi Josiah 250\n", 123 | "4 Dr. Pepper Josh 150\n", 124 | "5 Dr. Pepper Micaiah 500" 125 | ] 126 | }, 127 | "execution_count": 3, 128 | "metadata": {}, 129 | "output_type": "execute_result" 130 | } 131 | ], 132 | "source": [ 133 | "data = pd.DataFrame([ ['Coca-Cola', 'Nick', 200],\n", 134 | "\n", 135 | " ['Coca-Cola', 'Joel', 120],\n", 136 | "\n", 137 | " ['Pepsi','Taylor', 125],\n", 138 | "\n", 139 | " ['Pepsi','Josiah', 250],\n", 140 | "\n", 141 | " ['Dr. Pepper','Josh', 150],\n", 142 | "\n", 143 | " ['Dr. Pepper','Micaiah', 500]], \n", 144 | " columns = ['Organization', 'Salesperson Name', 'Sales'])\n", 145 | "\n", 146 | "data" 147 | ] 148 | }, 149 | { 150 | "cell_type": "code", 151 | "execution_count": 4, 152 | "metadata": {}, 153 | "outputs": [ 154 | { 155 | "data": { 156 | "text/html": [ 157 | "
\n", 158 | "\n", 171 | "\n", 172 | " \n", 173 | " \n", 174 | " \n", 175 | " \n", 176 | " \n", 177 | " \n", 178 | " \n", 179 | " \n", 180 | " \n", 181 | " \n", 182 | " \n", 183 | " \n", 184 | " \n", 185 | " \n", 186 | " \n", 187 | " \n", 188 | " \n", 189 | " \n", 190 | " \n", 191 | " \n", 192 | " \n", 193 | " \n", 194 | " \n", 195 | " \n", 196 | "
Sales
Organization
Coca-Cola160.0
Dr. Pepper325.0
Pepsi187.5
\n", 197 | "
" 198 | ], 199 | "text/plain": [ 200 | " Sales\n", 201 | "Organization \n", 202 | "Coca-Cola 160.0\n", 203 | "Dr. Pepper 325.0\n", 204 | "Pepsi 187.5" 205 | ] 206 | }, 207 | "execution_count": 4, 208 | "metadata": {}, 209 | "output_type": "execute_result" 210 | } 211 | ], 212 | "source": [ 213 | "#Solution goes here\n", 214 | "data.groupby('Organization').mean()" 215 | ] 216 | }, 217 | { 218 | "cell_type": "markdown", 219 | "metadata": {}, 220 | "source": [ 221 | "# Problem 4\n", 222 | "Given the dataset `data`, print a new DataFrame that shows the total sales for each `Organization`." 223 | ] 224 | }, 225 | { 226 | "cell_type": "code", 227 | "execution_count": 5, 228 | "metadata": {}, 229 | "outputs": [ 230 | { 231 | "data": { 232 | "text/html": [ 233 | "
\n", 234 | "\n", 247 | "\n", 248 | " \n", 249 | " \n", 250 | " \n", 251 | " \n", 252 | " \n", 253 | " \n", 254 | " \n", 255 | " \n", 256 | " \n", 257 | " \n", 258 | " \n", 259 | " \n", 260 | " \n", 261 | " \n", 262 | " \n", 263 | " \n", 264 | " \n", 265 | " \n", 266 | " \n", 267 | " \n", 268 | " \n", 269 | " \n", 270 | " \n", 271 | " \n", 272 | "
Sales
Organization
Coca-Cola320
Dr. Pepper650
Pepsi375
\n", 273 | "
" 274 | ], 275 | "text/plain": [ 276 | " Sales\n", 277 | "Organization \n", 278 | "Coca-Cola 320\n", 279 | "Dr. Pepper 650\n", 280 | "Pepsi 375" 281 | ] 282 | }, 283 | "execution_count": 5, 284 | "metadata": {}, 285 | "output_type": "execute_result" 286 | } 287 | ], 288 | "source": [ 289 | "data.groupby('Organization').sum()" 290 | ] 291 | }, 292 | { 293 | "cell_type": "markdown", 294 | "metadata": {}, 295 | "source": [ 296 | "# Problem 5\n", 297 | "Given the dataset data, print a new DataFrame that applies the describe method to each organization." 298 | ] 299 | }, 300 | { 301 | "cell_type": "code", 302 | "execution_count": 6, 303 | "metadata": {}, 304 | "outputs": [ 305 | { 306 | "data": { 307 | "text/html": [ 308 | "
\n", 309 | "\n", 326 | "\n", 327 | " \n", 328 | " \n", 329 | " \n", 330 | " \n", 331 | " \n", 332 | " \n", 333 | " \n", 334 | " \n", 335 | " \n", 336 | " \n", 337 | " \n", 338 | " \n", 339 | " \n", 340 | " \n", 341 | " \n", 342 | " \n", 343 | " \n", 344 | " \n", 345 | " \n", 346 | " \n", 347 | " \n", 348 | " \n", 349 | " \n", 350 | " \n", 351 | " \n", 352 | " \n", 353 | " \n", 354 | " \n", 355 | " \n", 356 | " \n", 357 | " \n", 358 | " \n", 359 | " \n", 360 | " \n", 361 | " \n", 362 | " \n", 363 | " \n", 364 | " \n", 365 | " \n", 366 | " \n", 367 | " \n", 368 | " \n", 369 | " \n", 370 | " \n", 371 | " \n", 372 | " \n", 373 | " \n", 374 | " \n", 375 | " \n", 376 | " \n", 377 | " \n", 378 | " \n", 379 | " \n", 380 | " \n", 381 | " \n", 382 | " \n", 383 | " \n", 384 | " \n", 385 | " \n", 386 | " \n", 387 | " \n", 388 | " \n", 389 | " \n", 390 | "
Sales
countmeanstdmin25%50%75%max
Organization
Coca-Cola2.0160.056.568542120.0140.00160.0180.00200.0
Dr. Pepper2.0325.0247.487373150.0237.50325.0412.50500.0
Pepsi2.0187.588.388348125.0156.25187.5218.75250.0
\n", 391 | "
" 392 | ], 393 | "text/plain": [ 394 | " Sales \n", 395 | " count mean std min 25% 50% 75% max\n", 396 | "Organization \n", 397 | "Coca-Cola 2.0 160.0 56.568542 120.0 140.00 160.0 180.00 200.0\n", 398 | "Dr. Pepper 2.0 325.0 247.487373 150.0 237.50 325.0 412.50 500.0\n", 399 | "Pepsi 2.0 187.5 88.388348 125.0 156.25 187.5 218.75 250.0" 400 | ] 401 | }, 402 | "execution_count": 6, 403 | "metadata": {}, 404 | "output_type": "execute_result" 405 | } 406 | ], 407 | "source": [ 408 | "data.groupby('Organization').describe()" 409 | ] 410 | }, 411 | { 412 | "cell_type": "code", 413 | "execution_count": null, 414 | "metadata": {}, 415 | "outputs": [], 416 | "source": [] 417 | }, 418 | { 419 | "cell_type": "code", 420 | "execution_count": null, 421 | "metadata": {}, 422 | "outputs": [], 423 | "source": [] 424 | }, 425 | { 426 | "cell_type": "code", 427 | "execution_count": null, 428 | "metadata": {}, 429 | "outputs": [], 430 | "source": [] 431 | } 432 | ], 433 | "metadata": { 434 | "kernelspec": { 435 | "display_name": "Python 3", 436 | "language": "python", 437 | "name": "python3" 438 | }, 439 | "language_info": { 440 | "codemirror_mode": { 441 | "name": "ipython", 442 | "version": 3 443 | }, 444 | "file_extension": ".py", 445 | "mimetype": "text/x-python", 446 | "name": "python", 447 | "nbconvert_exporter": "python", 448 | "pygments_lexer": "ipython3", 449 | "version": "3.8.2" 450 | } 451 | }, 452 | "nbformat": 4, 453 | "nbformat_minor": 4 454 | } 455 | -------------------------------------------------------------------------------- /finished-files/08 - How To Concatenate DataFrames in Pandas (Finished).ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Problem 1\n", 8 | "Import NumPy under the alias `np`." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 1, 14 | "metadata": {}, 15 | "outputs": [], 16 | "source": [ 17 | "import numpy as np" 18 | ] 19 | }, 20 | { 21 | "cell_type": "markdown", 22 | "metadata": {}, 23 | "source": [ 24 | "# Problem 2\n", 25 | "Import pandas under the alias `pd`." 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": 2, 31 | "metadata": {}, 32 | "outputs": [], 33 | "source": [ 34 | "import pandas as pd" 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "metadata": {}, 40 | "source": [ 41 | "# Problem 3\n", 42 | "Given `df1` and `df2` below, concatenate the two DataFrames." 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 3, 48 | "metadata": {}, 49 | "outputs": [], 50 | "source": [ 51 | "df1 = pd.DataFrame({'A': ['A0', 'A1', 'A2', 'A3'],\n", 52 | " 'B': ['B0', 'B1', 'B2', 'B3'],\n", 53 | " 'C': ['C0', 'C1', 'C2', 'C3'],\n", 54 | " 'D': ['D0', 'D1', 'D2', 'D3']},\n", 55 | " index=[0, 1, 2, 3])\n", 56 | "\n", 57 | "\n", 58 | "df2 = pd.DataFrame({'A': ['A4', 'A5', 'A6', 'A7'],\n", 59 | " 'B': ['B4', 'B5', 'B6', 'B7'],\n", 60 | " 'C': ['C4', 'C5', 'C6', 'C7'],\n", 61 | " 'D': ['D4', 'D5', 'D6', 'D7']},\n", 62 | " index=[4, 5, 6, 7])" 63 | ] 64 | }, 65 | { 66 | "cell_type": "code", 67 | "execution_count": 4, 68 | "metadata": {}, 69 | "outputs": [ 70 | { 71 | "data": { 72 | "text/html": [ 73 | "
\n", 74 | "\n", 87 | "\n", 88 | " \n", 89 | " \n", 90 | " \n", 91 | " \n", 92 | " \n", 93 | " \n", 94 | " \n", 95 | " \n", 96 | " \n", 97 | " \n", 98 | " \n", 99 | " \n", 100 | " \n", 101 | " \n", 102 | " \n", 103 | " \n", 104 | " \n", 105 | " \n", 106 | " \n", 107 | " \n", 108 | " \n", 109 | " \n", 110 | " \n", 111 | " \n", 112 | " \n", 113 | " \n", 114 | " \n", 115 | " \n", 116 | " \n", 117 | " \n", 118 | " \n", 119 | " \n", 120 | " \n", 121 | " \n", 122 | " \n", 123 | " \n", 124 | " \n", 125 | " \n", 126 | " \n", 127 | " \n", 128 | " \n", 129 | " \n", 130 | " \n", 131 | " \n", 132 | " \n", 133 | " \n", 134 | " \n", 135 | " \n", 136 | " \n", 137 | " \n", 138 | " \n", 139 | " \n", 140 | " \n", 141 | " \n", 142 | " \n", 143 | " \n", 144 | " \n", 145 | " \n", 146 | " \n", 147 | " \n", 148 | " \n", 149 | " \n", 150 | " \n", 151 | " \n", 152 | " \n", 153 | " \n", 154 | " \n", 155 | "
ABCD
0A0B0C0D0
1A1B1C1D1
2A2B2C2D2
3A3B3C3D3
4A4B4C4D4
5A5B5C5D5
6A6B6C6D6
7A7B7C7D7
\n", 156 | "
" 157 | ], 158 | "text/plain": [ 159 | " A B C D\n", 160 | "0 A0 B0 C0 D0\n", 161 | "1 A1 B1 C1 D1\n", 162 | "2 A2 B2 C2 D2\n", 163 | "3 A3 B3 C3 D3\n", 164 | "4 A4 B4 C4 D4\n", 165 | "5 A5 B5 C5 D5\n", 166 | "6 A6 B6 C6 D6\n", 167 | "7 A7 B7 C7 D7" 168 | ] 169 | }, 170 | "execution_count": 4, 171 | "metadata": {}, 172 | "output_type": "execute_result" 173 | } 174 | ], 175 | "source": [ 176 | "#Solution goes here\n", 177 | "pd.concat([df1, df2])" 178 | ] 179 | }, 180 | { 181 | "cell_type": "markdown", 182 | "metadata": {}, 183 | "source": [ 184 | "# Problem 4\n", 185 | "Given `df1` and `df2` below, concatenate the two DataFrames along their columns (instead of along their rows)." 186 | ] 187 | }, 188 | { 189 | "cell_type": "code", 190 | "execution_count": 5, 191 | "metadata": {}, 192 | "outputs": [ 193 | { 194 | "data": { 195 | "text/html": [ 196 | "
\n", 197 | "\n", 210 | "\n", 211 | " \n", 212 | " \n", 213 | " \n", 214 | " \n", 215 | " \n", 216 | " \n", 217 | " \n", 218 | " \n", 219 | " \n", 220 | " \n", 221 | " \n", 222 | " \n", 223 | " \n", 224 | " \n", 225 | " \n", 226 | " \n", 227 | " \n", 228 | " \n", 229 | " \n", 230 | " \n", 231 | " \n", 232 | " \n", 233 | " \n", 234 | " \n", 235 | " \n", 236 | " \n", 237 | " \n", 238 | " \n", 239 | " \n", 240 | " \n", 241 | " \n", 242 | " \n", 243 | " \n", 244 | " \n", 245 | " \n", 246 | " \n", 247 | " \n", 248 | " \n", 249 | " \n", 250 | " \n", 251 | " \n", 252 | " \n", 253 | " \n", 254 | " \n", 255 | " \n", 256 | " \n", 257 | " \n", 258 | " \n", 259 | " \n", 260 | " \n", 261 | " \n", 262 | " \n", 263 | " \n", 264 | " \n", 265 | " \n", 266 | " \n", 267 | " \n", 268 | " \n", 269 | " \n", 270 | " \n", 271 | " \n", 272 | " \n", 273 | " \n", 274 | " \n", 275 | " \n", 276 | " \n", 277 | " \n", 278 | " \n", 279 | " \n", 280 | " \n", 281 | " \n", 282 | " \n", 283 | " \n", 284 | " \n", 285 | " \n", 286 | " \n", 287 | " \n", 288 | " \n", 289 | " \n", 290 | " \n", 291 | " \n", 292 | " \n", 293 | " \n", 294 | " \n", 295 | " \n", 296 | " \n", 297 | " \n", 298 | " \n", 299 | " \n", 300 | " \n", 301 | " \n", 302 | " \n", 303 | " \n", 304 | " \n", 305 | " \n", 306 | " \n", 307 | " \n", 308 | " \n", 309 | " \n", 310 | " \n", 311 | " \n", 312 | " \n", 313 | " \n", 314 | "
ABCDABCD
0A0B0C0D0NaNNaNNaNNaN
1A1B1C1D1NaNNaNNaNNaN
2A2B2C2D2NaNNaNNaNNaN
3A3B3C3D3NaNNaNNaNNaN
4NaNNaNNaNNaNA4B4C4D4
5NaNNaNNaNNaNA5B5C5D5
6NaNNaNNaNNaNA6B6C6D6
7NaNNaNNaNNaNA7B7C7D7
\n", 315 | "
" 316 | ], 317 | "text/plain": [ 318 | " A B C D A B C D\n", 319 | "0 A0 B0 C0 D0 NaN NaN NaN NaN\n", 320 | "1 A1 B1 C1 D1 NaN NaN NaN NaN\n", 321 | "2 A2 B2 C2 D2 NaN NaN NaN NaN\n", 322 | "3 A3 B3 C3 D3 NaN NaN NaN NaN\n", 323 | "4 NaN NaN NaN NaN A4 B4 C4 D4\n", 324 | "5 NaN NaN NaN NaN A5 B5 C5 D5\n", 325 | "6 NaN NaN NaN NaN A6 B6 C6 D6\n", 326 | "7 NaN NaN NaN NaN A7 B7 C7 D7" 327 | ] 328 | }, 329 | "execution_count": 5, 330 | "metadata": {}, 331 | "output_type": "execute_result" 332 | } 333 | ], 334 | "source": [ 335 | "#Solution goes here\n", 336 | "pd.concat([df1, df2], axis=1)" 337 | ] 338 | } 339 | ], 340 | "metadata": { 341 | "kernelspec": { 342 | "display_name": "Python 3", 343 | "language": "python", 344 | "name": "python3" 345 | }, 346 | "language_info": { 347 | "codemirror_mode": { 348 | "name": "ipython", 349 | "version": 3 350 | }, 351 | "file_extension": ".py", 352 | "mimetype": "text/x-python", 353 | "name": "python", 354 | "nbconvert_exporter": "python", 355 | "pygments_lexer": "ipython3", 356 | "version": "3.7.6" 357 | } 358 | }, 359 | "nbformat": 4, 360 | "nbformat_minor": 4 361 | } 362 | -------------------------------------------------------------------------------- /finished-files/09 - How To Merge DataFrames in Pandas (Finished).ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Problem 1\n", 8 | "Import NumPy under the alias `np`." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 1, 14 | "metadata": {}, 15 | "outputs": [], 16 | "source": [ 17 | "import numpy as np" 18 | ] 19 | }, 20 | { 21 | "cell_type": "markdown", 22 | "metadata": {}, 23 | "source": [ 24 | "# Problem 2\n", 25 | "Import pandas under the alias `pd`." 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": 2, 31 | "metadata": {}, 32 | "outputs": [], 33 | "source": [ 34 | "import pandas as pd" 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "metadata": {}, 40 | "source": [ 41 | "# Problem 3\n", 42 | "Using `df1` and `df2` as specified below, merge them using the key `key`. Specify `how = inner` as an argument." 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 3, 48 | "metadata": {}, 49 | "outputs": [], 50 | "source": [ 51 | "df1 = pd.DataFrame({'key': ['foo', 'bar', 'baz', 'foo'],\n", 52 | " 'value': [1, 2, 3, 5]})\n", 53 | "df2 = pd.DataFrame({'key': ['foo', 'bar', 'baz', 'foo'],\n", 54 | " 'value': [5, 6, 7, 8]})" 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": 4, 60 | "metadata": {}, 61 | "outputs": [ 62 | { 63 | "data": { 64 | "text/html": [ 65 | "
\n", 66 | "\n", 79 | "\n", 80 | " \n", 81 | " \n", 82 | " \n", 83 | " \n", 84 | " \n", 85 | " \n", 86 | " \n", 87 | " \n", 88 | " \n", 89 | " \n", 90 | " \n", 91 | " \n", 92 | " \n", 93 | " \n", 94 | " \n", 95 | " \n", 96 | " \n", 97 | " \n", 98 | " \n", 99 | " \n", 100 | " \n", 101 | " \n", 102 | " \n", 103 | " \n", 104 | " \n", 105 | " \n", 106 | " \n", 107 | " \n", 108 | " \n", 109 | " \n", 110 | " \n", 111 | " \n", 112 | " \n", 113 | " \n", 114 | " \n", 115 | " \n", 116 | " \n", 117 | " \n", 118 | " \n", 119 | " \n", 120 | " \n", 121 | " \n", 122 | " \n", 123 | " \n", 124 | " \n", 125 | " \n", 126 | "
keyvalue_xvalue_y
0foo15
1foo18
2foo55
3foo58
4bar26
5baz37
\n", 127 | "
" 128 | ], 129 | "text/plain": [ 130 | " key value_x value_y\n", 131 | "0 foo 1 5\n", 132 | "1 foo 1 8\n", 133 | "2 foo 5 5\n", 134 | "3 foo 5 8\n", 135 | "4 bar 2 6\n", 136 | "5 baz 3 7" 137 | ] 138 | }, 139 | "execution_count": 4, 140 | "metadata": {}, 141 | "output_type": "execute_result" 142 | } 143 | ], 144 | "source": [ 145 | "#Solution goes here\n", 146 | "pd.merge(df1, df2, on='key', how='inner')" 147 | ] 148 | } 149 | ], 150 | "metadata": { 151 | "kernelspec": { 152 | "display_name": "Python 3", 153 | "language": "python", 154 | "name": "python3" 155 | }, 156 | "language_info": { 157 | "codemirror_mode": { 158 | "name": "ipython", 159 | "version": 3 160 | }, 161 | "file_extension": ".py", 162 | "mimetype": "text/x-python", 163 | "name": "python", 164 | "nbconvert_exporter": "python", 165 | "pygments_lexer": "ipython3", 166 | "version": "3.7.6" 167 | } 168 | }, 169 | "nbformat": 4, 170 | "nbformat_minor": 4 171 | } 172 | -------------------------------------------------------------------------------- /finished-files/10 - How To Join DataFrames in Pandas (Finished).ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Problem 1\n", 8 | "Import NumPy under the alias `np`." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 1, 14 | "metadata": {}, 15 | "outputs": [], 16 | "source": [ 17 | "import numpy as np" 18 | ] 19 | }, 20 | { 21 | "cell_type": "markdown", 22 | "metadata": {}, 23 | "source": [ 24 | "# Problem 2\n", 25 | "Import pandas under the alias `pd`." 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": 2, 31 | "metadata": {}, 32 | "outputs": [], 33 | "source": [ 34 | "import pandas as pd" 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "metadata": {}, 40 | "source": [ 41 | "# Problem 3\n", 42 | "Given the DataFrames `df` and `other_df`, perform a join operation that joins `other_df` onto `df`." 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 3, 48 | "metadata": {}, 49 | "outputs": [], 50 | "source": [ 51 | "df = pd.DataFrame({'A': ['A0', 'A1', 'A2', 'A3', 'A4', 'A5']}, index = ['K0', 'K1', 'K2', 'K3', 'K4', 'K5'])" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": 4, 57 | "metadata": {}, 58 | "outputs": [], 59 | "source": [ 60 | "other_df = pd.DataFrame({'B': ['B0', 'B1', 'B2']}, index = ['K0', 'K1', 'K2'])" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": 5, 66 | "metadata": {}, 67 | "outputs": [ 68 | { 69 | "data": { 70 | "text/html": [ 71 | "
\n", 72 | "\n", 85 | "\n", 86 | " \n", 87 | " \n", 88 | " \n", 89 | " \n", 90 | " \n", 91 | " \n", 92 | " \n", 93 | " \n", 94 | " \n", 95 | " \n", 96 | " \n", 97 | " \n", 98 | " \n", 99 | " \n", 100 | " \n", 101 | " \n", 102 | " \n", 103 | " \n", 104 | " \n", 105 | " \n", 106 | " \n", 107 | " \n", 108 | " \n", 109 | " \n", 110 | " \n", 111 | " \n", 112 | " \n", 113 | " \n", 114 | " \n", 115 | " \n", 116 | " \n", 117 | " \n", 118 | " \n", 119 | " \n", 120 | " \n", 121 | " \n", 122 | " \n", 123 | " \n", 124 | " \n", 125 | "
AB
K0A0B0
K1A1B1
K2A2B2
K3A3NaN
K4A4NaN
K5A5NaN
\n", 126 | "
" 127 | ], 128 | "text/plain": [ 129 | " A B\n", 130 | "K0 A0 B0\n", 131 | "K1 A1 B1\n", 132 | "K2 A2 B2\n", 133 | "K3 A3 NaN\n", 134 | "K4 A4 NaN\n", 135 | "K5 A5 NaN" 136 | ] 137 | }, 138 | "execution_count": 5, 139 | "metadata": {}, 140 | "output_type": "execute_result" 141 | } 142 | ], 143 | "source": [ 144 | "#Solution goes here\n", 145 | "df.join(other_df)" 146 | ] 147 | } 148 | ], 149 | "metadata": { 150 | "kernelspec": { 151 | "display_name": "Python 3", 152 | "language": "python", 153 | "name": "python3" 154 | }, 155 | "language_info": { 156 | "codemirror_mode": { 157 | "name": "ipython", 158 | "version": 3 159 | }, 160 | "file_extension": ".py", 161 | "mimetype": "text/x-python", 162 | "name": "python", 163 | "nbconvert_exporter": "python", 164 | "pygments_lexer": "ipython3", 165 | "version": "3.7.6" 166 | } 167 | }, 168 | "nbformat": 4, 169 | "nbformat_minor": 4 170 | } 171 | -------------------------------------------------------------------------------- /finished-files/11 - Common Operations in Pandas (Finished).ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Problem 1\n", 8 | "Import NumPy under the alias `np`." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": null, 14 | "metadata": {}, 15 | "outputs": [], 16 | "source": [] 17 | }, 18 | { 19 | "cell_type": "markdown", 20 | "metadata": {}, 21 | "source": [ 22 | "# Problem 2\n", 23 | "Import pandas under the alias `pd`." 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": null, 29 | "metadata": {}, 30 | "outputs": [], 31 | "source": [] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "metadata": {}, 36 | "source": [ 37 | "# Problem 3\n", 38 | "Given the pandas Series `my_series`, generate a NumPy array that contains only the unique values from `my_series`. Assign this new array to a variable called `my_array`. Print `my_array` to ensure that the operation has been executed successfully." 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": null, 44 | "metadata": {}, 45 | "outputs": [], 46 | "source": [ 47 | "my_series = pd.Series([1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9])\n", 48 | "my_series" 49 | ] 50 | }, 51 | { 52 | "cell_type": "code", 53 | "execution_count": null, 54 | "metadata": {}, 55 | "outputs": [], 56 | "source": [ 57 | "#Solution goes here" 58 | ] 59 | }, 60 | { 61 | "cell_type": "markdown", 62 | "metadata": {}, 63 | "source": [ 64 | "# Problem 4\n", 65 | "Given the pandas DataFrame `my_data_frame`, generate a NumPy array that contains only the unique values from the second column. Assign this new array to a variable called `another_array`. Print `another_array` to ensure the operation has been executed successfully." 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "execution_count": null, 71 | "metadata": {}, 72 | "outputs": [], 73 | "source": [ 74 | "my_data_frame = pd.DataFrame(np.random.randn(3,5))\n", 75 | "my_data_frame" 76 | ] 77 | }, 78 | { 79 | "cell_type": "code", 80 | "execution_count": null, 81 | "metadata": {}, 82 | "outputs": [], 83 | "source": [ 84 | "#Solution goes here" 85 | ] 86 | }, 87 | { 88 | "cell_type": "markdown", 89 | "metadata": {}, 90 | "source": [ 91 | "# Problem 5\n", 92 | "Count the occurence of every element within the `my_series` variable that was created earlier in these practice problems." 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": null, 98 | "metadata": {}, 99 | "outputs": [], 100 | "source": [] 101 | }, 102 | { 103 | "cell_type": "markdown", 104 | "metadata": {}, 105 | "source": [ 106 | "# Problem 6\n", 107 | "Given the function `triple_digit`, apply this to every element within `my_series`." 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": null, 113 | "metadata": {}, 114 | "outputs": [], 115 | "source": [ 116 | "def triple_digit(x):\n", 117 | " return x + x*10 + x*100" 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": null, 123 | "metadata": {}, 124 | "outputs": [], 125 | "source": [ 126 | "#Solution goes here" 127 | ] 128 | }, 129 | { 130 | "cell_type": "markdown", 131 | "metadata": {}, 132 | "source": [ 133 | "# Problem 7\n", 134 | "Sort the `my_data_frame` variable that we created earlier based on the contents of its second column." 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": null, 140 | "metadata": {}, 141 | "outputs": [], 142 | "source": [] 143 | } 144 | ], 145 | "metadata": { 146 | "kernelspec": { 147 | "display_name": "Python 3", 148 | "language": "python", 149 | "name": "python3" 150 | }, 151 | "language_info": { 152 | "codemirror_mode": { 153 | "name": "ipython", 154 | "version": 3 155 | }, 156 | "file_extension": ".py", 157 | "mimetype": "text/x-python", 158 | "name": "python", 159 | "nbconvert_exporter": "python", 160 | "pygments_lexer": "ipython3", 161 | "version": "3.8.2" 162 | } 163 | }, 164 | "nbformat": 4, 165 | "nbformat_minor": 4 166 | } 167 | -------------------------------------------------------------------------------- /starter-files/01 - NumPy Arrays.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Problem 1\n", 8 | "Import the NumPy library under the alias `np`." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": null, 14 | "metadata": {}, 15 | "outputs": [], 16 | "source": [] 17 | }, 18 | { 19 | "cell_type": "markdown", 20 | "metadata": {}, 21 | "source": [ 22 | "# Problem 2\n", 23 | "Create a NumPy array called `my_array` that contains the following elements: `1`, `3`, and `5`." 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": null, 29 | "metadata": {}, 30 | "outputs": [], 31 | "source": [] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "metadata": {}, 36 | "source": [ 37 | "# Problem 3\n", 38 | "Create a two-dimensional NumPy array with 9 elements. The array should be called `my_matrix` and should have 3 columns and three rows. The matrix can contain whatever values you'd like. " 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": null, 44 | "metadata": {}, 45 | "outputs": [], 46 | "source": [] 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "metadata": {}, 51 | "source": [ 52 | "# Problem 4\n", 53 | "Use NumPy's `arange` method to generate the following output:\n", 54 | "\n", 55 | "`array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,\n", 56 | " 17, 18, 19, 20])`" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": null, 62 | "metadata": {}, 63 | "outputs": [], 64 | "source": [] 65 | }, 66 | { 67 | "cell_type": "markdown", 68 | "metadata": {}, 69 | "source": [ 70 | "# Problem 5\n", 71 | "Use NumPy's `arange` method to generate the following output:\n", 72 | "\n", 73 | "`array([ 1, 4, 7, 10, 13])`\n", 74 | "\n", 75 | "Hint: You will need to use `arange`'s third argument." 76 | ] 77 | }, 78 | { 79 | "cell_type": "code", 80 | "execution_count": null, 81 | "metadata": {}, 82 | "outputs": [], 83 | "source": [] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "metadata": {}, 88 | "source": [ 89 | "# Problem 6\n", 90 | "Generate a NumPy array that contains 20 zeros." 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": null, 96 | "metadata": {}, 97 | "outputs": [], 98 | "source": [] 99 | }, 100 | { 101 | "cell_type": "markdown", 102 | "metadata": {}, 103 | "source": [ 104 | "# Problem 7\n", 105 | "Generate a NumPy array that contains 50 ones." 106 | ] 107 | }, 108 | { 109 | "cell_type": "code", 110 | "execution_count": null, 111 | "metadata": {}, 112 | "outputs": [], 113 | "source": [] 114 | }, 115 | { 116 | "cell_type": "markdown", 117 | "metadata": {}, 118 | "source": [ 119 | "# Problem 8\n", 120 | "Using NumPy, divide the space between 0 and 100 into 1000 even intervals." 121 | ] 122 | }, 123 | { 124 | "cell_type": "code", 125 | "execution_count": null, 126 | "metadata": {}, 127 | "outputs": [], 128 | "source": [] 129 | }, 130 | { 131 | "cell_type": "markdown", 132 | "metadata": {}, 133 | "source": [ 134 | "# Problem 9\n", 135 | "Create a 10x10 identity matrix using NumPy." 136 | ] 137 | }, 138 | { 139 | "cell_type": "code", 140 | "execution_count": null, 141 | "metadata": {}, 142 | "outputs": [], 143 | "source": [] 144 | }, 145 | { 146 | "cell_type": "markdown", 147 | "metadata": {}, 148 | "source": [ 149 | "# Problem 10\n", 150 | "Returns a random sample of numbers with 10 values where each value is between 0 and 1." 151 | ] 152 | }, 153 | { 154 | "cell_type": "code", 155 | "execution_count": null, 156 | "metadata": {}, 157 | "outputs": [], 158 | "source": [] 159 | }, 160 | { 161 | "cell_type": "markdown", 162 | "metadata": {}, 163 | "source": [ 164 | "# Problem 11\n", 165 | "Returns a random sample of numbers with 10 values where each value is between 0 and 10.\n", 166 | "\n", 167 | "Hint: Use the `random.rand` method combined with a multiplication operation." 168 | ] 169 | }, 170 | { 171 | "cell_type": "code", 172 | "execution_count": null, 173 | "metadata": {}, 174 | "outputs": [], 175 | "source": [] 176 | }, 177 | { 178 | "cell_type": "markdown", 179 | "metadata": {}, 180 | "source": [ 181 | "# Problem 12\n", 182 | "Generate a random sample of 15 numbers from a normal distribution." 183 | ] 184 | }, 185 | { 186 | "cell_type": "code", 187 | "execution_count": null, 188 | "metadata": {}, 189 | "outputs": [], 190 | "source": [] 191 | }, 192 | { 193 | "cell_type": "markdown", 194 | "metadata": {}, 195 | "source": [ 196 | "# Problem 13\n", 197 | "Generate a random sample of 7 integers that range between 5 and 10." 198 | ] 199 | }, 200 | { 201 | "cell_type": "code", 202 | "execution_count": null, 203 | "metadata": {}, 204 | "outputs": [], 205 | "source": [] 206 | }, 207 | { 208 | "cell_type": "markdown", 209 | "metadata": {}, 210 | "source": [ 211 | "# Problem 14\n", 212 | "Reshape the following one-dimensional NumPy array into a two-dimensional Numpy array with 3 rows and 3 columns." 213 | ] 214 | }, 215 | { 216 | "cell_type": "code", 217 | "execution_count": null, 218 | "metadata": {}, 219 | "outputs": [], 220 | "source": [ 221 | "arr = np.array([0,1,2,3,4,5,6,7,8])" 222 | ] 223 | }, 224 | { 225 | "cell_type": "markdown", 226 | "metadata": {}, 227 | "source": [ 228 | "# Problem 15\n", 229 | "Print the minimum and maximum values of the following NumPy array." 230 | ] 231 | }, 232 | { 233 | "cell_type": "code", 234 | "execution_count": null, 235 | "metadata": {}, 236 | "outputs": [], 237 | "source": [ 238 | "arr = np.array([0,1,2,3,4,5,6,7,8])" 239 | ] 240 | }, 241 | { 242 | "cell_type": "code", 243 | "execution_count": null, 244 | "metadata": {}, 245 | "outputs": [], 246 | "source": [ 247 | "#Print the minimum value here." 248 | ] 249 | }, 250 | { 251 | "cell_type": "code", 252 | "execution_count": null, 253 | "metadata": {}, 254 | "outputs": [], 255 | "source": [ 256 | "#Print the maximum value here." 257 | ] 258 | }, 259 | { 260 | "cell_type": "markdown", 261 | "metadata": {}, 262 | "source": [ 263 | "# Problem 16\n", 264 | "For the following NumPy array, print the index of the minimum and maximum values." 265 | ] 266 | }, 267 | { 268 | "cell_type": "code", 269 | "execution_count": null, 270 | "metadata": {}, 271 | "outputs": [], 272 | "source": [ 273 | "my_array = np.array([6, 7, 0, 2])" 274 | ] 275 | }, 276 | { 277 | "cell_type": "code", 278 | "execution_count": null, 279 | "metadata": {}, 280 | "outputs": [], 281 | "source": [ 282 | "#Print the minimum value's index here." 283 | ] 284 | }, 285 | { 286 | "cell_type": "code", 287 | "execution_count": null, 288 | "metadata": {}, 289 | "outputs": [], 290 | "source": [ 291 | "#Print the maximum value's index here." 292 | ] 293 | } 294 | ], 295 | "metadata": { 296 | "kernelspec": { 297 | "display_name": "Python 3", 298 | "language": "python", 299 | "name": "python3" 300 | }, 301 | "language_info": { 302 | "codemirror_mode": { 303 | "name": "ipython", 304 | "version": 3 305 | }, 306 | "file_extension": ".py", 307 | "mimetype": "text/x-python", 308 | "name": "python", 309 | "nbconvert_exporter": "python", 310 | "pygments_lexer": "ipython3", 311 | "version": "3.7.6" 312 | } 313 | }, 314 | "nbformat": 4, 315 | "nbformat_minor": 4 316 | } 317 | -------------------------------------------------------------------------------- /starter-files/02 - NumPy Methods and Operations.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Problem 1\n", 8 | "Import the NumPy library under the alias `np`." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": null, 14 | "metadata": {}, 15 | "outputs": [], 16 | "source": [] 17 | }, 18 | { 19 | "cell_type": "markdown", 20 | "metadata": {}, 21 | "source": [ 22 | "# Problem 2\n", 23 | "Add `2` to every element of the following NumPy array." 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": null, 29 | "metadata": {}, 30 | "outputs": [], 31 | "source": [ 32 | "arr = np.array([2,3,4,9,7,5,8,2])" 33 | ] 34 | }, 35 | { 36 | "cell_type": "markdown", 37 | "metadata": {}, 38 | "source": [ 39 | "# Problem 3\n", 40 | "Double the value of every element in `arr` by adding it to itself." 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": null, 46 | "metadata": {}, 47 | "outputs": [], 48 | "source": [] 49 | }, 50 | { 51 | "cell_type": "markdown", 52 | "metadata": {}, 53 | "source": [ 54 | "# Problem 4\n", 55 | "Create an array of zeros by subtracting `arr` from itself." 56 | ] 57 | }, 58 | { 59 | "cell_type": "code", 60 | "execution_count": null, 61 | "metadata": {}, 62 | "outputs": [], 63 | "source": [] 64 | }, 65 | { 66 | "cell_type": "markdown", 67 | "metadata": {}, 68 | "source": [ 69 | "# Problem 5\n", 70 | "Multiply every element in `arr` by 6." 71 | ] 72 | }, 73 | { 74 | "cell_type": "code", 75 | "execution_count": null, 76 | "metadata": {}, 77 | "outputs": [], 78 | "source": [] 79 | }, 80 | { 81 | "cell_type": "markdown", 82 | "metadata": {}, 83 | "source": [ 84 | "# Problem 6\n", 85 | "Divide every element in `arr` by 4." 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": null, 91 | "metadata": {}, 92 | "outputs": [], 93 | "source": [] 94 | }, 95 | { 96 | "cell_type": "markdown", 97 | "metadata": {}, 98 | "source": [ 99 | "# Problem 7\n", 100 | "Create an array of ones by dividing every element in `arr` by itself." 101 | ] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "execution_count": null, 106 | "metadata": {}, 107 | "outputs": [], 108 | "source": [] 109 | }, 110 | { 111 | "cell_type": "markdown", 112 | "metadata": {}, 113 | "source": [ 114 | "# Problem 8\n", 115 | "Calculate the square root of every element in `arr`. Do not use the `**` operator." 116 | ] 117 | }, 118 | { 119 | "cell_type": "code", 120 | "execution_count": null, 121 | "metadata": {}, 122 | "outputs": [], 123 | "source": [] 124 | } 125 | ], 126 | "metadata": { 127 | "kernelspec": { 128 | "display_name": "Python 3", 129 | "language": "python", 130 | "name": "python3" 131 | }, 132 | "language_info": { 133 | "codemirror_mode": { 134 | "name": "ipython", 135 | "version": 3 136 | }, 137 | "file_extension": ".py", 138 | "mimetype": "text/x-python", 139 | "name": "python", 140 | "nbconvert_exporter": "python", 141 | "pygments_lexer": "ipython3", 142 | "version": "3.7.6" 143 | } 144 | }, 145 | "nbformat": 4, 146 | "nbformat_minor": 4 147 | } 148 | -------------------------------------------------------------------------------- /starter-files/03 - NumPy Indexing and Assignment.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Problem 1\n", 8 | "Import the NumPy library under the alias `np`." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": null, 14 | "metadata": {}, 15 | "outputs": [], 16 | "source": [] 17 | }, 18 | { 19 | "cell_type": "markdown", 20 | "metadata": {}, 21 | "source": [ 22 | "# Problem 2\n", 23 | "Given the following NumPy array, return the first element and the last element." 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": null, 29 | "metadata": {}, 30 | "outputs": [], 31 | "source": [ 32 | "arr = np.array([8,2,4,9,7,3,8,1])" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": null, 38 | "metadata": {}, 39 | "outputs": [], 40 | "source": [ 41 | "#Return the first element here" 42 | ] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "execution_count": null, 47 | "metadata": {}, 48 | "outputs": [], 49 | "source": [ 50 | "#Returns the last element here" 51 | ] 52 | }, 53 | { 54 | "cell_type": "markdown", 55 | "metadata": {}, 56 | "source": [ 57 | "# Problem 3\n", 58 | "Given the following NumPy array, return the entire array except for the last element." 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": null, 64 | "metadata": {}, 65 | "outputs": [], 66 | "source": [ 67 | "new_arr = np.array([1,6,4,8,7,5,2,1,4,5,6,1,4,5,6,2,1])" 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": null, 73 | "metadata": {}, 74 | "outputs": [], 75 | "source": [ 76 | "#Place your solution here" 77 | ] 78 | }, 79 | { 80 | "cell_type": "markdown", 81 | "metadata": {}, 82 | "source": [ 83 | "# Problem 4\n", 84 | "Change the second element of `this_arr` to `4`." 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": null, 90 | "metadata": {}, 91 | "outputs": [], 92 | "source": [ 93 | "this_arr = np.array([2,4,89,7,5,4,2,6,4,5,78,1,6,9,7,456,12,45])" 94 | ] 95 | }, 96 | { 97 | "cell_type": "code", 98 | "execution_count": null, 99 | "metadata": {}, 100 | "outputs": [], 101 | "source": [ 102 | "#Place your solution here\n", 103 | "this_arr[1] = 4" 104 | ] 105 | }, 106 | { 107 | "cell_type": "markdown", 108 | "metadata": {}, 109 | "source": [ 110 | "# Problem 5\n", 111 | "Given the array `original_array`, create a reference to that array called `reference_array`. Change the second element of `reference_array` to `16` and then print `original_array` to verify that it modified the original data structure." 112 | ] 113 | }, 114 | { 115 | "cell_type": "code", 116 | "execution_count": null, 117 | "metadata": {}, 118 | "outputs": [], 119 | "source": [ 120 | "original_array = np.array([12,45,86,79,45,26,13,46,28])" 121 | ] 122 | }, 123 | { 124 | "cell_type": "code", 125 | "execution_count": null, 126 | "metadata": {}, 127 | "outputs": [], 128 | "source": [ 129 | "#Solution goes here" 130 | ] 131 | }, 132 | { 133 | "cell_type": "markdown", 134 | "metadata": {}, 135 | "source": [ 136 | "# Problem 6\n", 137 | "Given the array `first_array`, create a copy of the array called `copy_array`. Change the third element of `copy_array` to `42` and then print `first_array` to verify that its elements remain unchanged." 138 | ] 139 | }, 140 | { 141 | "cell_type": "code", 142 | "execution_count": null, 143 | "metadata": {}, 144 | "outputs": [], 145 | "source": [ 146 | "first_array = np.array([16,45,75,16,43,45,78,19,23,46,79,58])" 147 | ] 148 | }, 149 | { 150 | "cell_type": "code", 151 | "execution_count": null, 152 | "metadata": {}, 153 | "outputs": [], 154 | "source": [ 155 | "#Solution goes here" 156 | ] 157 | }, 158 | { 159 | "cell_type": "markdown", 160 | "metadata": {}, 161 | "source": [ 162 | "# Problem 7\n", 163 | "Given the two-dimensional array `matrix`, print the value `35`." 164 | ] 165 | }, 166 | { 167 | "cell_type": "code", 168 | "execution_count": null, 169 | "metadata": {}, 170 | "outputs": [], 171 | "source": [ 172 | "matrix = np.array([[15, 120, 115],[230, 35, 130],[335, 420, 425]])" 173 | ] 174 | }, 175 | { 176 | "cell_type": "code", 177 | "execution_count": null, 178 | "metadata": {}, 179 | "outputs": [], 180 | "source": [ 181 | "#Solution goes here" 182 | ] 183 | }, 184 | { 185 | "cell_type": "markdown", 186 | "metadata": {}, 187 | "source": [ 188 | "# Problem 8\n", 189 | "Given the array `integer_array`, print a NumPy array of Boolean values that indicate whether the corresponding values in `integer_array` are greater than 4." 190 | ] 191 | }, 192 | { 193 | "cell_type": "code", 194 | "execution_count": null, 195 | "metadata": {}, 196 | "outputs": [], 197 | "source": [ 198 | "integer_array = np.array([2,6,4,9,8,5,3,1,2,5,4,8,7,5,6])" 199 | ] 200 | }, 201 | { 202 | "cell_type": "code", 203 | "execution_count": null, 204 | "metadata": {}, 205 | "outputs": [], 206 | "source": [ 207 | "#Solution goes here" 208 | ] 209 | }, 210 | { 211 | "cell_type": "markdown", 212 | "metadata": {}, 213 | "source": [ 214 | "# Problem \n", 215 | "Given the same array `integer_array`, print a new NumPy array that only includes the values from `integer_array` that are less then `6`." 216 | ] 217 | }, 218 | { 219 | "cell_type": "code", 220 | "execution_count": null, 221 | "metadata": {}, 222 | "outputs": [], 223 | "source": [] 224 | } 225 | ], 226 | "metadata": { 227 | "kernelspec": { 228 | "display_name": "Python 3", 229 | "language": "python", 230 | "name": "python3" 231 | }, 232 | "language_info": { 233 | "codemirror_mode": { 234 | "name": "ipython", 235 | "version": 3 236 | }, 237 | "file_extension": ".py", 238 | "mimetype": "text/x-python", 239 | "name": "python", 240 | "nbconvert_exporter": "python", 241 | "pygments_lexer": "ipython3", 242 | "version": "3.7.6" 243 | } 244 | }, 245 | "nbformat": 4, 246 | "nbformat_minor": 4 247 | } 248 | -------------------------------------------------------------------------------- /starter-files/04 - Pandas Series.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Problem 1\n", 8 | "Import the NumPy library under the alias `np` and import the pandas library under the alias `pd`." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 1, 14 | "metadata": {}, 15 | "outputs": [], 16 | "source": [] 17 | }, 18 | { 19 | "cell_type": "markdown", 20 | "metadata": {}, 21 | "source": [ 22 | "# Problem 2\n", 23 | "Turn the variable `this_list` into a pandas Series. Name the Series `this_series`." 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": 2, 29 | "metadata": {}, 30 | "outputs": [], 31 | "source": [ 32 | "this_list = ['a', 'b', 'c']" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": 3, 38 | "metadata": {}, 39 | "outputs": [], 40 | "source": [ 41 | "#Solution goes here" 42 | ] 43 | }, 44 | { 45 | "cell_type": "markdown", 46 | "metadata": {}, 47 | "source": [ 48 | "# Problem 3\n", 49 | "Given the variable `labels`, overwirte the `this_series` variable you just created with a new version of `this_series` that has `labels` as its index." 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": 4, 55 | "metadata": {}, 56 | "outputs": [], 57 | "source": [ 58 | "labels = ['first', 'second', 'third']" 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": 5, 64 | "metadata": {}, 65 | "outputs": [], 66 | "source": [ 67 | "#Solution goes here" 68 | ] 69 | }, 70 | { 71 | "cell_type": "markdown", 72 | "metadata": {}, 73 | "source": [ 74 | "# Problem 4\n", 75 | "Given the dictionary `new_dict`, turn it into a pandas Seris named `new_series`." 76 | ] 77 | }, 78 | { 79 | "cell_type": "code", 80 | "execution_count": 6, 81 | "metadata": {}, 82 | "outputs": [], 83 | "source": [ 84 | "new_dict = {\"brand\": \"Ford\",\"model\": \"Mustang\",\"year\": 1964}" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": 7, 90 | "metadata": {}, 91 | "outputs": [], 92 | "source": [ 93 | "#Solution goes here" 94 | ] 95 | } 96 | ], 97 | "metadata": { 98 | "kernelspec": { 99 | "display_name": "Python 3", 100 | "language": "python", 101 | "name": "python3" 102 | }, 103 | "language_info": { 104 | "codemirror_mode": { 105 | "name": "ipython", 106 | "version": 3 107 | }, 108 | "file_extension": ".py", 109 | "mimetype": "text/x-python", 110 | "name": "python", 111 | "nbconvert_exporter": "python", 112 | "pygments_lexer": "ipython3", 113 | "version": "3.7.6" 114 | } 115 | }, 116 | "nbformat": 4, 117 | "nbformat_minor": 4 118 | } 119 | -------------------------------------------------------------------------------- /starter-files/05 - Pandas DataFrames.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Problem 1\n", 8 | "Import NumPy under the alias `np`." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": null, 14 | "metadata": {}, 15 | "outputs": [], 16 | "source": [] 17 | }, 18 | { 19 | "cell_type": "markdown", 20 | "metadata": {}, 21 | "source": [ 22 | "# Problem 2\n", 23 | "Import pandas under the alias `pd`." 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": null, 29 | "metadata": {}, 30 | "outputs": [], 31 | "source": [] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "metadata": {}, 36 | "source": [ 37 | "# Problem 3\n", 38 | "Given the following NumPy array `data`, create a pandas DataFrame named `first_data_frame` that contains the same elements. Print the DataFrame to make sure the operation executed successfully." 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": null, 44 | "metadata": {}, 45 | "outputs": [], 46 | "source": [ 47 | "data = np.round(np.random.randn(5,5),1)" 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": null, 53 | "metadata": {}, 54 | "outputs": [], 55 | "source": [ 56 | "#Solution goes here" 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "metadata": {}, 62 | "source": [ 63 | "# Problem 4\n", 64 | "Assign the values of `row_labels` to the index of `first_data_frame`. Print the DataFrame to make sure the operation executed successfully.\n", 65 | "\n", 66 | "Hint: It will be easier to overwrite `first_data_frame` by using another `pd.DataFrame` method." 67 | ] 68 | }, 69 | { 70 | "cell_type": "code", 71 | "execution_count": null, 72 | "metadata": {}, 73 | "outputs": [], 74 | "source": [ 75 | "row_labels = ['one','two','three','four','five']" 76 | ] 77 | }, 78 | { 79 | "cell_type": "code", 80 | "execution_count": null, 81 | "metadata": {}, 82 | "outputs": [], 83 | "source": [ 84 | "#Solution goes here" 85 | ] 86 | }, 87 | { 88 | "cell_type": "markdown", 89 | "metadata": {}, 90 | "source": [ 91 | "# Problem 5\n", 92 | "Assign the values of `column_labels` to the columns of `first_data_frame`. Note that there are two main ways to do this - you are free to chose the method of your choice. Print the DataFrame to make sure the operation executed successfully." 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": null, 98 | "metadata": {}, 99 | "outputs": [], 100 | "source": [ 101 | "column_labels = ['alpha','beta','charlie','delta','echo']" 102 | ] 103 | }, 104 | { 105 | "cell_type": "code", 106 | "execution_count": null, 107 | "metadata": {}, 108 | "outputs": [], 109 | "source": [ 110 | "#Solution goes here" 111 | ] 112 | }, 113 | { 114 | "cell_type": "markdown", 115 | "metadata": {}, 116 | "source": [ 117 | "# Problem 6\n", 118 | "Create a pandas Series named `my_series` that contains the values from row `alpha` of `first_data_frame`. Print `my_series` to make sure the operation executed successfully." 119 | ] 120 | }, 121 | { 122 | "cell_type": "code", 123 | "execution_count": null, 124 | "metadata": {}, 125 | "outputs": [], 126 | "source": [ 127 | "#Solution goes here" 128 | ] 129 | }, 130 | { 131 | "cell_type": "markdown", 132 | "metadata": {}, 133 | "source": [ 134 | "# Problem 7\n", 135 | "Create a new DataFrame called `second_data_frame` that is equal to `first_data_frame` but without row `one`. Print `second_data_frame` to make sure the operation executed successfully." 136 | ] 137 | }, 138 | { 139 | "cell_type": "code", 140 | "execution_count": null, 141 | "metadata": {}, 142 | "outputs": [], 143 | "source": [ 144 | "#Solution goes here" 145 | ] 146 | }, 147 | { 148 | "cell_type": "markdown", 149 | "metadata": {}, 150 | "source": [ 151 | "# Problem 8\n", 152 | "Create a new DataFrame called `third_data_frame` that is equal to `second_data_frame`, but without row `charlie`. Print `third_data_frame` to make sure the operation executed successfully." 153 | ] 154 | }, 155 | { 156 | "cell_type": "code", 157 | "execution_count": null, 158 | "metadata": {}, 159 | "outputs": [], 160 | "source": [ 161 | "#Solution goes here" 162 | ] 163 | }, 164 | { 165 | "cell_type": "markdown", 166 | "metadata": {}, 167 | "source": [ 168 | "# Problem 9\n", 169 | "Create a variable called `row_two` that is equal to row `two` from `third_data_frame`. Print `row_two` to make sure the operation executed successfully." 170 | ] 171 | }, 172 | { 173 | "cell_type": "code", 174 | "execution_count": null, 175 | "metadata": {}, 176 | "outputs": [], 177 | "source": [ 178 | "#Solution goes here" 179 | ] 180 | }, 181 | { 182 | "cell_type": "markdown", 183 | "metadata": {}, 184 | "source": [ 185 | "# Problem 10\n", 186 | "Print the shape of new_data." 187 | ] 188 | }, 189 | { 190 | "cell_type": "code", 191 | "execution_count": null, 192 | "metadata": {}, 193 | "outputs": [], 194 | "source": [ 195 | "new_data = np.round(np.random.randn(5,5),1)" 196 | ] 197 | }, 198 | { 199 | "cell_type": "code", 200 | "execution_count": null, 201 | "metadata": {}, 202 | "outputs": [], 203 | "source": [ 204 | "#Solution goes here" 205 | ] 206 | }, 207 | { 208 | "cell_type": "markdown", 209 | "metadata": {}, 210 | "source": [ 211 | "# Problem 11\n", 212 | "Print a DataFrame that contains boolean values that indicate whether the elements of `new_data` are greater than 1." 213 | ] 214 | }, 215 | { 216 | "cell_type": "code", 217 | "execution_count": null, 218 | "metadata": {}, 219 | "outputs": [], 220 | "source": [ 221 | "#Solution goes here" 222 | ] 223 | }, 224 | { 225 | "cell_type": "markdown", 226 | "metadata": {}, 227 | "source": [ 228 | "# Problem 12\n", 229 | "Print a NumPy array that contains only the elements of `new_data` that are greater than 1." 230 | ] 231 | }, 232 | { 233 | "cell_type": "code", 234 | "execution_count": null, 235 | "metadata": {}, 236 | "outputs": [], 237 | "source": [ 238 | "#Solution goes here" 239 | ] 240 | } 241 | ], 242 | "metadata": { 243 | "kernelspec": { 244 | "display_name": "Python 3", 245 | "language": "python", 246 | "name": "python3" 247 | }, 248 | "language_info": { 249 | "codemirror_mode": { 250 | "name": "ipython", 251 | "version": 3 252 | }, 253 | "file_extension": ".py", 254 | "mimetype": "text/x-python", 255 | "name": "python", 256 | "nbconvert_exporter": "python", 257 | "pygments_lexer": "ipython3", 258 | "version": "3.7.6" 259 | } 260 | }, 261 | "nbformat": 4, 262 | "nbformat_minor": 4 263 | } 264 | -------------------------------------------------------------------------------- /starter-files/06 - How To Deal With Missing Data in Pandas.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Problem 1\n", 8 | "Import NumPy under the alias `np`." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": null, 14 | "metadata": {}, 15 | "outputs": [], 16 | "source": [] 17 | }, 18 | { 19 | "cell_type": "markdown", 20 | "metadata": {}, 21 | "source": [ 22 | "# Problem 2\n", 23 | "Import pandas under the alias `pd`." 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": null, 29 | "metadata": {}, 30 | "outputs": [], 31 | "source": [] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "metadata": {}, 36 | "source": [ 37 | "# Problem 3\n", 38 | "Given the DataFrame `data`, remove all of its rows that contain null values using the pandas method discussed in the lesson." 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": null, 44 | "metadata": {}, 45 | "outputs": [], 46 | "source": [ 47 | "data = pd.DataFrame(np.array([[np.nan, 8, 12],[np.nan, 16, np.nan],[4, 13, 45]]))" 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": null, 53 | "metadata": {}, 54 | "outputs": [], 55 | "source": [ 56 | "#Solution goes here" 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "metadata": {}, 62 | "source": [ 63 | "# Problem 4\n", 64 | "Given the DataFrame `data`, remove all of its columns that contain null values using the pandas method discussed in the lesson." 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": null, 70 | "metadata": {}, 71 | "outputs": [], 72 | "source": [ 73 | "#Solution goes here" 74 | ] 75 | }, 76 | { 77 | "cell_type": "markdown", 78 | "metadata": {}, 79 | "source": [ 80 | "# Problem 5\n", 81 | "Given the DataFrame `data`, replace all of its null values with `💩` (copy and paste it)." 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": null, 87 | "metadata": {}, 88 | "outputs": [], 89 | "source": [] 90 | }, 91 | { 92 | "cell_type": "markdown", 93 | "metadata": {}, 94 | "source": [ 95 | "# Problem 6\n", 96 | "Given the DataFrame `data`, replace all of its null values with the mean value across the entire DataFrame." 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "execution_count": null, 102 | "metadata": {}, 103 | "outputs": [], 104 | "source": [] 105 | } 106 | ], 107 | "metadata": { 108 | "kernelspec": { 109 | "display_name": "Python 3", 110 | "language": "python", 111 | "name": "python3" 112 | }, 113 | "language_info": { 114 | "codemirror_mode": { 115 | "name": "ipython", 116 | "version": 3 117 | }, 118 | "file_extension": ".py", 119 | "mimetype": "text/x-python", 120 | "name": "python", 121 | "nbconvert_exporter": "python", 122 | "pygments_lexer": "ipython3", 123 | "version": "3.7.6" 124 | } 125 | }, 126 | "nbformat": 4, 127 | "nbformat_minor": 4 128 | } 129 | -------------------------------------------------------------------------------- /starter-files/07 - Pandas Groupby Method.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Problem 1\n", 8 | "Import NumPy under the alias `np`." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": null, 14 | "metadata": {}, 15 | "outputs": [], 16 | "source": [] 17 | }, 18 | { 19 | "cell_type": "markdown", 20 | "metadata": {}, 21 | "source": [ 22 | "# Problem 2\n", 23 | "Import pandas under the alias `pd`." 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": null, 29 | "metadata": {}, 30 | "outputs": [], 31 | "source": [] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "metadata": {}, 36 | "source": [ 37 | "# Problem 3\n", 38 | "We will again be using salesperson data to test your knowledge of the `groupby` method. Given the dataset `data`, print a new DataFrame that shows the mean sales per salesperson, grouped by `Organization`." 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": null, 44 | "metadata": {}, 45 | "outputs": [], 46 | "source": [ 47 | "data = pd.DataFrame([ ['Coca-Cola', 'Nick', 200],\n", 48 | "\n", 49 | " ['Coca-Cola', 'Joel', 120],\n", 50 | "\n", 51 | " ['Pepsi','Taylor', 125],\n", 52 | "\n", 53 | " ['Pepsi','Josiah', 250],\n", 54 | "\n", 55 | " ['Dr. Pepper','Josh', 150],\n", 56 | "\n", 57 | " ['Dr. Pepper','Micaiah', 500]], \n", 58 | " columns = ['Organization', 'Salesperson Name', 'Sales'])\n", 59 | "\n", 60 | "data" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": null, 66 | "metadata": {}, 67 | "outputs": [], 68 | "source": [ 69 | "#Solution goes here" 70 | ] 71 | }, 72 | { 73 | "cell_type": "markdown", 74 | "metadata": {}, 75 | "source": [ 76 | "# Problem 4\n", 77 | "Given the dataset `data`, print a new DataFrame that shows the total sales for each `Organization`." 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": null, 83 | "metadata": {}, 84 | "outputs": [], 85 | "source": [] 86 | }, 87 | { 88 | "cell_type": "markdown", 89 | "metadata": {}, 90 | "source": [ 91 | "# Problem 5\n", 92 | "Given the dataset `data`, print a new DataFrame that applies the `describe` method to each organization." 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": null, 98 | "metadata": {}, 99 | "outputs": [], 100 | "source": [] 101 | } 102 | ], 103 | "metadata": { 104 | "kernelspec": { 105 | "display_name": "Python 3", 106 | "language": "python", 107 | "name": "python3" 108 | }, 109 | "language_info": { 110 | "codemirror_mode": { 111 | "name": "ipython", 112 | "version": 3 113 | }, 114 | "file_extension": ".py", 115 | "mimetype": "text/x-python", 116 | "name": "python", 117 | "nbconvert_exporter": "python", 118 | "pygments_lexer": "ipython3", 119 | "version": "3.7.6" 120 | } 121 | }, 122 | "nbformat": 4, 123 | "nbformat_minor": 4 124 | } 125 | -------------------------------------------------------------------------------- /starter-files/08 - How To Concatenate DataFrames in Pandas.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Problem 1\n", 8 | "Import NumPy under the alias `np`." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": null, 14 | "metadata": {}, 15 | "outputs": [], 16 | "source": [] 17 | }, 18 | { 19 | "cell_type": "markdown", 20 | "metadata": {}, 21 | "source": [ 22 | "# Problem 2\n", 23 | "Import pandas under the alias `pd`." 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": null, 29 | "metadata": {}, 30 | "outputs": [], 31 | "source": [] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "metadata": {}, 36 | "source": [ 37 | "# Problem 3\n", 38 | "Given `df1` and `df2` below, concatenate the two DataFrames." 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": null, 44 | "metadata": {}, 45 | "outputs": [], 46 | "source": [ 47 | "df1 = pd.DataFrame({'A': ['A0', 'A1', 'A2', 'A3'],\n", 48 | " 'B': ['B0', 'B1', 'B2', 'B3'],\n", 49 | " 'C': ['C0', 'C1', 'C2', 'C3'],\n", 50 | " 'D': ['D0', 'D1', 'D2', 'D3']},\n", 51 | " index=[0, 1, 2, 3])\n", 52 | "\n", 53 | "\n", 54 | "df2 = pd.DataFrame({'A': ['A4', 'A5', 'A6', 'A7'],\n", 55 | " 'B': ['B4', 'B5', 'B6', 'B7'],\n", 56 | " 'C': ['C4', 'C5', 'C6', 'C7'],\n", 57 | " 'D': ['D4', 'D5', 'D6', 'D7']},\n", 58 | " index=[4, 5, 6, 7])" 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": null, 64 | "metadata": {}, 65 | "outputs": [], 66 | "source": [ 67 | "#Solution goes here" 68 | ] 69 | }, 70 | { 71 | "cell_type": "markdown", 72 | "metadata": {}, 73 | "source": [ 74 | "# Problem 4\n", 75 | "Given `df1` and `df2` below, concatenate the two DataFrames along their columns (instead of along their rows)." 76 | ] 77 | }, 78 | { 79 | "cell_type": "code", 80 | "execution_count": null, 81 | "metadata": {}, 82 | "outputs": [], 83 | "source": [ 84 | "#Solution goes here" 85 | ] 86 | } 87 | ], 88 | "metadata": { 89 | "kernelspec": { 90 | "display_name": "Python 3", 91 | "language": "python", 92 | "name": "python3" 93 | }, 94 | "language_info": { 95 | "codemirror_mode": { 96 | "name": "ipython", 97 | "version": 3 98 | }, 99 | "file_extension": ".py", 100 | "mimetype": "text/x-python", 101 | "name": "python", 102 | "nbconvert_exporter": "python", 103 | "pygments_lexer": "ipython3", 104 | "version": "3.7.6" 105 | } 106 | }, 107 | "nbformat": 4, 108 | "nbformat_minor": 4 109 | } 110 | -------------------------------------------------------------------------------- /starter-files/09 - How To Merge DataFrames in Pandas.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Problem 1\n", 8 | "Import NumPy under the alias `np`." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": null, 14 | "metadata": {}, 15 | "outputs": [], 16 | "source": [] 17 | }, 18 | { 19 | "cell_type": "markdown", 20 | "metadata": {}, 21 | "source": [ 22 | "# Problem 2\n", 23 | "Import pandas under the alias `pd`." 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": null, 29 | "metadata": {}, 30 | "outputs": [], 31 | "source": [] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "metadata": {}, 36 | "source": [ 37 | "# Problem 3\n", 38 | "Using `df1` and `df2` as specified below, merge them using the key `key`. Specify `how = inner` as an argument." 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": null, 44 | "metadata": {}, 45 | "outputs": [], 46 | "source": [ 47 | "df1 = pd.DataFrame({'key': ['foo', 'bar', 'baz', 'foo'],\n", 48 | " 'value': [1, 2, 3, 5]})\n", 49 | "df2 = pd.DataFrame({'key': ['foo', 'bar', 'baz', 'foo'],\n", 50 | " 'value': [5, 6, 7, 8]})" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": null, 56 | "metadata": {}, 57 | "outputs": [], 58 | "source": [ 59 | "#Solution goes here" 60 | ] 61 | } 62 | ], 63 | "metadata": { 64 | "kernelspec": { 65 | "display_name": "Python 3", 66 | "language": "python", 67 | "name": "python3" 68 | }, 69 | "language_info": { 70 | "codemirror_mode": { 71 | "name": "ipython", 72 | "version": 3 73 | }, 74 | "file_extension": ".py", 75 | "mimetype": "text/x-python", 76 | "name": "python", 77 | "nbconvert_exporter": "python", 78 | "pygments_lexer": "ipython3", 79 | "version": "3.7.6" 80 | } 81 | }, 82 | "nbformat": 4, 83 | "nbformat_minor": 4 84 | } 85 | -------------------------------------------------------------------------------- /starter-files/10 - How To Join DataFrames in Pandas.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Problem 1\n", 8 | "Import NumPy under the alias `np`." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": null, 14 | "metadata": {}, 15 | "outputs": [], 16 | "source": [] 17 | }, 18 | { 19 | "cell_type": "markdown", 20 | "metadata": {}, 21 | "source": [ 22 | "# Problem 2\n", 23 | "Import pandas under the alias `pd`." 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": null, 29 | "metadata": {}, 30 | "outputs": [], 31 | "source": [] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "metadata": {}, 36 | "source": [ 37 | "# Problem 3\n", 38 | "Given the DataFrames `df` and `other_df`, perform a join operation that joins `other_df` onto `df`." 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": null, 44 | "metadata": {}, 45 | "outputs": [], 46 | "source": [ 47 | "df = pd.DataFrame({'A': ['A0', 'A1', 'A2', 'A3', 'A4', 'A5']}, index = ['K0', 'K1', 'K2', 'K3', 'K4', 'K5'])" 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": null, 53 | "metadata": {}, 54 | "outputs": [], 55 | "source": [ 56 | "other_df = pd.DataFrame({'B': ['B0', 'B1', 'B2']}, index = ['K0', 'K1', 'K2'])" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": null, 62 | "metadata": {}, 63 | "outputs": [], 64 | "source": [ 65 | "#Solution goes here" 66 | ] 67 | } 68 | ], 69 | "metadata": { 70 | "kernelspec": { 71 | "display_name": "Python 3", 72 | "language": "python", 73 | "name": "python3" 74 | }, 75 | "language_info": { 76 | "codemirror_mode": { 77 | "name": "ipython", 78 | "version": 3 79 | }, 80 | "file_extension": ".py", 81 | "mimetype": "text/x-python", 82 | "name": "python", 83 | "nbconvert_exporter": "python", 84 | "pygments_lexer": "ipython3", 85 | "version": "3.7.6" 86 | } 87 | }, 88 | "nbformat": 4, 89 | "nbformat_minor": 4 90 | } 91 | -------------------------------------------------------------------------------- /starter-files/11 - Common Operations in Pandas.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Problem 1\n", 8 | "Import NumPy under the alias `np`." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 1, 14 | "metadata": {}, 15 | "outputs": [], 16 | "source": [ 17 | "import numpy as np" 18 | ] 19 | }, 20 | { 21 | "cell_type": "markdown", 22 | "metadata": {}, 23 | "source": [ 24 | "# Problem 2\n", 25 | "Import pandas under the alias `pd`." 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": 2, 31 | "metadata": {}, 32 | "outputs": [], 33 | "source": [ 34 | "import pandas as pd" 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "metadata": {}, 40 | "source": [ 41 | "# Problem 3\n", 42 | "Given the pandas Series `my_series`, generate a NumPy array that contains only the unique values from `my_series`. Assign this new array to a variable called `my_array`. Print `my_array` to ensure that the operation has been executed successfully." 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 3, 48 | "metadata": {}, 49 | "outputs": [ 50 | { 51 | "data": { 52 | "text/plain": [ 53 | "0 1\n", 54 | "1 1\n", 55 | "2 2\n", 56 | "3 2\n", 57 | "4 3\n", 58 | "5 3\n", 59 | "6 4\n", 60 | "7 4\n", 61 | "8 5\n", 62 | "9 5\n", 63 | "10 6\n", 64 | "11 6\n", 65 | "12 7\n", 66 | "13 7\n", 67 | "14 8\n", 68 | "15 8\n", 69 | "16 9\n", 70 | "17 9\n", 71 | "dtype: int64" 72 | ] 73 | }, 74 | "execution_count": 3, 75 | "metadata": {}, 76 | "output_type": "execute_result" 77 | } 78 | ], 79 | "source": [ 80 | "my_series = pd.Series([1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9])\n", 81 | "my_series" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": 4, 87 | "metadata": {}, 88 | "outputs": [ 89 | { 90 | "data": { 91 | "text/plain": [ 92 | "array([1, 2, 3, 4, 5, 6, 7, 8, 9])" 93 | ] 94 | }, 95 | "execution_count": 4, 96 | "metadata": {}, 97 | "output_type": "execute_result" 98 | } 99 | ], 100 | "source": [ 101 | "#Solution goes here\n", 102 | "my_array = my_series.unique()\n", 103 | "my_array" 104 | ] 105 | }, 106 | { 107 | "cell_type": "markdown", 108 | "metadata": {}, 109 | "source": [ 110 | "# Problem 4\n", 111 | "Given the pandas DataFrame `my_data_frame`, generate a NumPy array that contains only the unique values from the second column. Assign this new array to a variable called `another_array`. Print `another_array` to ensure the operation has been executed successfully." 112 | ] 113 | }, 114 | { 115 | "cell_type": "code", 116 | "execution_count": 5, 117 | "metadata": {}, 118 | "outputs": [ 119 | { 120 | "data": { 121 | "text/html": [ 122 | "
\n", 123 | "\n", 136 | "\n", 137 | " \n", 138 | " \n", 139 | " \n", 140 | " \n", 141 | " \n", 142 | " \n", 143 | " \n", 144 | " \n", 145 | " \n", 146 | " \n", 147 | " \n", 148 | " \n", 149 | " \n", 150 | " \n", 151 | " \n", 152 | " \n", 153 | " \n", 154 | " \n", 155 | " \n", 156 | " \n", 157 | " \n", 158 | " \n", 159 | " \n", 160 | " \n", 161 | " \n", 162 | " \n", 163 | " \n", 164 | " \n", 165 | " \n", 166 | " \n", 167 | " \n", 168 | " \n", 169 | " \n", 170 | " \n", 171 | " \n", 172 | " \n", 173 | "
01234
00.9501201.104541-0.135333-2.157449-1.786119
1-1.7721710.207613-1.4803140.191361-2.296765
2-0.576407-0.6151811.2331000.092227-1.881353
\n", 174 | "
" 175 | ], 176 | "text/plain": [ 177 | " 0 1 2 3 4\n", 178 | "0 0.950120 1.104541 -0.135333 -2.157449 -1.786119\n", 179 | "1 -1.772171 0.207613 -1.480314 0.191361 -2.296765\n", 180 | "2 -0.576407 -0.615181 1.233100 0.092227 -1.881353" 181 | ] 182 | }, 183 | "execution_count": 5, 184 | "metadata": {}, 185 | "output_type": "execute_result" 186 | } 187 | ], 188 | "source": [ 189 | "my_data_frame = pd.DataFrame(np.random.randn(3,5))\n", 190 | "my_data_frame" 191 | ] 192 | }, 193 | { 194 | "cell_type": "code", 195 | "execution_count": 6, 196 | "metadata": {}, 197 | "outputs": [ 198 | { 199 | "data": { 200 | "text/plain": [ 201 | "array([ 0.95011976, -1.7721715 , -0.57640705])" 202 | ] 203 | }, 204 | "execution_count": 6, 205 | "metadata": {}, 206 | "output_type": "execute_result" 207 | } 208 | ], 209 | "source": [ 210 | "#Solution goes here\n", 211 | "another_array = my_data_frame[0].unique()\n", 212 | "another_array" 213 | ] 214 | }, 215 | { 216 | "cell_type": "markdown", 217 | "metadata": {}, 218 | "source": [ 219 | "# Problem 5\n", 220 | "Count the occurence of every element within the `my_series` variable that was created earlier in these practice problems." 221 | ] 222 | }, 223 | { 224 | "cell_type": "code", 225 | "execution_count": 7, 226 | "metadata": {}, 227 | "outputs": [ 228 | { 229 | "data": { 230 | "text/plain": [ 231 | "9 2\n", 232 | "8 2\n", 233 | "7 2\n", 234 | "6 2\n", 235 | "5 2\n", 236 | "4 2\n", 237 | "3 2\n", 238 | "2 2\n", 239 | "1 2\n", 240 | "dtype: int64" 241 | ] 242 | }, 243 | "execution_count": 7, 244 | "metadata": {}, 245 | "output_type": "execute_result" 246 | } 247 | ], 248 | "source": [ 249 | "my_series.value_counts()" 250 | ] 251 | }, 252 | { 253 | "cell_type": "markdown", 254 | "metadata": {}, 255 | "source": [ 256 | "# Problem 6\n", 257 | "Given the function `triple_digit`, apply this to every element within `my_series`." 258 | ] 259 | }, 260 | { 261 | "cell_type": "code", 262 | "execution_count": 8, 263 | "metadata": {}, 264 | "outputs": [], 265 | "source": [ 266 | "def triple_digit(x):\n", 267 | " return x + x*10 + x*100" 268 | ] 269 | }, 270 | { 271 | "cell_type": "code", 272 | "execution_count": 9, 273 | "metadata": {}, 274 | "outputs": [ 275 | { 276 | "data": { 277 | "text/plain": [ 278 | "0 111\n", 279 | "1 111\n", 280 | "2 222\n", 281 | "3 222\n", 282 | "4 333\n", 283 | "5 333\n", 284 | "6 444\n", 285 | "7 444\n", 286 | "8 555\n", 287 | "9 555\n", 288 | "10 666\n", 289 | "11 666\n", 290 | "12 777\n", 291 | "13 777\n", 292 | "14 888\n", 293 | "15 888\n", 294 | "16 999\n", 295 | "17 999\n", 296 | "dtype: int64" 297 | ] 298 | }, 299 | "execution_count": 9, 300 | "metadata": {}, 301 | "output_type": "execute_result" 302 | } 303 | ], 304 | "source": [ 305 | "#Solution goes here\n", 306 | "my_series.apply(triple_digit)" 307 | ] 308 | }, 309 | { 310 | "cell_type": "markdown", 311 | "metadata": {}, 312 | "source": [ 313 | "# Problem 7\n", 314 | "Sort the `my_data_frame` variable that we created earlier based on the contents of its second column." 315 | ] 316 | }, 317 | { 318 | "cell_type": "code", 319 | "execution_count": 10, 320 | "metadata": {}, 321 | "outputs": [ 322 | { 323 | "data": { 324 | "text/html": [ 325 | "
\n", 326 | "\n", 339 | "\n", 340 | " \n", 341 | " \n", 342 | " \n", 343 | " \n", 344 | " \n", 345 | " \n", 346 | " \n", 347 | " \n", 348 | " \n", 349 | " \n", 350 | " \n", 351 | " \n", 352 | " \n", 353 | " \n", 354 | " \n", 355 | " \n", 356 | " \n", 357 | " \n", 358 | " \n", 359 | " \n", 360 | " \n", 361 | " \n", 362 | " \n", 363 | " \n", 364 | " \n", 365 | " \n", 366 | " \n", 367 | " \n", 368 | " \n", 369 | " \n", 370 | " \n", 371 | " \n", 372 | " \n", 373 | " \n", 374 | " \n", 375 | " \n", 376 | "
01234
1-1.7721710.207613-1.4803140.191361-2.296765
2-0.576407-0.6151811.2331000.092227-1.881353
00.9501201.104541-0.135333-2.157449-1.786119
\n", 377 | "
" 378 | ], 379 | "text/plain": [ 380 | " 0 1 2 3 4\n", 381 | "1 -1.772171 0.207613 -1.480314 0.191361 -2.296765\n", 382 | "2 -0.576407 -0.615181 1.233100 0.092227 -1.881353\n", 383 | "0 0.950120 1.104541 -0.135333 -2.157449 -1.786119" 384 | ] 385 | }, 386 | "execution_count": 10, 387 | "metadata": {}, 388 | "output_type": "execute_result" 389 | } 390 | ], 391 | "source": [ 392 | "my_data_frame.sort_values(0)" 393 | ] 394 | } 395 | ], 396 | "metadata": { 397 | "kernelspec": { 398 | "display_name": "Python 3", 399 | "language": "python", 400 | "name": "python3" 401 | }, 402 | "language_info": { 403 | "codemirror_mode": { 404 | "name": "ipython", 405 | "version": 3 406 | }, 407 | "file_extension": ".py", 408 | "mimetype": "text/x-python", 409 | "name": "python", 410 | "nbconvert_exporter": "python", 411 | "pygments_lexer": "ipython3", 412 | "version": "3.7.6" 413 | } 414 | }, 415 | "nbformat": 4, 416 | "nbformat_minor": 4 417 | } 418 | -------------------------------------------------------------------------------- /stock_prices/stock_prices.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nickmccullum/advanced-python/9005895eb8e35049c7dae40d1faa363892d5741e/stock_prices/stock_prices.xlsx --------------------------------------------------------------------------------