├── 1) Python ├── 0.png ├── 1.png ├── 2.png ├── 3.png ├── 4.png ├── 5.png ├── 6.png ├── Python.ipynb └── python.jpg ├── 2) Numpy ├── 0.png ├── 1.png ├── 10.png ├── 2.png ├── 3.png ├── 4.png ├── 5.png ├── 6.png ├── 7.png ├── 8.png ├── 9.png ├── Numpy.ipynb └── Numpy.pdf ├── 3) Pandas ├── 0.png ├── 1.png ├── 2.png ├── 3.png ├── 4.png ├── 5.png ├── 6.png ├── 7.png ├── 8.png ├── 9.png ├── Pandas.ipynb ├── Pandas.pdf └── first.csv └── README.md /1) Python/0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataiteam/Data-Science-Cheat-Sheet/2ee8d83062b676ceb055865c688d9c5ebf7e3deb/1) Python/0.png -------------------------------------------------------------------------------- /1) Python/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataiteam/Data-Science-Cheat-Sheet/2ee8d83062b676ceb055865c688d9c5ebf7e3deb/1) Python/1.png -------------------------------------------------------------------------------- /1) Python/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataiteam/Data-Science-Cheat-Sheet/2ee8d83062b676ceb055865c688d9c5ebf7e3deb/1) Python/2.png -------------------------------------------------------------------------------- /1) Python/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataiteam/Data-Science-Cheat-Sheet/2ee8d83062b676ceb055865c688d9c5ebf7e3deb/1) Python/3.png -------------------------------------------------------------------------------- /1) Python/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataiteam/Data-Science-Cheat-Sheet/2ee8d83062b676ceb055865c688d9c5ebf7e3deb/1) Python/4.png -------------------------------------------------------------------------------- /1) Python/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataiteam/Data-Science-Cheat-Sheet/2ee8d83062b676ceb055865c688d9c5ebf7e3deb/1) Python/5.png -------------------------------------------------------------------------------- /1) Python/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataiteam/Data-Science-Cheat-Sheet/2ee8d83062b676ceb055865c688d9c5ebf7e3deb/1) Python/6.png -------------------------------------------------------------------------------- /1) Python/Python.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Python for Data Science\n", 8 | "* [Install Python](#0)\n", 9 | "* [Variables and Data Types](#1)\n", 10 | "* [Python Help](#2)\n", 11 | "* [Strings](#3)\n", 12 | "* [Lists](#4)\n", 13 | "* [Python Libraries](#5)\n", 14 | "* [Numpy](#6)" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "![Title](python.jpg)" 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "metadata": {}, 27 | "source": [ 28 | "\n", 29 | "## Install Python\n", 30 | "![Title](0.png)" 31 | ] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "metadata": {}, 36 | "source": [ 37 | "\n", 38 | "## Variables and Data Types\n", 39 | "![Title](1.png)" 40 | ] 41 | }, 42 | { 43 | "cell_type": "code", 44 | "execution_count": 2, 45 | "metadata": {}, 46 | "outputs": [ 47 | { 48 | "data": { 49 | "text/plain": [ 50 | "10" 51 | ] 52 | }, 53 | "execution_count": 2, 54 | "metadata": {}, 55 | "output_type": "execute_result" 56 | } 57 | ], 58 | "source": [ 59 | "meyve_fiyati = 10\n", 60 | "meyve_fiyati" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": 10, 66 | "metadata": {}, 67 | "outputs": [ 68 | { 69 | "data": { 70 | "text/plain": [ 71 | "5.0" 72 | ] 73 | }, 74 | "execution_count": 10, 75 | "metadata": {}, 76 | "output_type": "execute_result" 77 | } 78 | ], 79 | "source": [ 80 | "# ilk ornek\n", 81 | "elma_fiyati = 10\n", 82 | "yeni_elma_fiyati1 = elma_fiyati + 10\n", 83 | "yeni_elma_fiyati2 = elma_fiyati - 10\n", 84 | "yeni_elma_fiyati3 = elma_fiyati*2\n", 85 | "yeni_elma_fiyati4 = elma_fiyati*elma_fiyati\n", 86 | "yeni_elma_fiyati5 = elma_fiyati**2\n", 87 | "yeni_elma_fiyati6 = elma_fiyati%3 # 3*3 + 1 = 10\n", 88 | "yeni_elma_fiyati7 = elma_fiyati/2\n", 89 | "yeni_elma_fiyati7" 90 | ] 91 | }, 92 | { 93 | "cell_type": "code", 94 | "execution_count": null, 95 | "metadata": {}, 96 | "outputs": [], 97 | "source": [ 98 | "# string \"dataiteam\"\n", 99 | "# int 5\n", 100 | "# float 5.5\n", 101 | "# boolean True, False" 102 | ] 103 | }, 104 | { 105 | "cell_type": "code", 106 | "execution_count": 11, 107 | "metadata": {}, 108 | "outputs": [], 109 | "source": [ 110 | "s = \"merhaba\"\n", 111 | "i = 5\n", 112 | "f = 5.5\n", 113 | "t = True" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": 14, 119 | "metadata": {}, 120 | "outputs": [ 121 | { 122 | "data": { 123 | "text/plain": [ 124 | "5" 125 | ] 126 | }, 127 | "execution_count": 14, 128 | "metadata": {}, 129 | "output_type": "execute_result" 130 | } 131 | ], 132 | "source": [ 133 | "s1 = str(i)\n", 134 | "i1 = int(s1)\n", 135 | "i1" 136 | ] 137 | }, 138 | { 139 | "cell_type": "code", 140 | "execution_count": 16, 141 | "metadata": {}, 142 | "outputs": [ 143 | { 144 | "ename": "TypeError", 145 | "evalue": "can only concatenate str (not \"int\") to str", 146 | "output_type": "error", 147 | "traceback": [ 148 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 149 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 150 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0ms1\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;36m5\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 151 | "\u001b[1;31mTypeError\u001b[0m: can only concatenate str (not \"int\") to str" 152 | ] 153 | } 154 | ], 155 | "source": [ 156 | "\"5\" + 5" 157 | ] 158 | }, 159 | { 160 | "cell_type": "code", 161 | "execution_count": 17, 162 | "metadata": {}, 163 | "outputs": [ 164 | { 165 | "data": { 166 | "text/plain": [ 167 | "'True'" 168 | ] 169 | }, 170 | "execution_count": 17, 171 | "metadata": {}, 172 | "output_type": "execute_result" 173 | } 174 | ], 175 | "source": [ 176 | "str(t)" 177 | ] 178 | }, 179 | { 180 | "cell_type": "code", 181 | "execution_count": 21, 182 | "metadata": {}, 183 | "outputs": [ 184 | { 185 | "data": { 186 | "text/plain": [ 187 | "5" 188 | ] 189 | }, 190 | "execution_count": 21, 191 | "metadata": {}, 192 | "output_type": "execute_result" 193 | } 194 | ], 195 | "source": [ 196 | "int(5.7)" 197 | ] 198 | }, 199 | { 200 | "cell_type": "markdown", 201 | "metadata": {}, 202 | "source": [ 203 | "\n", 204 | "## Python Help\n", 205 | "![Title](2.png)" 206 | ] 207 | }, 208 | { 209 | "cell_type": "code", 210 | "execution_count": 23, 211 | "metadata": {}, 212 | "outputs": [], 213 | "source": [ 214 | "# help(int)" 215 | ] 216 | }, 217 | { 218 | "cell_type": "markdown", 219 | "metadata": {}, 220 | "source": [ 221 | "\n", 222 | "## Strings\n", 223 | "![Title](3.png)" 224 | ] 225 | }, 226 | { 227 | "cell_type": "code", 228 | "execution_count": 24, 229 | "metadata": {}, 230 | "outputs": [ 231 | { 232 | "data": { 233 | "text/plain": [ 234 | "'datai team'" 235 | ] 236 | }, 237 | "execution_count": 24, 238 | "metadata": {}, 239 | "output_type": "execute_result" 240 | } 241 | ], 242 | "source": [ 243 | "s1 = \"datai team\"\n", 244 | "s1" 245 | ] 246 | }, 247 | { 248 | "cell_type": "code", 249 | "execution_count": 27, 250 | "metadata": {}, 251 | "outputs": [ 252 | { 253 | "data": { 254 | "text/plain": [ 255 | "'dataidatai'" 256 | ] 257 | }, 258 | "execution_count": 27, 259 | "metadata": {}, 260 | "output_type": "execute_result" 261 | } 262 | ], 263 | "source": [ 264 | "s1 = \"datai\"\n", 265 | "s1*2" 266 | ] 267 | }, 268 | { 269 | "cell_type": "code", 270 | "execution_count": 33, 271 | "metadata": {}, 272 | "outputs": [ 273 | { 274 | "data": { 275 | "text/plain": [ 276 | "'datai_team'" 277 | ] 278 | }, 279 | "execution_count": 33, 280 | "metadata": {}, 281 | "output_type": "execute_result" 282 | } 283 | ], 284 | "source": [ 285 | "s1 = \"datai\"\n", 286 | "s2 = \"team\"\n", 287 | "s3 = s1+\"_\"+s2\n", 288 | "s3" 289 | ] 290 | }, 291 | { 292 | "cell_type": "code", 293 | "execution_count": 35, 294 | "metadata": {}, 295 | "outputs": [ 296 | { 297 | "data": { 298 | "text/plain": [ 299 | "True" 300 | ] 301 | }, 302 | "execution_count": 35, 303 | "metadata": {}, 304 | "output_type": "execute_result" 305 | } 306 | ], 307 | "source": [ 308 | "\"_\" in s3" 309 | ] 310 | }, 311 | { 312 | "cell_type": "code", 313 | "execution_count": 37, 314 | "metadata": {}, 315 | "outputs": [ 316 | { 317 | "data": { 318 | "text/plain": [ 319 | "'datai_team'" 320 | ] 321 | }, 322 | "execution_count": 37, 323 | "metadata": {}, 324 | "output_type": "execute_result" 325 | } 326 | ], 327 | "source": [ 328 | "# string = lists of characters\n", 329 | "s = \"a\" + \"b\"\n", 330 | "s1 = \"datai_team\"\n", 331 | "s1" 332 | ] 333 | }, 334 | { 335 | "cell_type": "code", 336 | "execution_count": 43, 337 | "metadata": {}, 338 | "outputs": [ 339 | { 340 | "data": { 341 | "text/plain": [ 342 | "'datai'" 343 | ] 344 | }, 345 | "execution_count": 43, 346 | "metadata": {}, 347 | "output_type": "execute_result" 348 | } 349 | ], 350 | "source": [ 351 | "s1[0:5]" 352 | ] 353 | }, 354 | { 355 | "cell_type": "code", 356 | "execution_count": 44, 357 | "metadata": {}, 358 | "outputs": [ 359 | { 360 | "data": { 361 | "text/plain": [ 362 | "'team'" 363 | ] 364 | }, 365 | "execution_count": 44, 366 | "metadata": {}, 367 | "output_type": "execute_result" 368 | } 369 | ], 370 | "source": [ 371 | "s1[6:10]" 372 | ] 373 | }, 374 | { 375 | "cell_type": "code", 376 | "execution_count": 46, 377 | "metadata": {}, 378 | "outputs": [ 379 | { 380 | "data": { 381 | "text/plain": [ 382 | "'datai_team'" 383 | ] 384 | }, 385 | "execution_count": 46, 386 | "metadata": {}, 387 | "output_type": "execute_result" 388 | } 389 | ], 390 | "source": [ 391 | "s1[:]" 392 | ] 393 | }, 394 | { 395 | "cell_type": "code", 396 | "execution_count": 51, 397 | "metadata": {}, 398 | "outputs": [ 399 | { 400 | "data": { 401 | "text/plain": [ 402 | "'DATAI_TEAM'" 403 | ] 404 | }, 405 | "execution_count": 51, 406 | "metadata": {}, 407 | "output_type": "execute_result" 408 | } 409 | ], 410 | "source": [ 411 | "s2 = s1.upper()\n", 412 | "s2" 413 | ] 414 | }, 415 | { 416 | "cell_type": "code", 417 | "execution_count": 52, 418 | "metadata": {}, 419 | "outputs": [ 420 | { 421 | "data": { 422 | "text/plain": [ 423 | "'datai_team'" 424 | ] 425 | }, 426 | "execution_count": 52, 427 | "metadata": {}, 428 | "output_type": "execute_result" 429 | } 430 | ], 431 | "source": [ 432 | "s2.lower()" 433 | ] 434 | }, 435 | { 436 | "cell_type": "code", 437 | "execution_count": 53, 438 | "metadata": {}, 439 | "outputs": [ 440 | { 441 | "data": { 442 | "text/plain": [ 443 | "3" 444 | ] 445 | }, 446 | "execution_count": 53, 447 | "metadata": {}, 448 | "output_type": "execute_result" 449 | } 450 | ], 451 | "source": [ 452 | "s1.count(\"a\")" 453 | ] 454 | }, 455 | { 456 | "cell_type": "code", 457 | "execution_count": 54, 458 | "metadata": {}, 459 | "outputs": [ 460 | { 461 | "data": { 462 | "text/plain": [ 463 | "'d1t1i_te1m'" 464 | ] 465 | }, 466 | "execution_count": 54, 467 | "metadata": {}, 468 | "output_type": "execute_result" 469 | } 470 | ], 471 | "source": [ 472 | "s1.replace(\"a\",\"1\")" 473 | ] 474 | }, 475 | { 476 | "cell_type": "code", 477 | "execution_count": 57, 478 | "metadata": {}, 479 | "outputs": [ 480 | { 481 | "data": { 482 | "text/plain": [ 483 | "'datai'" 484 | ] 485 | }, 486 | "execution_count": 57, 487 | "metadata": {}, 488 | "output_type": "execute_result" 489 | } 490 | ], 491 | "source": [ 492 | "s3 = \" datai\"\n", 493 | "s3.strip()" 494 | ] 495 | }, 496 | { 497 | "cell_type": "markdown", 498 | "metadata": {}, 499 | "source": [ 500 | "\n", 501 | "## Lists\n", 502 | "![Title](4.png)" 503 | ] 504 | }, 505 | { 506 | "cell_type": "code", 507 | "execution_count": 58, 508 | "metadata": {}, 509 | "outputs": [ 510 | { 511 | "data": { 512 | "text/plain": [ 513 | "['apple', 'banana', 'cheese', 'water', 'milk']" 514 | ] 515 | }, 516 | "execution_count": 58, 517 | "metadata": {}, 518 | "output_type": "execute_result" 519 | } 520 | ], 521 | "source": [ 522 | "liste1 = [\"apple\",\"banana\",\"cheese\",\"water\",\"milk\"]\n", 523 | "liste1" 524 | ] 525 | }, 526 | { 527 | "cell_type": "code", 528 | "execution_count": 61, 529 | "metadata": {}, 530 | "outputs": [ 531 | { 532 | "data": { 533 | "text/plain": [ 534 | "'cheese'" 535 | ] 536 | }, 537 | "execution_count": 61, 538 | "metadata": {}, 539 | "output_type": "execute_result" 540 | } 541 | ], 542 | "source": [ 543 | "liste1[2]" 544 | ] 545 | }, 546 | { 547 | "cell_type": "code", 548 | "execution_count": 62, 549 | "metadata": {}, 550 | "outputs": [ 551 | { 552 | "data": { 553 | "text/plain": [ 554 | "['apple', 'banana', 'cheese']" 555 | ] 556 | }, 557 | "execution_count": 62, 558 | "metadata": {}, 559 | "output_type": "execute_result" 560 | } 561 | ], 562 | "source": [ 563 | "liste1[:3]" 564 | ] 565 | }, 566 | { 567 | "cell_type": "code", 568 | "execution_count": 63, 569 | "metadata": {}, 570 | "outputs": [ 571 | { 572 | "data": { 573 | "text/plain": [ 574 | "['cheese', 'water', 'milk']" 575 | ] 576 | }, 577 | "execution_count": 63, 578 | "metadata": {}, 579 | "output_type": "execute_result" 580 | } 581 | ], 582 | "source": [ 583 | "liste1[2:]" 584 | ] 585 | }, 586 | { 587 | "cell_type": "code", 588 | "execution_count": 67, 589 | "metadata": {}, 590 | "outputs": [ 591 | { 592 | "data": { 593 | "text/plain": [ 594 | "[['apple', 'banana', 'cheese', 'water', 'milk'],\n", 595 | " ['madrid', 'paris', 'viyana', 'istanbul']]" 596 | ] 597 | }, 598 | "execution_count": 67, 599 | "metadata": {}, 600 | "output_type": "execute_result" 601 | } 602 | ], 603 | "source": [ 604 | "liste1\n", 605 | "liste2 = [\"madrid\",\"paris\",\"viyana\",\"istanbul\"]\n", 606 | "liste2\n", 607 | "liste = [liste1, liste2]\n", 608 | "liste" 609 | ] 610 | }, 611 | { 612 | "cell_type": "code", 613 | "execution_count": 71, 614 | "metadata": {}, 615 | "outputs": [ 616 | { 617 | "data": { 618 | "text/plain": [ 619 | "['madrid', 'paris', 'viyana']" 620 | ] 621 | }, 622 | "execution_count": 71, 623 | "metadata": {}, 624 | "output_type": "execute_result" 625 | } 626 | ], 627 | "source": [ 628 | "liste[1][:3]" 629 | ] 630 | }, 631 | { 632 | "cell_type": "code", 633 | "execution_count": 76, 634 | "metadata": {}, 635 | "outputs": [ 636 | { 637 | "data": { 638 | "text/plain": [ 639 | "['apple',\n", 640 | " 'banana',\n", 641 | " 'cheese',\n", 642 | " 'water',\n", 643 | " 'milk',\n", 644 | " 'madrid',\n", 645 | " 'paris',\n", 646 | " 'viyana',\n", 647 | " 'istanbul']" 648 | ] 649 | }, 650 | "execution_count": 76, 651 | "metadata": {}, 652 | "output_type": "execute_result" 653 | } 654 | ], 655 | "source": [ 656 | "liste1 + liste2" 657 | ] 658 | }, 659 | { 660 | "cell_type": "code", 661 | "execution_count": 77, 662 | "metadata": {}, 663 | "outputs": [ 664 | { 665 | "data": { 666 | "text/plain": [ 667 | "['apple',\n", 668 | " 'banana',\n", 669 | " 'cheese',\n", 670 | " 'water',\n", 671 | " 'milk',\n", 672 | " 'apple',\n", 673 | " 'banana',\n", 674 | " 'cheese',\n", 675 | " 'water',\n", 676 | " 'milk']" 677 | ] 678 | }, 679 | "execution_count": 77, 680 | "metadata": {}, 681 | "output_type": "execute_result" 682 | } 683 | ], 684 | "source": [ 685 | "liste1*2" 686 | ] 687 | }, 688 | { 689 | "cell_type": "code", 690 | "execution_count": 80, 691 | "metadata": {}, 692 | "outputs": [ 693 | { 694 | "data": { 695 | "text/plain": [ 696 | "['apple', 'banana', 'cheese', 'water', 'milk']" 697 | ] 698 | }, 699 | "execution_count": 80, 700 | "metadata": {}, 701 | "output_type": "execute_result" 702 | } 703 | ], 704 | "source": [ 705 | "liste1" 706 | ] 707 | }, 708 | { 709 | "cell_type": "code", 710 | "execution_count": 81, 711 | "metadata": {}, 712 | "outputs": [ 713 | { 714 | "data": { 715 | "text/plain": [ 716 | "1" 717 | ] 718 | }, 719 | "execution_count": 81, 720 | "metadata": {}, 721 | "output_type": "execute_result" 722 | } 723 | ], 724 | "source": [ 725 | "liste1.index('banana')" 726 | ] 727 | }, 728 | { 729 | "cell_type": "code", 730 | "execution_count": 82, 731 | "metadata": {}, 732 | "outputs": [ 733 | { 734 | "data": { 735 | "text/plain": [ 736 | "1" 737 | ] 738 | }, 739 | "execution_count": 82, 740 | "metadata": {}, 741 | "output_type": "execute_result" 742 | } 743 | ], 744 | "source": [ 745 | "liste1.count(\"apple\")" 746 | ] 747 | }, 748 | { 749 | "cell_type": "code", 750 | "execution_count": 83, 751 | "metadata": {}, 752 | "outputs": [ 753 | { 754 | "data": { 755 | "text/plain": [ 756 | "['apple', 'banana', 'cheese', 'water', 'milk', 'sugar']" 757 | ] 758 | }, 759 | "execution_count": 83, 760 | "metadata": {}, 761 | "output_type": "execute_result" 762 | } 763 | ], 764 | "source": [ 765 | "liste1.append(\"sugar\")\n", 766 | "liste1" 767 | ] 768 | }, 769 | { 770 | "cell_type": "code", 771 | "execution_count": 84, 772 | "metadata": {}, 773 | "outputs": [ 774 | { 775 | "data": { 776 | "text/plain": [ 777 | "['banana', 'cheese', 'water', 'milk', 'sugar']" 778 | ] 779 | }, 780 | "execution_count": 84, 781 | "metadata": {}, 782 | "output_type": "execute_result" 783 | } 784 | ], 785 | "source": [ 786 | "liste1.remove(\"apple\")\n", 787 | "liste1" 788 | ] 789 | }, 790 | { 791 | "cell_type": "code", 792 | "execution_count": 87, 793 | "metadata": {}, 794 | "outputs": [ 795 | { 796 | "data": { 797 | "text/plain": [ 798 | "['banana', 'milk', 'sugar']" 799 | ] 800 | }, 801 | "execution_count": 87, 802 | "metadata": {}, 803 | "output_type": "execute_result" 804 | } 805 | ], 806 | "source": [ 807 | "liste1\n", 808 | "del(liste1[1])\n", 809 | "liste1" 810 | ] 811 | }, 812 | { 813 | "cell_type": "code", 814 | "execution_count": 97, 815 | "metadata": {}, 816 | "outputs": [ 817 | { 818 | "data": { 819 | "text/plain": [ 820 | "[4, 3, 2, 1]" 821 | ] 822 | }, 823 | "execution_count": 97, 824 | "metadata": {}, 825 | "output_type": "execute_result" 826 | } 827 | ], 828 | "source": [ 829 | "liste12 = [1,2,3,4]\n", 830 | "liste12.reverse()\n", 831 | "liste12" 832 | ] 833 | }, 834 | { 835 | "cell_type": "code", 836 | "execution_count": 98, 837 | "metadata": {}, 838 | "outputs": [ 839 | { 840 | "data": { 841 | "text/plain": [ 842 | "[4, 3, 2, 1, '!']" 843 | ] 844 | }, 845 | "execution_count": 98, 846 | "metadata": {}, 847 | "output_type": "execute_result" 848 | } 849 | ], 850 | "source": [ 851 | "liste12.extend(\"!\")\n", 852 | "liste12" 853 | ] 854 | }, 855 | { 856 | "cell_type": "code", 857 | "execution_count": 101, 858 | "metadata": {}, 859 | "outputs": [ 860 | { 861 | "data": { 862 | "text/plain": [ 863 | "[1, 2, 3]" 864 | ] 865 | }, 866 | "execution_count": 101, 867 | "metadata": {}, 868 | "output_type": "execute_result" 869 | } 870 | ], 871 | "source": [ 872 | "liste12 = [1,2,3,4]\n", 873 | "liste12.pop(-1)\n", 874 | "liste12" 875 | ] 876 | }, 877 | { 878 | "cell_type": "code", 879 | "execution_count": 102, 880 | "metadata": {}, 881 | "outputs": [ 882 | { 883 | "data": { 884 | "text/plain": [ 885 | "[1, 2, 's', 3, 4]" 886 | ] 887 | }, 888 | "execution_count": 102, 889 | "metadata": {}, 890 | "output_type": "execute_result" 891 | } 892 | ], 893 | "source": [ 894 | "liste12 = [1,2,3,4]\n", 895 | "liste12.insert(2,\"s\")\n", 896 | "liste12" 897 | ] 898 | }, 899 | { 900 | "cell_type": "code", 901 | "execution_count": 106, 902 | "metadata": {}, 903 | "outputs": [ 904 | { 905 | "data": { 906 | "text/plain": [ 907 | "[1, 2, 4, 6, 6, 8, 9]" 908 | ] 909 | }, 910 | "execution_count": 106, 911 | "metadata": {}, 912 | "output_type": "execute_result" 913 | } 914 | ], 915 | "source": [ 916 | "liste123 = [1,6,4,2,6,8,9]\n", 917 | "liste123.sort()\n", 918 | "liste123" 919 | ] 920 | }, 921 | { 922 | "cell_type": "markdown", 923 | "metadata": {}, 924 | "source": [ 925 | "\n", 926 | "## Python Libraries\n", 927 | "![Title](5.png)" 928 | ] 929 | }, 930 | { 931 | "cell_type": "code", 932 | "execution_count": 107, 933 | "metadata": {}, 934 | "outputs": [ 935 | { 936 | "data": { 937 | "text/plain": [ 938 | "array([1, 2, 3])" 939 | ] 940 | }, 941 | "execution_count": 107, 942 | "metadata": {}, 943 | "output_type": "execute_result" 944 | } 945 | ], 946 | "source": [ 947 | "import numpy as np\n", 948 | "array1 = np.array([1,2,3])\n", 949 | "array1" 950 | ] 951 | }, 952 | { 953 | "cell_type": "markdown", 954 | "metadata": {}, 955 | "source": [ 956 | "\n", 957 | "## Numpy\n", 958 | "![Title](6.png)" 959 | ] 960 | }, 961 | { 962 | "cell_type": "code", 963 | "execution_count": 108, 964 | "metadata": {}, 965 | "outputs": [ 966 | { 967 | "data": { 968 | "text/plain": [ 969 | "array([1, 2, 3, 4, 5])" 970 | ] 971 | }, 972 | "execution_count": 108, 973 | "metadata": {}, 974 | "output_type": "execute_result" 975 | } 976 | ], 977 | "source": [ 978 | "import numpy as np\n", 979 | "liste1 = [1,2,3,4,5]\n", 980 | "a1 = np.array(liste1)\n", 981 | "a1" 982 | ] 983 | }, 984 | { 985 | "cell_type": "code", 986 | "execution_count": 112, 987 | "metadata": {}, 988 | "outputs": [ 989 | { 990 | "data": { 991 | "text/plain": [ 992 | "array([[1, 2, 3, 4, 5],\n", 993 | " [1, 2, 3, 4, 5]])" 994 | ] 995 | }, 996 | "execution_count": 112, 997 | "metadata": {}, 998 | "output_type": "execute_result" 999 | } 1000 | ], 1001 | "source": [ 1002 | "a2 = np.array([liste1,liste1])\n", 1003 | "a2" 1004 | ] 1005 | }, 1006 | { 1007 | "cell_type": "code", 1008 | "execution_count": 113, 1009 | "metadata": {}, 1010 | "outputs": [ 1011 | { 1012 | "data": { 1013 | "text/plain": [ 1014 | "3" 1015 | ] 1016 | }, 1017 | "execution_count": 113, 1018 | "metadata": {}, 1019 | "output_type": "execute_result" 1020 | } 1021 | ], 1022 | "source": [ 1023 | "a1[2]" 1024 | ] 1025 | }, 1026 | { 1027 | "cell_type": "code", 1028 | "execution_count": 114, 1029 | "metadata": {}, 1030 | "outputs": [ 1031 | { 1032 | "data": { 1033 | "text/plain": [ 1034 | "array([2, 3])" 1035 | ] 1036 | }, 1037 | "execution_count": 114, 1038 | "metadata": {}, 1039 | "output_type": "execute_result" 1040 | } 1041 | ], 1042 | "source": [ 1043 | "a1[1:3]" 1044 | ] 1045 | }, 1046 | { 1047 | "cell_type": "code", 1048 | "execution_count": 115, 1049 | "metadata": {}, 1050 | "outputs": [ 1051 | { 1052 | "data": { 1053 | "text/plain": [ 1054 | "5" 1055 | ] 1056 | }, 1057 | "execution_count": 115, 1058 | "metadata": {}, 1059 | "output_type": "execute_result" 1060 | } 1061 | ], 1062 | "source": [ 1063 | "a2[0,-1]" 1064 | ] 1065 | }, 1066 | { 1067 | "cell_type": "code", 1068 | "execution_count": 117, 1069 | "metadata": {}, 1070 | "outputs": [ 1071 | { 1072 | "data": { 1073 | "text/plain": [ 1074 | "array([1, 2, 3, 4, 5])" 1075 | ] 1076 | }, 1077 | "execution_count": 117, 1078 | "metadata": {}, 1079 | "output_type": "execute_result" 1080 | } 1081 | ], 1082 | "source": [ 1083 | "a1" 1084 | ] 1085 | }, 1086 | { 1087 | "cell_type": "code", 1088 | "execution_count": 116, 1089 | "metadata": {}, 1090 | "outputs": [ 1091 | { 1092 | "data": { 1093 | "text/plain": [ 1094 | "array([False, False, False, True, True])" 1095 | ] 1096 | }, 1097 | "execution_count": 116, 1098 | "metadata": {}, 1099 | "output_type": "execute_result" 1100 | } 1101 | ], 1102 | "source": [ 1103 | "a1 > 3" 1104 | ] 1105 | }, 1106 | { 1107 | "cell_type": "code", 1108 | "execution_count": 118, 1109 | "metadata": {}, 1110 | "outputs": [ 1111 | { 1112 | "data": { 1113 | "text/plain": [ 1114 | "array([ 2, 4, 6, 8, 10])" 1115 | ] 1116 | }, 1117 | "execution_count": 118, 1118 | "metadata": {}, 1119 | "output_type": "execute_result" 1120 | } 1121 | ], 1122 | "source": [ 1123 | "a1*2" 1124 | ] 1125 | }, 1126 | { 1127 | "cell_type": "code", 1128 | "execution_count": 120, 1129 | "metadata": {}, 1130 | "outputs": [ 1131 | { 1132 | "data": { 1133 | "text/plain": [ 1134 | "array([ 3, 6, 9, 12, 15])" 1135 | ] 1136 | }, 1137 | "execution_count": 120, 1138 | "metadata": {}, 1139 | "output_type": "execute_result" 1140 | } 1141 | ], 1142 | "source": [ 1143 | "a1+a1+a1" 1144 | ] 1145 | }, 1146 | { 1147 | "cell_type": "code", 1148 | "execution_count": 121, 1149 | "metadata": {}, 1150 | "outputs": [ 1151 | { 1152 | "data": { 1153 | "text/plain": [ 1154 | "(5,)" 1155 | ] 1156 | }, 1157 | "execution_count": 121, 1158 | "metadata": {}, 1159 | "output_type": "execute_result" 1160 | } 1161 | ], 1162 | "source": [ 1163 | "a1.shape" 1164 | ] 1165 | }, 1166 | { 1167 | "cell_type": "code", 1168 | "execution_count": 122, 1169 | "metadata": {}, 1170 | "outputs": [ 1171 | { 1172 | "data": { 1173 | "text/plain": [ 1174 | "(2, 5)" 1175 | ] 1176 | }, 1177 | "execution_count": 122, 1178 | "metadata": {}, 1179 | "output_type": "execute_result" 1180 | } 1181 | ], 1182 | "source": [ 1183 | "a2.shape" 1184 | ] 1185 | }, 1186 | { 1187 | "cell_type": "code", 1188 | "execution_count": 127, 1189 | "metadata": {}, 1190 | "outputs": [ 1191 | { 1192 | "data": { 1193 | "text/plain": [ 1194 | "array([1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5])" 1195 | ] 1196 | }, 1197 | "execution_count": 127, 1198 | "metadata": {}, 1199 | "output_type": "execute_result" 1200 | } 1201 | ], 1202 | "source": [ 1203 | "np.append(a1,a2)" 1204 | ] 1205 | }, 1206 | { 1207 | "cell_type": "code", 1208 | "execution_count": 128, 1209 | "metadata": {}, 1210 | "outputs": [ 1211 | { 1212 | "data": { 1213 | "text/plain": [ 1214 | "array([1, 2, 3, 4, 5])" 1215 | ] 1216 | }, 1217 | "execution_count": 128, 1218 | "metadata": {}, 1219 | "output_type": "execute_result" 1220 | } 1221 | ], 1222 | "source": [ 1223 | "a1" 1224 | ] 1225 | }, 1226 | { 1227 | "cell_type": "code", 1228 | "execution_count": 130, 1229 | "metadata": {}, 1230 | "outputs": [ 1231 | { 1232 | "data": { 1233 | "text/plain": [ 1234 | "array([1, 4, 2, 3, 4, 5])" 1235 | ] 1236 | }, 1237 | "execution_count": 130, 1238 | "metadata": {}, 1239 | "output_type": "execute_result" 1240 | } 1241 | ], 1242 | "source": [ 1243 | "np.insert(a1,1,4)" 1244 | ] 1245 | }, 1246 | { 1247 | "cell_type": "code", 1248 | "execution_count": 134, 1249 | "metadata": {}, 1250 | "outputs": [ 1251 | { 1252 | "data": { 1253 | "text/plain": [ 1254 | "array([2, 3, 4, 5])" 1255 | ] 1256 | }, 1257 | "execution_count": 134, 1258 | "metadata": {}, 1259 | "output_type": "execute_result" 1260 | } 1261 | ], 1262 | "source": [ 1263 | "np.delete(a1,0)" 1264 | ] 1265 | }, 1266 | { 1267 | "cell_type": "code", 1268 | "execution_count": 136, 1269 | "metadata": {}, 1270 | "outputs": [ 1271 | { 1272 | "data": { 1273 | "text/plain": [ 1274 | "array([1, 2, 3, 4, 5])" 1275 | ] 1276 | }, 1277 | "execution_count": 136, 1278 | "metadata": {}, 1279 | "output_type": "execute_result" 1280 | } 1281 | ], 1282 | "source": [ 1283 | "a1" 1284 | ] 1285 | }, 1286 | { 1287 | "cell_type": "code", 1288 | "execution_count": 135, 1289 | "metadata": {}, 1290 | "outputs": [ 1291 | { 1292 | "data": { 1293 | "text/plain": [ 1294 | "3.0" 1295 | ] 1296 | }, 1297 | "execution_count": 135, 1298 | "metadata": {}, 1299 | "output_type": "execute_result" 1300 | } 1301 | ], 1302 | "source": [ 1303 | "np.mean(a1)" 1304 | ] 1305 | }, 1306 | { 1307 | "cell_type": "code", 1308 | "execution_count": 137, 1309 | "metadata": {}, 1310 | "outputs": [ 1311 | { 1312 | "data": { 1313 | "text/plain": [ 1314 | "3.0" 1315 | ] 1316 | }, 1317 | "execution_count": 137, 1318 | "metadata": {}, 1319 | "output_type": "execute_result" 1320 | } 1321 | ], 1322 | "source": [ 1323 | "np.median(a1)" 1324 | ] 1325 | }, 1326 | { 1327 | "cell_type": "code", 1328 | "execution_count": 138, 1329 | "metadata": {}, 1330 | "outputs": [ 1331 | { 1332 | "data": { 1333 | "text/plain": [ 1334 | "1.4142135623730951" 1335 | ] 1336 | }, 1337 | "execution_count": 138, 1338 | "metadata": {}, 1339 | "output_type": "execute_result" 1340 | } 1341 | ], 1342 | "source": [ 1343 | "np.std(a1)" 1344 | ] 1345 | } 1346 | ], 1347 | "metadata": { 1348 | "kernelspec": { 1349 | "display_name": "Python 3", 1350 | "language": "python", 1351 | "name": "python3" 1352 | }, 1353 | "language_info": { 1354 | "codemirror_mode": { 1355 | "name": "ipython", 1356 | "version": 3 1357 | }, 1358 | "file_extension": ".py", 1359 | "mimetype": "text/x-python", 1360 | "name": "python", 1361 | "nbconvert_exporter": "python", 1362 | "pygments_lexer": "ipython3", 1363 | "version": "3.7.1" 1364 | } 1365 | }, 1366 | "nbformat": 4, 1367 | "nbformat_minor": 2 1368 | } 1369 | -------------------------------------------------------------------------------- /1) Python/python.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataiteam/Data-Science-Cheat-Sheet/2ee8d83062b676ceb055865c688d9c5ebf7e3deb/1) Python/python.jpg -------------------------------------------------------------------------------- /2) Numpy/0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataiteam/Data-Science-Cheat-Sheet/2ee8d83062b676ceb055865c688d9c5ebf7e3deb/2) Numpy/0.png -------------------------------------------------------------------------------- /2) Numpy/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataiteam/Data-Science-Cheat-Sheet/2ee8d83062b676ceb055865c688d9c5ebf7e3deb/2) Numpy/1.png -------------------------------------------------------------------------------- /2) Numpy/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataiteam/Data-Science-Cheat-Sheet/2ee8d83062b676ceb055865c688d9c5ebf7e3deb/2) Numpy/10.png -------------------------------------------------------------------------------- /2) Numpy/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataiteam/Data-Science-Cheat-Sheet/2ee8d83062b676ceb055865c688d9c5ebf7e3deb/2) Numpy/2.png -------------------------------------------------------------------------------- /2) Numpy/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataiteam/Data-Science-Cheat-Sheet/2ee8d83062b676ceb055865c688d9c5ebf7e3deb/2) Numpy/3.png -------------------------------------------------------------------------------- /2) Numpy/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataiteam/Data-Science-Cheat-Sheet/2ee8d83062b676ceb055865c688d9c5ebf7e3deb/2) Numpy/4.png -------------------------------------------------------------------------------- /2) Numpy/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataiteam/Data-Science-Cheat-Sheet/2ee8d83062b676ceb055865c688d9c5ebf7e3deb/2) Numpy/5.png -------------------------------------------------------------------------------- /2) Numpy/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataiteam/Data-Science-Cheat-Sheet/2ee8d83062b676ceb055865c688d9c5ebf7e3deb/2) Numpy/6.png -------------------------------------------------------------------------------- /2) Numpy/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataiteam/Data-Science-Cheat-Sheet/2ee8d83062b676ceb055865c688d9c5ebf7e3deb/2) Numpy/7.png -------------------------------------------------------------------------------- /2) Numpy/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataiteam/Data-Science-Cheat-Sheet/2ee8d83062b676ceb055865c688d9c5ebf7e3deb/2) Numpy/8.png -------------------------------------------------------------------------------- /2) Numpy/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataiteam/Data-Science-Cheat-Sheet/2ee8d83062b676ceb055865c688d9c5ebf7e3deb/2) Numpy/9.png -------------------------------------------------------------------------------- /2) Numpy/Numpy.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Numpy for Data Science\n", 8 | "* [Numpy](#0)\n", 9 | "* [Arrays](#1)\n", 10 | "* [Input/Output](#2)\n", 11 | "* [Data Types](#3)\n", 12 | "* [Inspecting Array](#4)\n", 13 | "* [Numpy Help](#5)\n", 14 | "* [Array Math](#6)\n", 15 | "* [Copying Arrays](#7)\n", 16 | "* [Sorting Arrays](#8)\n", 17 | "* [Subsetting, Slicing and Indexing](#9)\n", 18 | "* [Array Manipulation](#10)\n" 19 | ] 20 | }, 21 | { 22 | "cell_type": "markdown", 23 | "metadata": {}, 24 | "source": [ 25 | "\n", 26 | "## Numpy\n", 27 | "![Title](0.png)" 28 | ] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "execution_count": 1, 33 | "metadata": {}, 34 | "outputs": [], 35 | "source": [ 36 | "import numpy as np" 37 | ] 38 | }, 39 | { 40 | "cell_type": "markdown", 41 | "metadata": {}, 42 | "source": [ 43 | "\n", 44 | "## Arrays\n", 45 | "![Title](1.png)" 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": 2, 51 | "metadata": {}, 52 | "outputs": [ 53 | { 54 | "data": { 55 | "text/plain": [ 56 | "array([1, 2, 3, 4])" 57 | ] 58 | }, 59 | "execution_count": 2, 60 | "metadata": {}, 61 | "output_type": "execute_result" 62 | } 63 | ], 64 | "source": [ 65 | "a = np.array([1,2,3,4])\n", 66 | "a" 67 | ] 68 | }, 69 | { 70 | "cell_type": "code", 71 | "execution_count": 3, 72 | "metadata": {}, 73 | "outputs": [ 74 | { 75 | "data": { 76 | "text/plain": [ 77 | "array([[1, 2, 3],\n", 78 | " [4, 5, 6],\n", 79 | " [7, 8, 9]])" 80 | ] 81 | }, 82 | "execution_count": 3, 83 | "metadata": {}, 84 | "output_type": "execute_result" 85 | } 86 | ], 87 | "source": [ 88 | "b = np.array([[1,2,3],[4,5,6],[7,8,9]])\n", 89 | "b" 90 | ] 91 | }, 92 | { 93 | "cell_type": "code", 94 | "execution_count": 8, 95 | "metadata": {}, 96 | "outputs": [ 97 | { 98 | "data": { 99 | "text/plain": [ 100 | "array([11., 12., 13., 14.])" 101 | ] 102 | }, 103 | "execution_count": 8, 104 | "metadata": {}, 105 | "output_type": "execute_result" 106 | } 107 | ], 108 | "source": [ 109 | "c = np.zeros(4)\n", 110 | "for i in range(4):\n", 111 | " c[i] = a[i] + 10\n", 112 | "c" 113 | ] 114 | }, 115 | { 116 | "cell_type": "code", 117 | "execution_count": 14, 118 | "metadata": {}, 119 | "outputs": [ 120 | { 121 | "name": "stdout", 122 | "output_type": "stream", 123 | "text": [ 124 | "[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]\n" 125 | ] 126 | }, 127 | { 128 | "data": { 129 | "text/plain": [ 130 | "array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])" 131 | ] 132 | }, 133 | "execution_count": 14, 134 | "metadata": {}, 135 | "output_type": "execute_result" 136 | } 137 | ], 138 | "source": [ 139 | "kedi = np.ones(10)\n", 140 | "print(kedi)\n", 141 | "dog = np.zeros(10)\n", 142 | "dog" 143 | ] 144 | }, 145 | { 146 | "cell_type": "code", 147 | "execution_count": 27, 148 | "metadata": {}, 149 | "outputs": [ 150 | { 151 | "data": { 152 | "text/plain": [ 153 | "array([5, 8])" 154 | ] 155 | }, 156 | "execution_count": 27, 157 | "metadata": {}, 158 | "output_type": "execute_result" 159 | } 160 | ], 161 | "source": [ 162 | "np.arange(5,10,3)" 163 | ] 164 | }, 165 | { 166 | "cell_type": "code", 167 | "execution_count": 26, 168 | "metadata": {}, 169 | "outputs": [ 170 | { 171 | "data": { 172 | "text/plain": [ 173 | "array([ 5. , 6.25, 7.5 , 8.75, 10. ])" 174 | ] 175 | }, 176 | "execution_count": 26, 177 | "metadata": {}, 178 | "output_type": "execute_result" 179 | } 180 | ], 181 | "source": [ 182 | "np.linspace(5,10,5)" 183 | ] 184 | }, 185 | { 186 | "cell_type": "code", 187 | "execution_count": 28, 188 | "metadata": {}, 189 | "outputs": [ 190 | { 191 | "data": { 192 | "text/plain": [ 193 | "array([[5, 5, 5, 5],\n", 194 | " [5, 5, 5, 5],\n", 195 | " [5, 5, 5, 5],\n", 196 | " [5, 5, 5, 5]])" 197 | ] 198 | }, 199 | "execution_count": 28, 200 | "metadata": {}, 201 | "output_type": "execute_result" 202 | } 203 | ], 204 | "source": [ 205 | "np.full((4,4),5)" 206 | ] 207 | }, 208 | { 209 | "cell_type": "code", 210 | "execution_count": 29, 211 | "metadata": {}, 212 | "outputs": [ 213 | { 214 | "data": { 215 | "text/plain": [ 216 | "array([[1., 0., 0., 0., 0.],\n", 217 | " [0., 1., 0., 0., 0.],\n", 218 | " [0., 0., 1., 0., 0.],\n", 219 | " [0., 0., 0., 1., 0.],\n", 220 | " [0., 0., 0., 0., 1.]])" 221 | ] 222 | }, 223 | "execution_count": 29, 224 | "metadata": {}, 225 | "output_type": "execute_result" 226 | } 227 | ], 228 | "source": [ 229 | "np.eye(5)" 230 | ] 231 | }, 232 | { 233 | "cell_type": "code", 234 | "execution_count": 30, 235 | "metadata": {}, 236 | "outputs": [ 237 | { 238 | "data": { 239 | "text/plain": [ 240 | "array([[0.07454573, 0.54904978, 0.16003405, 0.81593976, 0.67797104],\n", 241 | " [0.39841091, 0.62178616, 0.85880033, 0.94358348, 0.63954797],\n", 242 | " [0.87506023, 0.78167133, 0.53358004, 0.89252177, 0.11481598],\n", 243 | " [0.80477405, 0.85450694, 0.2732485 , 0.4181864 , 0.01702107],\n", 244 | " [0.44524266, 0.63259858, 0.09358092, 0.37489794, 0.17610092]])" 245 | ] 246 | }, 247 | "execution_count": 30, 248 | "metadata": {}, 249 | "output_type": "execute_result" 250 | } 251 | ], 252 | "source": [ 253 | "np.random.random((5,5))" 254 | ] 255 | }, 256 | { 257 | "cell_type": "code", 258 | "execution_count": 31, 259 | "metadata": {}, 260 | "outputs": [ 261 | { 262 | "data": { 263 | "text/plain": [ 264 | "array([[0.00000000e+000, 0.00000000e+000, 0.00000000e+000],\n", 265 | " [0.00000000e+000, 0.00000000e+000, 4.13038880e-321],\n", 266 | " [1.02356521e-306, 1.61317855e-307, 2.67008863e-307]])" 267 | ] 268 | }, 269 | "execution_count": 31, 270 | "metadata": {}, 271 | "output_type": "execute_result" 272 | } 273 | ], 274 | "source": [ 275 | "np.empty((3,3))" 276 | ] 277 | }, 278 | { 279 | "cell_type": "markdown", 280 | "metadata": {}, 281 | "source": [ 282 | "\n", 283 | "## Input/Output\n", 284 | "![Title](2.png)" 285 | ] 286 | }, 287 | { 288 | "cell_type": "code", 289 | "execution_count": 42, 290 | "metadata": {}, 291 | "outputs": [ 292 | { 293 | "data": { 294 | "text/plain": [ 295 | "array([1, 2, 3, 4])" 296 | ] 297 | }, 298 | "execution_count": 42, 299 | "metadata": {}, 300 | "output_type": "execute_result" 301 | } 302 | ], 303 | "source": [ 304 | "a = np.array([1,2,3,4])\n", 305 | "np.save(\"array1\",a)\n", 306 | "b = np.load(\"array1.npy\")\n", 307 | "b" 308 | ] 309 | }, 310 | { 311 | "cell_type": "code", 312 | "execution_count": 44, 313 | "metadata": {}, 314 | "outputs": [ 315 | { 316 | "data": { 317 | "text/plain": [ 318 | "array([1., 2., 3., 4.])" 319 | ] 320 | }, 321 | "execution_count": 44, 322 | "metadata": {}, 323 | "output_type": "execute_result" 324 | } 325 | ], 326 | "source": [ 327 | "np.savetxt(\"array1.txt\",a, delimiter = \" \")\n", 328 | "c = np.loadtxt(\"array1.txt\")\n", 329 | "c" 330 | ] 331 | }, 332 | { 333 | "cell_type": "markdown", 334 | "metadata": {}, 335 | "source": [ 336 | "\n", 337 | "## Data Types\n", 338 | "![Title](3.png)" 339 | ] 340 | }, 341 | { 342 | "cell_type": "code", 343 | "execution_count": 45, 344 | "metadata": {}, 345 | "outputs": [ 346 | { 347 | "data": { 348 | "text/plain": [ 349 | "array([1, 2, 3, 4], dtype=int64)" 350 | ] 351 | }, 352 | "execution_count": 45, 353 | "metadata": {}, 354 | "output_type": "execute_result" 355 | } 356 | ], 357 | "source": [ 358 | "a = np.array([1,2,3,4],dtype = np.int64)\n", 359 | "a" 360 | ] 361 | }, 362 | { 363 | "cell_type": "code", 364 | "execution_count": 46, 365 | "metadata": {}, 366 | "outputs": [ 367 | { 368 | "data": { 369 | "text/plain": [ 370 | "array([1., 2., 3., 4.], dtype=float32)" 371 | ] 372 | }, 373 | "execution_count": 46, 374 | "metadata": {}, 375 | "output_type": "execute_result" 376 | } 377 | ], 378 | "source": [ 379 | "a = np.array([1,2,3,4],dtype = np.float32)\n", 380 | "a" 381 | ] 382 | }, 383 | { 384 | "cell_type": "markdown", 385 | "metadata": {}, 386 | "source": [ 387 | "\n", 388 | "## Inspecting Array\n", 389 | "![Title](4.png)" 390 | ] 391 | }, 392 | { 393 | "cell_type": "code", 394 | "execution_count": 53, 395 | "metadata": {}, 396 | "outputs": [ 397 | { 398 | "data": { 399 | "text/plain": [ 400 | "array([[1., 2., 3.],\n", 401 | " [4., 5., 6.]], dtype=float32)" 402 | ] 403 | }, 404 | "execution_count": 53, 405 | "metadata": {}, 406 | "output_type": "execute_result" 407 | } 408 | ], 409 | "source": [ 410 | "a = np.array([[1,2,3],[4,5,6]],dtype = np.float32)\n", 411 | "a" 412 | ] 413 | }, 414 | { 415 | "cell_type": "code", 416 | "execution_count": 48, 417 | "metadata": {}, 418 | "outputs": [ 419 | { 420 | "data": { 421 | "text/plain": [ 422 | "(2, 3)" 423 | ] 424 | }, 425 | "execution_count": 48, 426 | "metadata": {}, 427 | "output_type": "execute_result" 428 | } 429 | ], 430 | "source": [ 431 | "a.shape" 432 | ] 433 | }, 434 | { 435 | "cell_type": "code", 436 | "execution_count": 49, 437 | "metadata": {}, 438 | "outputs": [ 439 | { 440 | "data": { 441 | "text/plain": [ 442 | "2" 443 | ] 444 | }, 445 | "execution_count": 49, 446 | "metadata": {}, 447 | "output_type": "execute_result" 448 | } 449 | ], 450 | "source": [ 451 | "len(a)" 452 | ] 453 | }, 454 | { 455 | "cell_type": "code", 456 | "execution_count": 50, 457 | "metadata": {}, 458 | "outputs": [ 459 | { 460 | "data": { 461 | "text/plain": [ 462 | "6" 463 | ] 464 | }, 465 | "execution_count": 50, 466 | "metadata": {}, 467 | "output_type": "execute_result" 468 | } 469 | ], 470 | "source": [ 471 | "a.size" 472 | ] 473 | }, 474 | { 475 | "cell_type": "code", 476 | "execution_count": 51, 477 | "metadata": {}, 478 | "outputs": [ 479 | { 480 | "data": { 481 | "text/plain": [ 482 | "2" 483 | ] 484 | }, 485 | "execution_count": 51, 486 | "metadata": {}, 487 | "output_type": "execute_result" 488 | } 489 | ], 490 | "source": [ 491 | "a.ndim" 492 | ] 493 | }, 494 | { 495 | "cell_type": "code", 496 | "execution_count": 54, 497 | "metadata": {}, 498 | "outputs": [ 499 | { 500 | "data": { 501 | "text/plain": [ 502 | "dtype('float32')" 503 | ] 504 | }, 505 | "execution_count": 54, 506 | "metadata": {}, 507 | "output_type": "execute_result" 508 | } 509 | ], 510 | "source": [ 511 | "a.dtype" 512 | ] 513 | }, 514 | { 515 | "cell_type": "code", 516 | "execution_count": 55, 517 | "metadata": {}, 518 | "outputs": [ 519 | { 520 | "data": { 521 | "text/plain": [ 522 | "'float32'" 523 | ] 524 | }, 525 | "execution_count": 55, 526 | "metadata": {}, 527 | "output_type": "execute_result" 528 | } 529 | ], 530 | "source": [ 531 | "a.dtype.name" 532 | ] 533 | }, 534 | { 535 | "cell_type": "code", 536 | "execution_count": 57, 537 | "metadata": {}, 538 | "outputs": [ 539 | { 540 | "data": { 541 | "text/plain": [ 542 | "array([[1, 2, 3],\n", 543 | " [4, 5, 6]], dtype=int64)" 544 | ] 545 | }, 546 | "execution_count": 57, 547 | "metadata": {}, 548 | "output_type": "execute_result" 549 | } 550 | ], 551 | "source": [ 552 | "a.astype(np.int64)" 553 | ] 554 | }, 555 | { 556 | "cell_type": "markdown", 557 | "metadata": {}, 558 | "source": [ 559 | "\n", 560 | "## Numpy Help\n", 561 | "![Title](5.png)" 562 | ] 563 | }, 564 | { 565 | "cell_type": "code", 566 | "execution_count": 58, 567 | "metadata": {}, 568 | "outputs": [ 569 | { 570 | "name": "stdout", 571 | "output_type": "stream", 572 | "text": [ 573 | "Data-type of the array's elements.\n", 574 | "\n", 575 | "Parameters\n", 576 | "----------\n", 577 | "None\n", 578 | "\n", 579 | "Returns\n", 580 | "-------\n", 581 | "d : numpy dtype object\n", 582 | "\n", 583 | "See Also\n", 584 | "--------\n", 585 | "numpy.dtype\n", 586 | "\n", 587 | "Examples\n", 588 | "--------\n", 589 | ">>> x\n", 590 | "array([[0, 1],\n", 591 | " [2, 3]])\n", 592 | ">>> x.dtype\n", 593 | "dtype('int32')\n", 594 | ">>> type(x.dtype)\n", 595 | "\n" 596 | ] 597 | } 598 | ], 599 | "source": [ 600 | "np.info(np.ndarray.dtype)" 601 | ] 602 | }, 603 | { 604 | "cell_type": "markdown", 605 | "metadata": {}, 606 | "source": [ 607 | "\n", 608 | "## Array Math\n", 609 | "![Title](6.png)" 610 | ] 611 | }, 612 | { 613 | "cell_type": "code", 614 | "execution_count": 59, 615 | "metadata": {}, 616 | "outputs": [ 617 | { 618 | "data": { 619 | "text/plain": [ 620 | "array([ 6, 8, 10, 12])" 621 | ] 622 | }, 623 | "execution_count": 59, 624 | "metadata": {}, 625 | "output_type": "execute_result" 626 | } 627 | ], 628 | "source": [ 629 | "a = np.array([1,2,3,4])\n", 630 | "b = np.array([5,6,7,8])\n", 631 | "a+b" 632 | ] 633 | }, 634 | { 635 | "cell_type": "code", 636 | "execution_count": 60, 637 | "metadata": {}, 638 | "outputs": [ 639 | { 640 | "data": { 641 | "text/plain": [ 642 | "array([-4, -4, -4, -4])" 643 | ] 644 | }, 645 | "execution_count": 60, 646 | "metadata": {}, 647 | "output_type": "execute_result" 648 | } 649 | ], 650 | "source": [ 651 | "a-b" 652 | ] 653 | }, 654 | { 655 | "cell_type": "code", 656 | "execution_count": 61, 657 | "metadata": {}, 658 | "outputs": [ 659 | { 660 | "data": { 661 | "text/plain": [ 662 | "array([ 5, 12, 21, 32])" 663 | ] 664 | }, 665 | "execution_count": 61, 666 | "metadata": {}, 667 | "output_type": "execute_result" 668 | } 669 | ], 670 | "source": [ 671 | "a*b" 672 | ] 673 | }, 674 | { 675 | "cell_type": "code", 676 | "execution_count": 62, 677 | "metadata": {}, 678 | "outputs": [ 679 | { 680 | "data": { 681 | "text/plain": [ 682 | "array([0.2 , 0.33333333, 0.42857143, 0.5 ])" 683 | ] 684 | }, 685 | "execution_count": 62, 686 | "metadata": {}, 687 | "output_type": "execute_result" 688 | } 689 | ], 690 | "source": [ 691 | "a/b" 692 | ] 693 | }, 694 | { 695 | "cell_type": "code", 696 | "execution_count": 63, 697 | "metadata": {}, 698 | "outputs": [ 699 | { 700 | "data": { 701 | "text/plain": [ 702 | "array([ 5, 12, 21, 32])" 703 | ] 704 | }, 705 | "execution_count": 63, 706 | "metadata": {}, 707 | "output_type": "execute_result" 708 | } 709 | ], 710 | "source": [ 711 | "np.multiply(a,b)" 712 | ] 713 | }, 714 | { 715 | "cell_type": "code", 716 | "execution_count": 64, 717 | "metadata": {}, 718 | "outputs": [ 719 | { 720 | "data": { 721 | "text/plain": [ 722 | "array([1. , 1.41421356, 1.73205081, 2. ])" 723 | ] 724 | }, 725 | "execution_count": 64, 726 | "metadata": {}, 727 | "output_type": "execute_result" 728 | } 729 | ], 730 | "source": [ 731 | "np.sqrt(a)" 732 | ] 733 | }, 734 | { 735 | "cell_type": "code", 736 | "execution_count": 65, 737 | "metadata": {}, 738 | "outputs": [ 739 | { 740 | "data": { 741 | "text/plain": [ 742 | "70" 743 | ] 744 | }, 745 | "execution_count": 65, 746 | "metadata": {}, 747 | "output_type": "execute_result" 748 | } 749 | ], 750 | "source": [ 751 | "a.dot(b)" 752 | ] 753 | }, 754 | { 755 | "cell_type": "code", 756 | "execution_count": 71, 757 | "metadata": {}, 758 | "outputs": [ 759 | { 760 | "data": { 761 | "text/plain": [ 762 | "array([ True, True, True, False, False, False])" 763 | ] 764 | }, 765 | "execution_count": 71, 766 | "metadata": {}, 767 | "output_type": "execute_result" 768 | } 769 | ], 770 | "source": [ 771 | "np.array([0,0,0,1,1,1]) < 0.5" 772 | ] 773 | }, 774 | { 775 | "cell_type": "code", 776 | "execution_count": 69, 777 | "metadata": {}, 778 | "outputs": [ 779 | { 780 | "data": { 781 | "text/plain": [ 782 | "array([ True, False, False, False])" 783 | ] 784 | }, 785 | "execution_count": 69, 786 | "metadata": {}, 787 | "output_type": "execute_result" 788 | } 789 | ], 790 | "source": [ 791 | "a < 2" 792 | ] 793 | }, 794 | { 795 | "cell_type": "code", 796 | "execution_count": 72, 797 | "metadata": {}, 798 | "outputs": [ 799 | { 800 | "data": { 801 | "text/plain": [ 802 | "False" 803 | ] 804 | }, 805 | "execution_count": 72, 806 | "metadata": {}, 807 | "output_type": "execute_result" 808 | } 809 | ], 810 | "source": [ 811 | "np.array_equal(a,b)" 812 | ] 813 | }, 814 | { 815 | "cell_type": "code", 816 | "execution_count": 75, 817 | "metadata": {}, 818 | "outputs": [ 819 | { 820 | "data": { 821 | "text/plain": [ 822 | "array([1, 2, 3, 4])" 823 | ] 824 | }, 825 | "execution_count": 75, 826 | "metadata": {}, 827 | "output_type": "execute_result" 828 | } 829 | ], 830 | "source": [ 831 | "a" 832 | ] 833 | }, 834 | { 835 | "cell_type": "code", 836 | "execution_count": 74, 837 | "metadata": {}, 838 | "outputs": [ 839 | { 840 | "data": { 841 | "text/plain": [ 842 | "10" 843 | ] 844 | }, 845 | "execution_count": 74, 846 | "metadata": {}, 847 | "output_type": "execute_result" 848 | } 849 | ], 850 | "source": [ 851 | "a.sum()" 852 | ] 853 | }, 854 | { 855 | "cell_type": "code", 856 | "execution_count": 76, 857 | "metadata": {}, 858 | "outputs": [ 859 | { 860 | "data": { 861 | "text/plain": [ 862 | "1" 863 | ] 864 | }, 865 | "execution_count": 76, 866 | "metadata": {}, 867 | "output_type": "execute_result" 868 | } 869 | ], 870 | "source": [ 871 | "a.min()" 872 | ] 873 | }, 874 | { 875 | "cell_type": "code", 876 | "execution_count": 77, 877 | "metadata": {}, 878 | "outputs": [ 879 | { 880 | "data": { 881 | "text/plain": [ 882 | "4" 883 | ] 884 | }, 885 | "execution_count": 77, 886 | "metadata": {}, 887 | "output_type": "execute_result" 888 | } 889 | ], 890 | "source": [ 891 | "a.max()" 892 | ] 893 | }, 894 | { 895 | "cell_type": "code", 896 | "execution_count": 83, 897 | "metadata": {}, 898 | "outputs": [ 899 | { 900 | "data": { 901 | "text/plain": [ 902 | "2.5" 903 | ] 904 | }, 905 | "execution_count": 83, 906 | "metadata": {}, 907 | "output_type": "execute_result" 908 | } 909 | ], 910 | "source": [ 911 | "np.mean(a)" 912 | ] 913 | }, 914 | { 915 | "cell_type": "code", 916 | "execution_count": 81, 917 | "metadata": {}, 918 | "outputs": [ 919 | { 920 | "data": { 921 | "text/plain": [ 922 | "2.5" 923 | ] 924 | }, 925 | "execution_count": 81, 926 | "metadata": {}, 927 | "output_type": "execute_result" 928 | } 929 | ], 930 | "source": [ 931 | "np.median(a)" 932 | ] 933 | }, 934 | { 935 | "cell_type": "code", 936 | "execution_count": 82, 937 | "metadata": {}, 938 | "outputs": [ 939 | { 940 | "data": { 941 | "text/plain": [ 942 | "1.118033988749895" 943 | ] 944 | }, 945 | "execution_count": 82, 946 | "metadata": {}, 947 | "output_type": "execute_result" 948 | } 949 | ], 950 | "source": [ 951 | "np.std(a)" 952 | ] 953 | }, 954 | { 955 | "cell_type": "markdown", 956 | "metadata": {}, 957 | "source": [ 958 | "\n", 959 | "## Copying Arrays\n", 960 | "![Title](7.png)" 961 | ] 962 | }, 963 | { 964 | "cell_type": "code", 965 | "execution_count": 90, 966 | "metadata": {}, 967 | "outputs": [ 968 | { 969 | "name": "stdout", 970 | "output_type": "stream", 971 | "text": [ 972 | "[1 2 3 4]\n", 973 | "[1 2 3 4]\n" 974 | ] 975 | } 976 | ], 977 | "source": [ 978 | "a = np.array([1,2,3,4])\n", 979 | "b = a.view()\n", 980 | "print(b)\n", 981 | "c = a.copy()\n", 982 | "print(c)" 983 | ] 984 | }, 985 | { 986 | "cell_type": "code", 987 | "execution_count": 91, 988 | "metadata": {}, 989 | "outputs": [ 990 | { 991 | "name": "stdout", 992 | "output_type": "stream", 993 | "text": [ 994 | "[100 2 3 4]\n", 995 | "[1 2 3 4]\n" 996 | ] 997 | } 998 | ], 999 | "source": [ 1000 | "a[0] = 100\n", 1001 | "print(b)\n", 1002 | "print(c)" 1003 | ] 1004 | }, 1005 | { 1006 | "cell_type": "markdown", 1007 | "metadata": {}, 1008 | "source": [ 1009 | "\n", 1010 | "## Sorting Arrays\n", 1011 | "![Title](8.png)" 1012 | ] 1013 | }, 1014 | { 1015 | "cell_type": "code", 1016 | "execution_count": 103, 1017 | "metadata": {}, 1018 | "outputs": [ 1019 | { 1020 | "name": "stdout", 1021 | "output_type": "stream", 1022 | "text": [ 1023 | "[[ 1 2 3]\n", 1024 | " [ 0 -4 5]]\n", 1025 | "[[ 1 2 3]\n", 1026 | " [-4 0 5]]\n" 1027 | ] 1028 | } 1029 | ], 1030 | "source": [ 1031 | "a = np.array([[1,2,3],[0,-4,5]])\n", 1032 | "print(a)\n", 1033 | "a.sort()\n", 1034 | "print(a)" 1035 | ] 1036 | }, 1037 | { 1038 | "cell_type": "code", 1039 | "execution_count": 104, 1040 | "metadata": {}, 1041 | "outputs": [ 1042 | { 1043 | "data": { 1044 | "text/plain": [ 1045 | "array([[-4, 0, 3],\n", 1046 | " [ 1, 2, 5]])" 1047 | ] 1048 | }, 1049 | "execution_count": 104, 1050 | "metadata": {}, 1051 | "output_type": "execute_result" 1052 | } 1053 | ], 1054 | "source": [ 1055 | "a.sort(axis = 0)\n", 1056 | "a" 1057 | ] 1058 | }, 1059 | { 1060 | "cell_type": "markdown", 1061 | "metadata": {}, 1062 | "source": [ 1063 | "\n", 1064 | "## Subsetting, Slicing and Indexing\n", 1065 | "![Title](9.png)" 1066 | ] 1067 | }, 1068 | { 1069 | "cell_type": "code", 1070 | "execution_count": 105, 1071 | "metadata": {}, 1072 | "outputs": [ 1073 | { 1074 | "data": { 1075 | "text/plain": [ 1076 | "array([[1, 2, 3],\n", 1077 | " [4, 5, 6]])" 1078 | ] 1079 | }, 1080 | "execution_count": 105, 1081 | "metadata": {}, 1082 | "output_type": "execute_result" 1083 | } 1084 | ], 1085 | "source": [ 1086 | "a = np.array([[1,2,3],[4,5,6]])\n", 1087 | "a" 1088 | ] 1089 | }, 1090 | { 1091 | "cell_type": "code", 1092 | "execution_count": 106, 1093 | "metadata": {}, 1094 | "outputs": [ 1095 | { 1096 | "data": { 1097 | "text/plain": [ 1098 | "4" 1099 | ] 1100 | }, 1101 | "execution_count": 106, 1102 | "metadata": {}, 1103 | "output_type": "execute_result" 1104 | } 1105 | ], 1106 | "source": [ 1107 | "a[1,0]" 1108 | ] 1109 | }, 1110 | { 1111 | "cell_type": "code", 1112 | "execution_count": 107, 1113 | "metadata": {}, 1114 | "outputs": [ 1115 | { 1116 | "data": { 1117 | "text/plain": [ 1118 | "array([2, 3])" 1119 | ] 1120 | }, 1121 | "execution_count": 107, 1122 | "metadata": {}, 1123 | "output_type": "execute_result" 1124 | } 1125 | ], 1126 | "source": [ 1127 | "a[0,1:]" 1128 | ] 1129 | }, 1130 | { 1131 | "cell_type": "code", 1132 | "execution_count": 108, 1133 | "metadata": {}, 1134 | "outputs": [ 1135 | { 1136 | "data": { 1137 | "text/plain": [ 1138 | "array([[4, 5, 6],\n", 1139 | " [1, 2, 3]])" 1140 | ] 1141 | }, 1142 | "execution_count": 108, 1143 | "metadata": {}, 1144 | "output_type": "execute_result" 1145 | } 1146 | ], 1147 | "source": [ 1148 | "a[::-1]" 1149 | ] 1150 | }, 1151 | { 1152 | "cell_type": "code", 1153 | "execution_count": 109, 1154 | "metadata": {}, 1155 | "outputs": [ 1156 | { 1157 | "data": { 1158 | "text/plain": [ 1159 | "array([4, 3, 2, 1, 0])" 1160 | ] 1161 | }, 1162 | "execution_count": 109, 1163 | "metadata": {}, 1164 | "output_type": "execute_result" 1165 | } 1166 | ], 1167 | "source": [ 1168 | "b = np.array([0,1,2,3,4])\n", 1169 | "b[::-1]" 1170 | ] 1171 | }, 1172 | { 1173 | "cell_type": "code", 1174 | "execution_count": 111, 1175 | "metadata": {}, 1176 | "outputs": [ 1177 | { 1178 | "data": { 1179 | "text/plain": [ 1180 | "array([ True, True, False, False, False])" 1181 | ] 1182 | }, 1183 | "execution_count": 111, 1184 | "metadata": {}, 1185 | "output_type": "execute_result" 1186 | } 1187 | ], 1188 | "source": [ 1189 | "filtre = b < 2\n", 1190 | "filtre" 1191 | ] 1192 | }, 1193 | { 1194 | "cell_type": "code", 1195 | "execution_count": 112, 1196 | "metadata": {}, 1197 | "outputs": [ 1198 | { 1199 | "data": { 1200 | "text/plain": [ 1201 | "array([0, 1])" 1202 | ] 1203 | }, 1204 | "execution_count": 112, 1205 | "metadata": {}, 1206 | "output_type": "execute_result" 1207 | } 1208 | ], 1209 | "source": [ 1210 | "b[filtre]" 1211 | ] 1212 | }, 1213 | { 1214 | "cell_type": "code", 1215 | "execution_count": 115, 1216 | "metadata": {}, 1217 | "outputs": [ 1218 | { 1219 | "data": { 1220 | "text/plain": [ 1221 | "(1, 0, 2)" 1222 | ] 1223 | }, 1224 | "execution_count": 115, 1225 | "metadata": {}, 1226 | "output_type": "execute_result" 1227 | } 1228 | ], 1229 | "source": [ 1230 | "b = np.array([0,1,2,3,4])\n", 1231 | "b[1],b[0],b[2]" 1232 | ] 1233 | }, 1234 | { 1235 | "cell_type": "code", 1236 | "execution_count": 116, 1237 | "metadata": {}, 1238 | "outputs": [ 1239 | { 1240 | "data": { 1241 | "text/plain": [ 1242 | "array([1, 0, 2])" 1243 | ] 1244 | }, 1245 | "execution_count": 116, 1246 | "metadata": {}, 1247 | "output_type": "execute_result" 1248 | } 1249 | ], 1250 | "source": [ 1251 | "idx = [1,0,2]\n", 1252 | "b[idx]" 1253 | ] 1254 | }, 1255 | { 1256 | "cell_type": "markdown", 1257 | "metadata": {}, 1258 | "source": [ 1259 | "\n", 1260 | "## Array Manipulation\n", 1261 | "![Title](10.png)" 1262 | ] 1263 | }, 1264 | { 1265 | "cell_type": "code", 1266 | "execution_count": 130, 1267 | "metadata": {}, 1268 | "outputs": [ 1269 | { 1270 | "data": { 1271 | "text/plain": [ 1272 | "array([[1, 2, 3, 4],\n", 1273 | " [5, 6, 7, 8]])" 1274 | ] 1275 | }, 1276 | "execution_count": 130, 1277 | "metadata": {}, 1278 | "output_type": "execute_result" 1279 | } 1280 | ], 1281 | "source": [ 1282 | "a = np.array([[1,2,3,4],[5,6,7,8]])\n", 1283 | "a\n" 1284 | ] 1285 | }, 1286 | { 1287 | "cell_type": "code", 1288 | "execution_count": 131, 1289 | "metadata": {}, 1290 | "outputs": [ 1291 | { 1292 | "data": { 1293 | "text/plain": [ 1294 | "array([[1, 5],\n", 1295 | " [2, 6],\n", 1296 | " [3, 7],\n", 1297 | " [4, 8]])" 1298 | ] 1299 | }, 1300 | "execution_count": 131, 1301 | "metadata": {}, 1302 | "output_type": "execute_result" 1303 | } 1304 | ], 1305 | "source": [ 1306 | "np.transpose(a)" 1307 | ] 1308 | }, 1309 | { 1310 | "cell_type": "code", 1311 | "execution_count": 132, 1312 | "metadata": {}, 1313 | "outputs": [ 1314 | { 1315 | "data": { 1316 | "text/plain": [ 1317 | "array([[1, 5],\n", 1318 | " [2, 6],\n", 1319 | " [3, 7],\n", 1320 | " [4, 8]])" 1321 | ] 1322 | }, 1323 | "execution_count": 132, 1324 | "metadata": {}, 1325 | "output_type": "execute_result" 1326 | } 1327 | ], 1328 | "source": [ 1329 | "a.T" 1330 | ] 1331 | }, 1332 | { 1333 | "cell_type": "code", 1334 | "execution_count": 133, 1335 | "metadata": {}, 1336 | "outputs": [ 1337 | { 1338 | "data": { 1339 | "text/plain": [ 1340 | "(2, 4)" 1341 | ] 1342 | }, 1343 | "execution_count": 133, 1344 | "metadata": {}, 1345 | "output_type": "execute_result" 1346 | } 1347 | ], 1348 | "source": [ 1349 | "a.shape" 1350 | ] 1351 | }, 1352 | { 1353 | "cell_type": "code", 1354 | "execution_count": 137, 1355 | "metadata": {}, 1356 | "outputs": [ 1357 | { 1358 | "data": { 1359 | "text/plain": [ 1360 | "array([1, 2, 3, 4, 5, 6, 7, 8])" 1361 | ] 1362 | }, 1363 | "execution_count": 137, 1364 | "metadata": {}, 1365 | "output_type": "execute_result" 1366 | } 1367 | ], 1368 | "source": [ 1369 | "a.ravel()" 1370 | ] 1371 | }, 1372 | { 1373 | "cell_type": "code", 1374 | "execution_count": 139, 1375 | "metadata": {}, 1376 | "outputs": [ 1377 | { 1378 | "data": { 1379 | "text/plain": [ 1380 | "array([[1, 2],\n", 1381 | " [3, 4],\n", 1382 | " [5, 6],\n", 1383 | " [7, 8]])" 1384 | ] 1385 | }, 1386 | "execution_count": 139, 1387 | "metadata": {}, 1388 | "output_type": "execute_result" 1389 | } 1390 | ], 1391 | "source": [ 1392 | "a.reshape(-1,2)" 1393 | ] 1394 | }, 1395 | { 1396 | "cell_type": "code", 1397 | "execution_count": 141, 1398 | "metadata": {}, 1399 | "outputs": [ 1400 | { 1401 | "data": { 1402 | "text/plain": [ 1403 | "array([1, 2, 3, 4, 5, 6, 7, 8])" 1404 | ] 1405 | }, 1406 | "execution_count": 141, 1407 | "metadata": {}, 1408 | "output_type": "execute_result" 1409 | } 1410 | ], 1411 | "source": [ 1412 | "a = a.ravel()\n", 1413 | "a" 1414 | ] 1415 | }, 1416 | { 1417 | "cell_type": "code", 1418 | "execution_count": 142, 1419 | "metadata": {}, 1420 | "outputs": [ 1421 | { 1422 | "data": { 1423 | "text/plain": [ 1424 | "array([ 1, 2, 3, 4, 5, 6, 7, 8, 100])" 1425 | ] 1426 | }, 1427 | "execution_count": 142, 1428 | "metadata": {}, 1429 | "output_type": "execute_result" 1430 | } 1431 | ], 1432 | "source": [ 1433 | "np.append(a,100)" 1434 | ] 1435 | }, 1436 | { 1437 | "cell_type": "code", 1438 | "execution_count": 143, 1439 | "metadata": {}, 1440 | "outputs": [ 1441 | { 1442 | "data": { 1443 | "text/plain": [ 1444 | "array([-100, 1, 2, 3, 4, 5, 6, 7, 8])" 1445 | ] 1446 | }, 1447 | "execution_count": 143, 1448 | "metadata": {}, 1449 | "output_type": "execute_result" 1450 | } 1451 | ], 1452 | "source": [ 1453 | "np.insert(a, 0, -100)" 1454 | ] 1455 | }, 1456 | { 1457 | "cell_type": "code", 1458 | "execution_count": 144, 1459 | "metadata": {}, 1460 | "outputs": [ 1461 | { 1462 | "data": { 1463 | "text/plain": [ 1464 | "array([1, 3, 4, 5, 6, 7, 8])" 1465 | ] 1466 | }, 1467 | "execution_count": 144, 1468 | "metadata": {}, 1469 | "output_type": "execute_result" 1470 | } 1471 | ], 1472 | "source": [ 1473 | "np.delete(a,1)" 1474 | ] 1475 | }, 1476 | { 1477 | "cell_type": "code", 1478 | "execution_count": 145, 1479 | "metadata": {}, 1480 | "outputs": [ 1481 | { 1482 | "data": { 1483 | "text/plain": [ 1484 | "array([1, 2, 3, 4, 5, 6, 7, 8])" 1485 | ] 1486 | }, 1487 | "execution_count": 145, 1488 | "metadata": {}, 1489 | "output_type": "execute_result" 1490 | } 1491 | ], 1492 | "source": [ 1493 | "a" 1494 | ] 1495 | }, 1496 | { 1497 | "cell_type": "code", 1498 | "execution_count": 146, 1499 | "metadata": {}, 1500 | "outputs": [ 1501 | { 1502 | "data": { 1503 | "text/plain": [ 1504 | "array([-1, -2, -3])" 1505 | ] 1506 | }, 1507 | "execution_count": 146, 1508 | "metadata": {}, 1509 | "output_type": "execute_result" 1510 | } 1511 | ], 1512 | "source": [ 1513 | "b = np.array([-1,-2,-3])\n", 1514 | "b" 1515 | ] 1516 | }, 1517 | { 1518 | "cell_type": "code", 1519 | "execution_count": 147, 1520 | "metadata": {}, 1521 | "outputs": [ 1522 | { 1523 | "data": { 1524 | "text/plain": [ 1525 | "array([ 1, 2, 3, 4, 5, 6, 7, 8, -1, -2, -3])" 1526 | ] 1527 | }, 1528 | "execution_count": 147, 1529 | "metadata": {}, 1530 | "output_type": "execute_result" 1531 | } 1532 | ], 1533 | "source": [ 1534 | "np.concatenate((a,b))" 1535 | ] 1536 | }, 1537 | { 1538 | "cell_type": "code", 1539 | "execution_count": 152, 1540 | "metadata": {}, 1541 | "outputs": [ 1542 | { 1543 | "data": { 1544 | "text/plain": [ 1545 | "array([[-1, -2, -3],\n", 1546 | " [-1, -2, -3]])" 1547 | ] 1548 | }, 1549 | "execution_count": 152, 1550 | "metadata": {}, 1551 | "output_type": "execute_result" 1552 | } 1553 | ], 1554 | "source": [ 1555 | "np.vstack((b,b))" 1556 | ] 1557 | }, 1558 | { 1559 | "cell_type": "code", 1560 | "execution_count": 153, 1561 | "metadata": {}, 1562 | "outputs": [ 1563 | { 1564 | "data": { 1565 | "text/plain": [ 1566 | "array([ 1, 2, 3, 4, 5, 6, 7, 8, -1, -2, -3])" 1567 | ] 1568 | }, 1569 | "execution_count": 153, 1570 | "metadata": {}, 1571 | "output_type": "execute_result" 1572 | } 1573 | ], 1574 | "source": [ 1575 | "np.hstack((a,b))" 1576 | ] 1577 | }, 1578 | { 1579 | "cell_type": "code", 1580 | "execution_count": 161, 1581 | "metadata": {}, 1582 | "outputs": [ 1583 | { 1584 | "data": { 1585 | "text/plain": [ 1586 | "array([[ 0, 1, 2, 3],\n", 1587 | " [ 4, 5, 6, 7],\n", 1588 | " [ 8, 9, 10, 11],\n", 1589 | " [12, 13, 14, 15]])" 1590 | ] 1591 | }, 1592 | "execution_count": 161, 1593 | "metadata": {}, 1594 | "output_type": "execute_result" 1595 | } 1596 | ], 1597 | "source": [ 1598 | "a = np.arange(16).reshape(4,4)\n", 1599 | "a" 1600 | ] 1601 | }, 1602 | { 1603 | "cell_type": "code", 1604 | "execution_count": 162, 1605 | "metadata": {}, 1606 | "outputs": [ 1607 | { 1608 | "data": { 1609 | "text/plain": [ 1610 | "[array([[0, 1, 2, 3],\n", 1611 | " [4, 5, 6, 7]]), array([[ 8, 9, 10, 11],\n", 1612 | " [12, 13, 14, 15]])]" 1613 | ] 1614 | }, 1615 | "execution_count": 162, 1616 | "metadata": {}, 1617 | "output_type": "execute_result" 1618 | } 1619 | ], 1620 | "source": [ 1621 | "np.vsplit(a,2)" 1622 | ] 1623 | }, 1624 | { 1625 | "cell_type": "code", 1626 | "execution_count": 163, 1627 | "metadata": {}, 1628 | "outputs": [ 1629 | { 1630 | "data": { 1631 | "text/plain": [ 1632 | "[array([[ 0, 1],\n", 1633 | " [ 4, 5],\n", 1634 | " [ 8, 9],\n", 1635 | " [12, 13]]), array([[ 2, 3],\n", 1636 | " [ 6, 7],\n", 1637 | " [10, 11],\n", 1638 | " [14, 15]])]" 1639 | ] 1640 | }, 1641 | "execution_count": 163, 1642 | "metadata": {}, 1643 | "output_type": "execute_result" 1644 | } 1645 | ], 1646 | "source": [ 1647 | "np.hsplit(a,2)" 1648 | ] 1649 | } 1650 | ], 1651 | "metadata": { 1652 | "kernelspec": { 1653 | "display_name": "Python 3", 1654 | "language": "python", 1655 | "name": "python3" 1656 | }, 1657 | "language_info": { 1658 | "codemirror_mode": { 1659 | "name": "ipython", 1660 | "version": 3 1661 | }, 1662 | "file_extension": ".py", 1663 | "mimetype": "text/x-python", 1664 | "name": "python", 1665 | "nbconvert_exporter": "python", 1666 | "pygments_lexer": "ipython3", 1667 | "version": "3.7.1" 1668 | } 1669 | }, 1670 | "nbformat": 4, 1671 | "nbformat_minor": 2 1672 | } 1673 | -------------------------------------------------------------------------------- /2) Numpy/Numpy.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataiteam/Data-Science-Cheat-Sheet/2ee8d83062b676ceb055865c688d9c5ebf7e3deb/2) Numpy/Numpy.pdf -------------------------------------------------------------------------------- /3) Pandas/0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataiteam/Data-Science-Cheat-Sheet/2ee8d83062b676ceb055865c688d9c5ebf7e3deb/3) Pandas/0.png -------------------------------------------------------------------------------- /3) Pandas/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataiteam/Data-Science-Cheat-Sheet/2ee8d83062b676ceb055865c688d9c5ebf7e3deb/3) Pandas/1.png -------------------------------------------------------------------------------- /3) Pandas/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataiteam/Data-Science-Cheat-Sheet/2ee8d83062b676ceb055865c688d9c5ebf7e3deb/3) Pandas/2.png -------------------------------------------------------------------------------- /3) Pandas/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataiteam/Data-Science-Cheat-Sheet/2ee8d83062b676ceb055865c688d9c5ebf7e3deb/3) Pandas/3.png -------------------------------------------------------------------------------- /3) Pandas/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataiteam/Data-Science-Cheat-Sheet/2ee8d83062b676ceb055865c688d9c5ebf7e3deb/3) Pandas/4.png -------------------------------------------------------------------------------- /3) Pandas/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataiteam/Data-Science-Cheat-Sheet/2ee8d83062b676ceb055865c688d9c5ebf7e3deb/3) Pandas/5.png -------------------------------------------------------------------------------- /3) Pandas/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataiteam/Data-Science-Cheat-Sheet/2ee8d83062b676ceb055865c688d9c5ebf7e3deb/3) Pandas/6.png -------------------------------------------------------------------------------- /3) Pandas/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataiteam/Data-Science-Cheat-Sheet/2ee8d83062b676ceb055865c688d9c5ebf7e3deb/3) Pandas/7.png -------------------------------------------------------------------------------- /3) Pandas/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataiteam/Data-Science-Cheat-Sheet/2ee8d83062b676ceb055865c688d9c5ebf7e3deb/3) Pandas/8.png -------------------------------------------------------------------------------- /3) Pandas/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataiteam/Data-Science-Cheat-Sheet/2ee8d83062b676ceb055865c688d9c5ebf7e3deb/3) Pandas/9.png -------------------------------------------------------------------------------- /3) Pandas/Pandas.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Pandas for Data Science\n", 8 | "* [Pandas](#0)\n", 9 | "* [Pandas Data Structure](#1)\n", 10 | "* [Input/Output](#2)\n", 11 | "* [Pandas Help](#3)\n", 12 | "* [Selection](#4)\n", 13 | "* [Dropping](#5)\n", 14 | "* [Sort and Rank](#6)\n", 15 | "* [Retrieving Series/DataFrame Information](#7)\n", 16 | "* [Applying Functions](#8)\n", 17 | "* [Data Alignment](#9)" 18 | ] 19 | }, 20 | { 21 | "cell_type": "markdown", 22 | "metadata": {}, 23 | "source": [ 24 | "\n", 25 | "## Pandas\n", 26 | "![Title](0.png)" 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": 1, 32 | "metadata": {}, 33 | "outputs": [], 34 | "source": [ 35 | "import pandas as pd" 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": {}, 41 | "source": [ 42 | "\n", 43 | "## Pandas Data Structure\n", 44 | "![Title](1.png)" 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": 3, 50 | "metadata": {}, 51 | "outputs": [ 52 | { 53 | "data": { 54 | "text/plain": [ 55 | "c1 10\n", 56 | "c2 20\n", 57 | "c3 30\n", 58 | "dtype: int64" 59 | ] 60 | }, 61 | "execution_count": 3, 62 | "metadata": {}, 63 | "output_type": "execute_result" 64 | } 65 | ], 66 | "source": [ 67 | "series = pd.Series([10,20,30], index = [\"c1\",\"c2\",\"c3\"])\n", 68 | "series" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": 9, 74 | "metadata": {}, 75 | "outputs": [ 76 | { 77 | "data": { 78 | "text/html": [ 79 | "
\n", 80 | "\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 | "
Football_teamFootballermoney
0barcelonamessi30.0
1real_madridramos20.0
\n", 117 | "
" 118 | ], 119 | "text/plain": [ 120 | " Football_team Footballer money\n", 121 | "0 barcelona messi 30.0\n", 122 | "1 real_madrid ramos 20.0" 123 | ] 124 | }, 125 | "execution_count": 9, 126 | "metadata": {}, 127 | "output_type": "execute_result" 128 | } 129 | ], 130 | "source": [ 131 | "data = {\"Football_team\":[\"barcelona\", \"real_madrid\"],\n", 132 | " \"Footballer\":[\"messi\",\"ramos\"],\n", 133 | " \"money\":[30.0,20.0]}\n", 134 | "df = pd.DataFrame(data, columns=[\"Football_team\", \"Footballer\",\"money\" ])\n", 135 | "df" 136 | ] 137 | }, 138 | { 139 | "cell_type": "markdown", 140 | "metadata": {}, 141 | "source": [ 142 | "\n", 143 | "## Input/Output\n", 144 | "![Title](2.png)" 145 | ] 146 | }, 147 | { 148 | "cell_type": "code", 149 | "execution_count": 10, 150 | "metadata": {}, 151 | "outputs": [ 152 | { 153 | "data": { 154 | "text/html": [ 155 | "
\n", 156 | "\n", 169 | "\n", 170 | " \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 | "
Football_teamFootballermoney
0barcelonamessi30.0
1real_madridramos20.0
\n", 193 | "
" 194 | ], 195 | "text/plain": [ 196 | " Football_team Footballer money\n", 197 | "0 barcelona messi 30.0\n", 198 | "1 real_madrid ramos 20.0" 199 | ] 200 | }, 201 | "execution_count": 10, 202 | "metadata": {}, 203 | "output_type": "execute_result" 204 | } 205 | ], 206 | "source": [ 207 | "data = {\"Football_team\":[\"barcelona\", \"real_madrid\"],\n", 208 | " \"Footballer\":[\"messi\",\"ramos\"],\n", 209 | " \"money\":[30.0,20.0]}\n", 210 | "df = pd.DataFrame(data, columns=[\"Football_team\", \"Footballer\",\"money\" ])\n", 211 | "df" 212 | ] 213 | }, 214 | { 215 | "cell_type": "code", 216 | "execution_count": 19, 217 | "metadata": {}, 218 | "outputs": [ 219 | { 220 | "data": { 221 | "text/html": [ 222 | "
\n", 223 | "\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 | "
Football_teamFootballermoney
0barcelonamessi30.0
1real_madridramos20.0
\n", 260 | "
" 261 | ], 262 | "text/plain": [ 263 | " Football_team Footballer money\n", 264 | "0 barcelona messi 30.0\n", 265 | "1 real_madrid ramos 20.0" 266 | ] 267 | }, 268 | "execution_count": 19, 269 | "metadata": {}, 270 | "output_type": "execute_result" 271 | } 272 | ], 273 | "source": [ 274 | "df.to_csv(\"first.csv\")\n", 275 | "df1 = pd.read_csv(\"first.csv\",index_col = 0)\n", 276 | "df1" 277 | ] 278 | }, 279 | { 280 | "cell_type": "markdown", 281 | "metadata": {}, 282 | "source": [ 283 | "\n", 284 | "## Pandas Help\n", 285 | "![Title](3.png)" 286 | ] 287 | }, 288 | { 289 | "cell_type": "code", 290 | "execution_count": 20, 291 | "metadata": {}, 292 | "outputs": [ 293 | { 294 | "name": "stdout", 295 | "output_type": "stream", 296 | "text": [ 297 | "Help on property:\n", 298 | "\n", 299 | " Access a group of rows and columns by label(s) or a boolean array.\n", 300 | " \n", 301 | " ``.loc[]`` is primarily label based, but may also be used with a\n", 302 | " boolean array.\n", 303 | " \n", 304 | " Allowed inputs are:\n", 305 | " \n", 306 | " - A single label, e.g. ``5`` or ``'a'``, (note that ``5`` is\n", 307 | " interpreted as a *label* of the index, and **never** as an\n", 308 | " integer position along the index).\n", 309 | " - A list or array of labels, e.g. ``['a', 'b', 'c']``.\n", 310 | " - A slice object with labels, e.g. ``'a':'f'``.\n", 311 | " \n", 312 | " .. warning:: Note that contrary to usual python slices, **both** the\n", 313 | " start and the stop are included\n", 314 | " \n", 315 | " - A boolean array of the same length as the axis being sliced,\n", 316 | " e.g. ``[True, False, True]``.\n", 317 | " - A ``callable`` function with one argument (the calling Series, DataFrame\n", 318 | " or Panel) and that returns valid output for indexing (one of the above)\n", 319 | " \n", 320 | " See more at :ref:`Selection by Label `\n", 321 | " \n", 322 | " See Also\n", 323 | " --------\n", 324 | " DataFrame.at : Access a single value for a row/column label pair\n", 325 | " DataFrame.iloc : Access group of rows and columns by integer position(s)\n", 326 | " DataFrame.xs : Returns a cross-section (row(s) or column(s)) from the\n", 327 | " Series/DataFrame.\n", 328 | " Series.loc : Access group of values using labels\n", 329 | " \n", 330 | " Examples\n", 331 | " --------\n", 332 | " **Getting values**\n", 333 | " \n", 334 | " >>> df = pd.DataFrame([[1, 2], [4, 5], [7, 8]],\n", 335 | " ... index=['cobra', 'viper', 'sidewinder'],\n", 336 | " ... columns=['max_speed', 'shield'])\n", 337 | " >>> df\n", 338 | " max_speed shield\n", 339 | " cobra 1 2\n", 340 | " viper 4 5\n", 341 | " sidewinder 7 8\n", 342 | " \n", 343 | " Single label. Note this returns the row as a Series.\n", 344 | " \n", 345 | " >>> df.loc['viper']\n", 346 | " max_speed 4\n", 347 | " shield 5\n", 348 | " Name: viper, dtype: int64\n", 349 | " \n", 350 | " List of labels. Note using ``[[]]`` returns a DataFrame.\n", 351 | " \n", 352 | " >>> df.loc[['viper', 'sidewinder']]\n", 353 | " max_speed shield\n", 354 | " viper 4 5\n", 355 | " sidewinder 7 8\n", 356 | " \n", 357 | " Single label for row and column\n", 358 | " \n", 359 | " >>> df.loc['cobra', 'shield']\n", 360 | " 2\n", 361 | " \n", 362 | " Slice with labels for row and single label for column. As mentioned\n", 363 | " above, note that both the start and stop of the slice are included.\n", 364 | " \n", 365 | " >>> df.loc['cobra':'viper', 'max_speed']\n", 366 | " cobra 1\n", 367 | " viper 4\n", 368 | " Name: max_speed, dtype: int64\n", 369 | " \n", 370 | " Boolean list with the same length as the row axis\n", 371 | " \n", 372 | " >>> df.loc[[False, False, True]]\n", 373 | " max_speed shield\n", 374 | " sidewinder 7 8\n", 375 | " \n", 376 | " Conditional that returns a boolean Series\n", 377 | " \n", 378 | " >>> df.loc[df['shield'] > 6]\n", 379 | " max_speed shield\n", 380 | " sidewinder 7 8\n", 381 | " \n", 382 | " Conditional that returns a boolean Series with column labels specified\n", 383 | " \n", 384 | " >>> df.loc[df['shield'] > 6, ['max_speed']]\n", 385 | " max_speed\n", 386 | " sidewinder 7\n", 387 | " \n", 388 | " Callable that returns a boolean Series\n", 389 | " \n", 390 | " >>> df.loc[lambda df: df['shield'] == 8]\n", 391 | " max_speed shield\n", 392 | " sidewinder 7 8\n", 393 | " \n", 394 | " **Setting values**\n", 395 | " \n", 396 | " Set value for all items matching the list of labels\n", 397 | " \n", 398 | " >>> df.loc[['viper', 'sidewinder'], ['shield']] = 50\n", 399 | " >>> df\n", 400 | " max_speed shield\n", 401 | " cobra 1 2\n", 402 | " viper 4 50\n", 403 | " sidewinder 7 50\n", 404 | " \n", 405 | " Set value for an entire row\n", 406 | " \n", 407 | " >>> df.loc['cobra'] = 10\n", 408 | " >>> df\n", 409 | " max_speed shield\n", 410 | " cobra 10 10\n", 411 | " viper 4 50\n", 412 | " sidewinder 7 50\n", 413 | " \n", 414 | " Set value for an entire column\n", 415 | " \n", 416 | " >>> df.loc[:, 'max_speed'] = 30\n", 417 | " >>> df\n", 418 | " max_speed shield\n", 419 | " cobra 30 10\n", 420 | " viper 30 50\n", 421 | " sidewinder 30 50\n", 422 | " \n", 423 | " Set value for rows matching callable condition\n", 424 | " \n", 425 | " >>> df.loc[df['shield'] > 35] = 0\n", 426 | " >>> df\n", 427 | " max_speed shield\n", 428 | " cobra 30 10\n", 429 | " viper 0 0\n", 430 | " sidewinder 0 0\n", 431 | " \n", 432 | " **Getting values on a DataFrame with an index that has integer labels**\n", 433 | " \n", 434 | " Another example using integers for the index\n", 435 | " \n", 436 | " >>> df = pd.DataFrame([[1, 2], [4, 5], [7, 8]],\n", 437 | " ... index=[7, 8, 9], columns=['max_speed', 'shield'])\n", 438 | " >>> df\n", 439 | " max_speed shield\n", 440 | " 7 1 2\n", 441 | " 8 4 5\n", 442 | " 9 7 8\n", 443 | " \n", 444 | " Slice with integer labels for rows. As mentioned above, note that both\n", 445 | " the start and stop of the slice are included.\n", 446 | " \n", 447 | " >>> df.loc[7:9]\n", 448 | " max_speed shield\n", 449 | " 7 1 2\n", 450 | " 8 4 5\n", 451 | " 9 7 8\n", 452 | " \n", 453 | " **Getting values with a MultiIndex**\n", 454 | " \n", 455 | " A number of examples using a DataFrame with a MultiIndex\n", 456 | " \n", 457 | " >>> tuples = [\n", 458 | " ... ('cobra', 'mark i'), ('cobra', 'mark ii'),\n", 459 | " ... ('sidewinder', 'mark i'), ('sidewinder', 'mark ii'),\n", 460 | " ... ('viper', 'mark ii'), ('viper', 'mark iii')\n", 461 | " ... ]\n", 462 | " >>> index = pd.MultiIndex.from_tuples(tuples)\n", 463 | " >>> values = [[12, 2], [0, 4], [10, 20],\n", 464 | " ... [1, 4], [7, 1], [16, 36]]\n", 465 | " >>> df = pd.DataFrame(values, columns=['max_speed', 'shield'], index=index)\n", 466 | " >>> df\n", 467 | " max_speed shield\n", 468 | " cobra mark i 12 2\n", 469 | " mark ii 0 4\n", 470 | " sidewinder mark i 10 20\n", 471 | " mark ii 1 4\n", 472 | " viper mark ii 7 1\n", 473 | " mark iii 16 36\n", 474 | " \n", 475 | " Single label. Note this returns a DataFrame with a single index.\n", 476 | " \n", 477 | " >>> df.loc['cobra']\n", 478 | " max_speed shield\n", 479 | " mark i 12 2\n", 480 | " mark ii 0 4\n", 481 | " \n", 482 | " Single index tuple. Note this returns a Series.\n", 483 | " \n", 484 | " >>> df.loc[('cobra', 'mark ii')]\n", 485 | " max_speed 0\n", 486 | " shield 4\n", 487 | " Name: (cobra, mark ii), dtype: int64\n", 488 | " \n", 489 | " Single label for row and column. Similar to passing in a tuple, this\n", 490 | " returns a Series.\n", 491 | " \n", 492 | " >>> df.loc['cobra', 'mark i']\n", 493 | " max_speed 12\n", 494 | " shield 2\n", 495 | " Name: (cobra, mark i), dtype: int64\n", 496 | " \n", 497 | " Single tuple. Note using ``[[]]`` returns a DataFrame.\n", 498 | " \n", 499 | " >>> df.loc[[('cobra', 'mark ii')]]\n", 500 | " max_speed shield\n", 501 | " cobra mark ii 0 4\n", 502 | " \n", 503 | " Single tuple for the index with a single label for the column\n", 504 | " \n", 505 | " >>> df.loc[('cobra', 'mark i'), 'shield']\n", 506 | " 2\n", 507 | " \n", 508 | " Slice from index tuple to single label\n", 509 | " \n", 510 | " >>> df.loc[('cobra', 'mark i'):'viper']\n", 511 | " max_speed shield\n", 512 | " cobra mark i 12 2\n", 513 | " mark ii 0 4\n", 514 | " sidewinder mark i 10 20\n", 515 | " mark ii 1 4\n", 516 | " viper mark ii 7 1\n", 517 | " mark iii 16 36\n", 518 | " \n", 519 | " Slice from index tuple to index tuple\n", 520 | " \n", 521 | " >>> df.loc[('cobra', 'mark i'):('viper', 'mark ii')]\n", 522 | " max_speed shield\n", 523 | " cobra mark i 12 2\n", 524 | " mark ii 0 4\n", 525 | " sidewinder mark i 10 20\n", 526 | " mark ii 1 4\n", 527 | " viper mark ii 7 1\n", 528 | " \n", 529 | " Raises\n", 530 | " ------\n", 531 | " KeyError:\n", 532 | " when any items are not found\n", 533 | "\n" 534 | ] 535 | } 536 | ], 537 | "source": [ 538 | "help(pd.Series.loc)" 539 | ] 540 | }, 541 | { 542 | "cell_type": "markdown", 543 | "metadata": {}, 544 | "source": [ 545 | "\n", 546 | "## Selection\n", 547 | "![Title](4.png)" 548 | ] 549 | }, 550 | { 551 | "cell_type": "code", 552 | "execution_count": 25, 553 | "metadata": {}, 554 | "outputs": [ 555 | { 556 | "data": { 557 | "text/html": [ 558 | "
\n", 559 | "\n", 572 | "\n", 573 | " \n", 574 | " \n", 575 | " \n", 576 | " \n", 577 | " \n", 578 | " \n", 579 | " \n", 580 | " \n", 581 | " \n", 582 | " \n", 583 | " \n", 584 | " \n", 585 | " \n", 586 | " \n", 587 | " \n", 588 | " \n", 589 | " \n", 590 | " \n", 591 | " \n", 592 | " \n", 593 | " \n", 594 | " \n", 595 | "
Football_teamFootballermoney
0barcelonamessi30.0
1real_madridramos20.0
\n", 596 | "
" 597 | ], 598 | "text/plain": [ 599 | " Football_team Footballer money\n", 600 | "0 barcelona messi 30.0\n", 601 | "1 real_madrid ramos 20.0" 602 | ] 603 | }, 604 | "execution_count": 25, 605 | "metadata": {}, 606 | "output_type": "execute_result" 607 | } 608 | ], 609 | "source": [ 610 | "df" 611 | ] 612 | }, 613 | { 614 | "cell_type": "code", 615 | "execution_count": 26, 616 | "metadata": {}, 617 | "outputs": [ 618 | { 619 | "data": { 620 | "text/plain": [ 621 | "0 30.0\n", 622 | "1 20.0\n", 623 | "Name: money, dtype: float64" 624 | ] 625 | }, 626 | "execution_count": 26, 627 | "metadata": {}, 628 | "output_type": "execute_result" 629 | } 630 | ], 631 | "source": [ 632 | "df[\"money\"]" 633 | ] 634 | }, 635 | { 636 | "cell_type": "code", 637 | "execution_count": 28, 638 | "metadata": {}, 639 | "outputs": [ 640 | { 641 | "data": { 642 | "text/html": [ 643 | "
\n", 644 | "\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 | "
Football_teamFootballermoney
0barcelonamessi30.0
\n", 675 | "
" 676 | ], 677 | "text/plain": [ 678 | " Football_team Footballer money\n", 679 | "0 barcelona messi 30.0" 680 | ] 681 | }, 682 | "execution_count": 28, 683 | "metadata": {}, 684 | "output_type": "execute_result" 685 | } 686 | ], 687 | "source": [ 688 | "df[:1]" 689 | ] 690 | }, 691 | { 692 | "cell_type": "code", 693 | "execution_count": 29, 694 | "metadata": {}, 695 | "outputs": [ 696 | { 697 | "data": { 698 | "text/plain": [ 699 | "'ramos'" 700 | ] 701 | }, 702 | "execution_count": 29, 703 | "metadata": {}, 704 | "output_type": "execute_result" 705 | } 706 | ], 707 | "source": [ 708 | "df.iloc[1,1]" 709 | ] 710 | }, 711 | { 712 | "cell_type": "code", 713 | "execution_count": 30, 714 | "metadata": {}, 715 | "outputs": [ 716 | { 717 | "data": { 718 | "text/plain": [ 719 | "'ramos'" 720 | ] 721 | }, 722 | "execution_count": 30, 723 | "metadata": {}, 724 | "output_type": "execute_result" 725 | } 726 | ], 727 | "source": [ 728 | "df.loc[1,\"Footballer\"]" 729 | ] 730 | }, 731 | { 732 | "cell_type": "code", 733 | "execution_count": 35, 734 | "metadata": {}, 735 | "outputs": [], 736 | "source": [ 737 | "#df.ix[1,1]" 738 | ] 739 | }, 740 | { 741 | "cell_type": "code", 742 | "execution_count": 38, 743 | "metadata": {}, 744 | "outputs": [ 745 | { 746 | "data": { 747 | "text/html": [ 748 | "
\n", 749 | "\n", 762 | "\n", 763 | " \n", 764 | " \n", 765 | " \n", 766 | " \n", 767 | " \n", 768 | " \n", 769 | " \n", 770 | " \n", 771 | " \n", 772 | " \n", 773 | " \n", 774 | " \n", 775 | " \n", 776 | " \n", 777 | " \n", 778 | " \n", 779 | " \n", 780 | " \n", 781 | " \n", 782 | " \n", 783 | " \n", 784 | " \n", 785 | "
Football_teamFootballermoney
0barcelonamessi30.0
1real_madridramos20.0
\n", 786 | "
" 787 | ], 788 | "text/plain": [ 789 | " Football_team Footballer money\n", 790 | "0 barcelona messi 30.0\n", 791 | "1 real_madrid ramos 20.0" 792 | ] 793 | }, 794 | "execution_count": 38, 795 | "metadata": {}, 796 | "output_type": "execute_result" 797 | } 798 | ], 799 | "source": [ 800 | "df" 801 | ] 802 | }, 803 | { 804 | "cell_type": "code", 805 | "execution_count": 39, 806 | "metadata": {}, 807 | "outputs": [ 808 | { 809 | "data": { 810 | "text/html": [ 811 | "
\n", 812 | "\n", 825 | "\n", 826 | " \n", 827 | " \n", 828 | " \n", 829 | " \n", 830 | " \n", 831 | " \n", 832 | " \n", 833 | " \n", 834 | " \n", 835 | " \n", 836 | " \n", 837 | " \n", 838 | " \n", 839 | " \n", 840 | " \n", 841 | " \n", 842 | "
Football_teamFootballermoney
1real_madridramos20.0
\n", 843 | "
" 844 | ], 845 | "text/plain": [ 846 | " Football_team Footballer money\n", 847 | "1 real_madrid ramos 20.0" 848 | ] 849 | }, 850 | "execution_count": 39, 851 | "metadata": {}, 852 | "output_type": "execute_result" 853 | } 854 | ], 855 | "source": [ 856 | "filter_ = 25 > df[\"money\"]\n", 857 | "df[filter_]" 858 | ] 859 | }, 860 | { 861 | "cell_type": "code", 862 | "execution_count": 44, 863 | "metadata": {}, 864 | "outputs": [ 865 | { 866 | "data": { 867 | "text/plain": [ 868 | "c1 10\n", 869 | "c2 20\n", 870 | "c3 30\n", 871 | "dtype: int64" 872 | ] 873 | }, 874 | "execution_count": 44, 875 | "metadata": {}, 876 | "output_type": "execute_result" 877 | } 878 | ], 879 | "source": [ 880 | "series" 881 | ] 882 | }, 883 | { 884 | "cell_type": "code", 885 | "execution_count": 46, 886 | "metadata": {}, 887 | "outputs": [ 888 | { 889 | "data": { 890 | "text/plain": [ 891 | "c1 10\n", 892 | "c2 100\n", 893 | "c3 30\n", 894 | "dtype: int64" 895 | ] 896 | }, 897 | "execution_count": 46, 898 | "metadata": {}, 899 | "output_type": "execute_result" 900 | } 901 | ], 902 | "source": [ 903 | "series[\"c2\"] = 100\n", 904 | "series" 905 | ] 906 | }, 907 | { 908 | "cell_type": "markdown", 909 | "metadata": {}, 910 | "source": [ 911 | "\n", 912 | "## Dropping\n", 913 | "![Title](5.png)" 914 | ] 915 | }, 916 | { 917 | "cell_type": "code", 918 | "execution_count": 57, 919 | "metadata": {}, 920 | "outputs": [ 921 | { 922 | "data": { 923 | "text/html": [ 924 | "
\n", 925 | "\n", 938 | "\n", 939 | " \n", 940 | " \n", 941 | " \n", 942 | " \n", 943 | " \n", 944 | " \n", 945 | " \n", 946 | " \n", 947 | " \n", 948 | " \n", 949 | " \n", 950 | " \n", 951 | " \n", 952 | " \n", 953 | " \n", 954 | " \n", 955 | " \n", 956 | " \n", 957 | " \n", 958 | " \n", 959 | " \n", 960 | " \n", 961 | "
Football_teamFootballermoney
0barcelonamessi30.0
1real_madridramos20.0
\n", 962 | "
" 963 | ], 964 | "text/plain": [ 965 | " Football_team Footballer money\n", 966 | "0 barcelona messi 30.0\n", 967 | "1 real_madrid ramos 20.0" 968 | ] 969 | }, 970 | "execution_count": 57, 971 | "metadata": {}, 972 | "output_type": "execute_result" 973 | } 974 | ], 975 | "source": [ 976 | "data = {\"Football_team\":[\"barcelona\", \"real_madrid\"],\n", 977 | " \"Footballer\":[\"messi\",\"ramos\"],\n", 978 | " \"money\":[30.0,20.0]}\n", 979 | "df = pd.DataFrame(data, columns=[\"Football_team\", \"Footballer\",\"money\" ])\n", 980 | "df" 981 | ] 982 | }, 983 | { 984 | "cell_type": "code", 985 | "execution_count": 59, 986 | "metadata": {}, 987 | "outputs": [ 988 | { 989 | "data": { 990 | "text/html": [ 991 | "
\n", 992 | "\n", 1005 | "\n", 1006 | " \n", 1007 | " \n", 1008 | " \n", 1009 | " \n", 1010 | " \n", 1011 | " \n", 1012 | " \n", 1013 | " \n", 1014 | " \n", 1015 | " \n", 1016 | " \n", 1017 | " \n", 1018 | " \n", 1019 | " \n", 1020 | " \n", 1021 | " \n", 1022 | "
Football_teamFootballermoney
1real_madridramos20.0
\n", 1023 | "
" 1024 | ], 1025 | "text/plain": [ 1026 | " Football_team Footballer money\n", 1027 | "1 real_madrid ramos 20.0" 1028 | ] 1029 | }, 1030 | "execution_count": 59, 1031 | "metadata": {}, 1032 | "output_type": "execute_result" 1033 | } 1034 | ], 1035 | "source": [ 1036 | "df.drop([0],inplace = True)\n", 1037 | "df" 1038 | ] 1039 | }, 1040 | { 1041 | "cell_type": "code", 1042 | "execution_count": 60, 1043 | "metadata": {}, 1044 | "outputs": [ 1045 | { 1046 | "data": { 1047 | "text/html": [ 1048 | "
\n", 1049 | "\n", 1062 | "\n", 1063 | " \n", 1064 | " \n", 1065 | " \n", 1066 | " \n", 1067 | " \n", 1068 | " \n", 1069 | " \n", 1070 | " \n", 1071 | " \n", 1072 | " \n", 1073 | " \n", 1074 | " \n", 1075 | " \n", 1076 | " \n", 1077 | "
Football_teamFootballer
1real_madridramos
\n", 1078 | "
" 1079 | ], 1080 | "text/plain": [ 1081 | " Football_team Footballer\n", 1082 | "1 real_madrid ramos" 1083 | ] 1084 | }, 1085 | "execution_count": 60, 1086 | "metadata": {}, 1087 | "output_type": "execute_result" 1088 | } 1089 | ], 1090 | "source": [ 1091 | "df.drop([\"money\"],axis = 1,inplace = True)\n", 1092 | "df" 1093 | ] 1094 | }, 1095 | { 1096 | "cell_type": "markdown", 1097 | "metadata": {}, 1098 | "source": [ 1099 | "\n", 1100 | "## Sort and Rank\n", 1101 | "![Title](6.png)" 1102 | ] 1103 | }, 1104 | { 1105 | "cell_type": "code", 1106 | "execution_count": 61, 1107 | "metadata": {}, 1108 | "outputs": [ 1109 | { 1110 | "data": { 1111 | "text/html": [ 1112 | "
\n", 1113 | "\n", 1126 | "\n", 1127 | " \n", 1128 | " \n", 1129 | " \n", 1130 | " \n", 1131 | " \n", 1132 | " \n", 1133 | " \n", 1134 | " \n", 1135 | " \n", 1136 | " \n", 1137 | " \n", 1138 | " \n", 1139 | " \n", 1140 | " \n", 1141 | " \n", 1142 | " \n", 1143 | " \n", 1144 | " \n", 1145 | " \n", 1146 | " \n", 1147 | " \n", 1148 | " \n", 1149 | "
Football_teamFootballermoney
0barcelonamessi30.0
1real_madridramos20.0
\n", 1150 | "
" 1151 | ], 1152 | "text/plain": [ 1153 | " Football_team Footballer money\n", 1154 | "0 barcelona messi 30.0\n", 1155 | "1 real_madrid ramos 20.0" 1156 | ] 1157 | }, 1158 | "execution_count": 61, 1159 | "metadata": {}, 1160 | "output_type": "execute_result" 1161 | } 1162 | ], 1163 | "source": [ 1164 | "data = {\"Football_team\":[\"barcelona\", \"real_madrid\"],\n", 1165 | " \"Footballer\":[\"messi\",\"ramos\"],\n", 1166 | " \"money\":[30.0,20.0]}\n", 1167 | "df = pd.DataFrame(data, columns=[\"Football_team\", \"Footballer\",\"money\" ])\n", 1168 | "df" 1169 | ] 1170 | }, 1171 | { 1172 | "cell_type": "code", 1173 | "execution_count": 68, 1174 | "metadata": {}, 1175 | "outputs": [ 1176 | { 1177 | "data": { 1178 | "text/html": [ 1179 | "
\n", 1180 | "\n", 1193 | "\n", 1194 | " \n", 1195 | " \n", 1196 | " \n", 1197 | " \n", 1198 | " \n", 1199 | " \n", 1200 | " \n", 1201 | " \n", 1202 | " \n", 1203 | " \n", 1204 | " \n", 1205 | " \n", 1206 | " \n", 1207 | " \n", 1208 | " \n", 1209 | " \n", 1210 | " \n", 1211 | " \n", 1212 | " \n", 1213 | " \n", 1214 | " \n", 1215 | " \n", 1216 | "
Football_teamFootballermoney
1real_madridramos20.0
0barcelonamessi30.0
\n", 1217 | "
" 1218 | ], 1219 | "text/plain": [ 1220 | " Football_team Footballer money\n", 1221 | "1 real_madrid ramos 20.0\n", 1222 | "0 barcelona messi 30.0" 1223 | ] 1224 | }, 1225 | "execution_count": 68, 1226 | "metadata": {}, 1227 | "output_type": "execute_result" 1228 | } 1229 | ], 1230 | "source": [ 1231 | "df = df.sort_values(by = \"money\")\n", 1232 | "df" 1233 | ] 1234 | }, 1235 | { 1236 | "cell_type": "code", 1237 | "execution_count": 69, 1238 | "metadata": {}, 1239 | "outputs": [ 1240 | { 1241 | "data": { 1242 | "text/html": [ 1243 | "
\n", 1244 | "\n", 1257 | "\n", 1258 | " \n", 1259 | " \n", 1260 | " \n", 1261 | " \n", 1262 | " \n", 1263 | " \n", 1264 | " \n", 1265 | " \n", 1266 | " \n", 1267 | " \n", 1268 | " \n", 1269 | " \n", 1270 | " \n", 1271 | " \n", 1272 | " \n", 1273 | " \n", 1274 | " \n", 1275 | " \n", 1276 | " \n", 1277 | " \n", 1278 | " \n", 1279 | " \n", 1280 | "
Football_teamFootballermoney
0barcelonamessi30.0
1real_madridramos20.0
\n", 1281 | "
" 1282 | ], 1283 | "text/plain": [ 1284 | " Football_team Footballer money\n", 1285 | "0 barcelona messi 30.0\n", 1286 | "1 real_madrid ramos 20.0" 1287 | ] 1288 | }, 1289 | "execution_count": 69, 1290 | "metadata": {}, 1291 | "output_type": "execute_result" 1292 | } 1293 | ], 1294 | "source": [ 1295 | "df = df.sort_index()\n", 1296 | "df" 1297 | ] 1298 | }, 1299 | { 1300 | "cell_type": "code", 1301 | "execution_count": 71, 1302 | "metadata": {}, 1303 | "outputs": [ 1304 | { 1305 | "data": { 1306 | "text/html": [ 1307 | "
\n", 1308 | "\n", 1321 | "\n", 1322 | " \n", 1323 | " \n", 1324 | " \n", 1325 | " \n", 1326 | " \n", 1327 | " \n", 1328 | " \n", 1329 | " \n", 1330 | " \n", 1331 | " \n", 1332 | " \n", 1333 | " \n", 1334 | " \n", 1335 | " \n", 1336 | " \n", 1337 | " \n", 1338 | " \n", 1339 | " \n", 1340 | " \n", 1341 | " \n", 1342 | " \n", 1343 | " \n", 1344 | "
Football_teamFootballermoney
01.01.02.0
12.02.01.0
\n", 1345 | "
" 1346 | ], 1347 | "text/plain": [ 1348 | " Football_team Footballer money\n", 1349 | "0 1.0 1.0 2.0\n", 1350 | "1 2.0 2.0 1.0" 1351 | ] 1352 | }, 1353 | "execution_count": 71, 1354 | "metadata": {}, 1355 | "output_type": "execute_result" 1356 | } 1357 | ], 1358 | "source": [ 1359 | "df.rank()" 1360 | ] 1361 | }, 1362 | { 1363 | "cell_type": "markdown", 1364 | "metadata": {}, 1365 | "source": [ 1366 | "\n", 1367 | "## Retrieving Series/DataFrame Information\n", 1368 | "![Title](7.png)" 1369 | ] 1370 | }, 1371 | { 1372 | "cell_type": "code", 1373 | "execution_count": 72, 1374 | "metadata": {}, 1375 | "outputs": [ 1376 | { 1377 | "data": { 1378 | "text/html": [ 1379 | "
\n", 1380 | "\n", 1393 | "\n", 1394 | " \n", 1395 | " \n", 1396 | " \n", 1397 | " \n", 1398 | " \n", 1399 | " \n", 1400 | " \n", 1401 | " \n", 1402 | " \n", 1403 | " \n", 1404 | " \n", 1405 | " \n", 1406 | " \n", 1407 | " \n", 1408 | " \n", 1409 | " \n", 1410 | " \n", 1411 | " \n", 1412 | " \n", 1413 | " \n", 1414 | " \n", 1415 | " \n", 1416 | "
Football_teamFootballermoney
0barcelonamessi30.0
1real_madridramos20.0
\n", 1417 | "
" 1418 | ], 1419 | "text/plain": [ 1420 | " Football_team Footballer money\n", 1421 | "0 barcelona messi 30.0\n", 1422 | "1 real_madrid ramos 20.0" 1423 | ] 1424 | }, 1425 | "execution_count": 72, 1426 | "metadata": {}, 1427 | "output_type": "execute_result" 1428 | } 1429 | ], 1430 | "source": [ 1431 | "df" 1432 | ] 1433 | }, 1434 | { 1435 | "cell_type": "code", 1436 | "execution_count": 73, 1437 | "metadata": {}, 1438 | "outputs": [ 1439 | { 1440 | "data": { 1441 | "text/plain": [ 1442 | "(2, 3)" 1443 | ] 1444 | }, 1445 | "execution_count": 73, 1446 | "metadata": {}, 1447 | "output_type": "execute_result" 1448 | } 1449 | ], 1450 | "source": [ 1451 | "df.shape" 1452 | ] 1453 | }, 1454 | { 1455 | "cell_type": "code", 1456 | "execution_count": 74, 1457 | "metadata": {}, 1458 | "outputs": [ 1459 | { 1460 | "data": { 1461 | "text/plain": [ 1462 | "Int64Index([0, 1], dtype='int64')" 1463 | ] 1464 | }, 1465 | "execution_count": 74, 1466 | "metadata": {}, 1467 | "output_type": "execute_result" 1468 | } 1469 | ], 1470 | "source": [ 1471 | "df.index" 1472 | ] 1473 | }, 1474 | { 1475 | "cell_type": "code", 1476 | "execution_count": 75, 1477 | "metadata": {}, 1478 | "outputs": [ 1479 | { 1480 | "data": { 1481 | "text/plain": [ 1482 | "Index(['Football_team', 'Footballer', 'money'], dtype='object')" 1483 | ] 1484 | }, 1485 | "execution_count": 75, 1486 | "metadata": {}, 1487 | "output_type": "execute_result" 1488 | } 1489 | ], 1490 | "source": [ 1491 | "df.columns" 1492 | ] 1493 | }, 1494 | { 1495 | "cell_type": "code", 1496 | "execution_count": 76, 1497 | "metadata": {}, 1498 | "outputs": [ 1499 | { 1500 | "name": "stdout", 1501 | "output_type": "stream", 1502 | "text": [ 1503 | "\n", 1504 | "Int64Index: 2 entries, 0 to 1\n", 1505 | "Data columns (total 3 columns):\n", 1506 | "Football_team 2 non-null object\n", 1507 | "Footballer 2 non-null object\n", 1508 | "money 2 non-null float64\n", 1509 | "dtypes: float64(1), object(2)\n", 1510 | "memory usage: 64.0+ bytes\n" 1511 | ] 1512 | } 1513 | ], 1514 | "source": [ 1515 | "df.info()" 1516 | ] 1517 | }, 1518 | { 1519 | "cell_type": "code", 1520 | "execution_count": 78, 1521 | "metadata": {}, 1522 | "outputs": [ 1523 | { 1524 | "data": { 1525 | "text/plain": [ 1526 | "Football_team 2\n", 1527 | "Footballer 2\n", 1528 | "money 2\n", 1529 | "dtype: int64" 1530 | ] 1531 | }, 1532 | "execution_count": 78, 1533 | "metadata": {}, 1534 | "output_type": "execute_result" 1535 | } 1536 | ], 1537 | "source": [ 1538 | "df.count() # nan" 1539 | ] 1540 | }, 1541 | { 1542 | "cell_type": "code", 1543 | "execution_count": 80, 1544 | "metadata": {}, 1545 | "outputs": [ 1546 | { 1547 | "data": { 1548 | "text/html": [ 1549 | "
\n", 1550 | "\n", 1563 | "\n", 1564 | " \n", 1565 | " \n", 1566 | " \n", 1567 | " \n", 1568 | " \n", 1569 | " \n", 1570 | " \n", 1571 | " \n", 1572 | " \n", 1573 | " \n", 1574 | " \n", 1575 | " \n", 1576 | " \n", 1577 | " \n", 1578 | " \n", 1579 | " \n", 1580 | " \n", 1581 | " \n", 1582 | " \n", 1583 | " \n", 1584 | " \n", 1585 | " \n", 1586 | "
Football_teamFootballermoney
0barcelonamessi30.0
1real_madridramos20.0
\n", 1587 | "
" 1588 | ], 1589 | "text/plain": [ 1590 | " Football_team Footballer money\n", 1591 | "0 barcelona messi 30.0\n", 1592 | "1 real_madrid ramos 20.0" 1593 | ] 1594 | }, 1595 | "execution_count": 80, 1596 | "metadata": {}, 1597 | "output_type": "execute_result" 1598 | } 1599 | ], 1600 | "source": [ 1601 | "df" 1602 | ] 1603 | }, 1604 | { 1605 | "cell_type": "code", 1606 | "execution_count": 79, 1607 | "metadata": {}, 1608 | "outputs": [ 1609 | { 1610 | "data": { 1611 | "text/plain": [ 1612 | "Football_team barcelonareal_madrid\n", 1613 | "Footballer messiramos\n", 1614 | "money 50\n", 1615 | "dtype: object" 1616 | ] 1617 | }, 1618 | "execution_count": 79, 1619 | "metadata": {}, 1620 | "output_type": "execute_result" 1621 | } 1622 | ], 1623 | "source": [ 1624 | "df.sum()" 1625 | ] 1626 | }, 1627 | { 1628 | "cell_type": "code", 1629 | "execution_count": 82, 1630 | "metadata": {}, 1631 | "outputs": [ 1632 | { 1633 | "data": { 1634 | "text/plain": [ 1635 | "Football_team real_madrid\n", 1636 | "Footballer ramos\n", 1637 | "money 30\n", 1638 | "dtype: object" 1639 | ] 1640 | }, 1641 | "execution_count": 82, 1642 | "metadata": {}, 1643 | "output_type": "execute_result" 1644 | } 1645 | ], 1646 | "source": [ 1647 | "df.max()" 1648 | ] 1649 | }, 1650 | { 1651 | "cell_type": "code", 1652 | "execution_count": 89, 1653 | "metadata": {}, 1654 | "outputs": [ 1655 | { 1656 | "data": { 1657 | "text/plain": [ 1658 | "1" 1659 | ] 1660 | }, 1661 | "execution_count": 89, 1662 | "metadata": {}, 1663 | "output_type": "execute_result" 1664 | } 1665 | ], 1666 | "source": [ 1667 | "df.index.argmax()" 1668 | ] 1669 | }, 1670 | { 1671 | "cell_type": "code", 1672 | "execution_count": 90, 1673 | "metadata": {}, 1674 | "outputs": [ 1675 | { 1676 | "data": { 1677 | "text/html": [ 1678 | "
\n", 1679 | "\n", 1692 | "\n", 1693 | " \n", 1694 | " \n", 1695 | " \n", 1696 | " \n", 1697 | " \n", 1698 | " \n", 1699 | " \n", 1700 | " \n", 1701 | " \n", 1702 | " \n", 1703 | " \n", 1704 | " \n", 1705 | " \n", 1706 | " \n", 1707 | " \n", 1708 | " \n", 1709 | " \n", 1710 | " \n", 1711 | " \n", 1712 | " \n", 1713 | " \n", 1714 | " \n", 1715 | " \n", 1716 | " \n", 1717 | " \n", 1718 | " \n", 1719 | " \n", 1720 | " \n", 1721 | " \n", 1722 | " \n", 1723 | " \n", 1724 | " \n", 1725 | " \n", 1726 | " \n", 1727 | " \n", 1728 | " \n", 1729 | " \n", 1730 | " \n", 1731 | " \n", 1732 | " \n", 1733 | "
money
count2.000000
mean25.000000
std7.071068
min20.000000
25%22.500000
50%25.000000
75%27.500000
max30.000000
\n", 1734 | "
" 1735 | ], 1736 | "text/plain": [ 1737 | " money\n", 1738 | "count 2.000000\n", 1739 | "mean 25.000000\n", 1740 | "std 7.071068\n", 1741 | "min 20.000000\n", 1742 | "25% 22.500000\n", 1743 | "50% 25.000000\n", 1744 | "75% 27.500000\n", 1745 | "max 30.000000" 1746 | ] 1747 | }, 1748 | "execution_count": 90, 1749 | "metadata": {}, 1750 | "output_type": "execute_result" 1751 | } 1752 | ], 1753 | "source": [ 1754 | "df.describe()" 1755 | ] 1756 | }, 1757 | { 1758 | "cell_type": "code", 1759 | "execution_count": 92, 1760 | "metadata": {}, 1761 | "outputs": [ 1762 | { 1763 | "data": { 1764 | "text/plain": [ 1765 | "money 25.0\n", 1766 | "dtype: float64" 1767 | ] 1768 | }, 1769 | "execution_count": 92, 1770 | "metadata": {}, 1771 | "output_type": "execute_result" 1772 | } 1773 | ], 1774 | "source": [ 1775 | "df.mean()" 1776 | ] 1777 | }, 1778 | { 1779 | "cell_type": "code", 1780 | "execution_count": 93, 1781 | "metadata": {}, 1782 | "outputs": [ 1783 | { 1784 | "data": { 1785 | "text/plain": [ 1786 | "money 25.0\n", 1787 | "dtype: float64" 1788 | ] 1789 | }, 1790 | "execution_count": 93, 1791 | "metadata": {}, 1792 | "output_type": "execute_result" 1793 | } 1794 | ], 1795 | "source": [ 1796 | "df.median()" 1797 | ] 1798 | }, 1799 | { 1800 | "cell_type": "markdown", 1801 | "metadata": {}, 1802 | "source": [ 1803 | "\n", 1804 | "## Applying Functions\n", 1805 | "![Title](8.png)" 1806 | ] 1807 | }, 1808 | { 1809 | "cell_type": "code", 1810 | "execution_count": 94, 1811 | "metadata": {}, 1812 | "outputs": [ 1813 | { 1814 | "data": { 1815 | "text/html": [ 1816 | "
\n", 1817 | "\n", 1830 | "\n", 1831 | " \n", 1832 | " \n", 1833 | " \n", 1834 | " \n", 1835 | " \n", 1836 | " \n", 1837 | " \n", 1838 | " \n", 1839 | " \n", 1840 | " \n", 1841 | " \n", 1842 | " \n", 1843 | " \n", 1844 | " \n", 1845 | " \n", 1846 | " \n", 1847 | " \n", 1848 | " \n", 1849 | " \n", 1850 | " \n", 1851 | " \n", 1852 | " \n", 1853 | "
Football_teamFootballermoney
0barcelonamessi30.0
1real_madridramos20.0
\n", 1854 | "
" 1855 | ], 1856 | "text/plain": [ 1857 | " Football_team Footballer money\n", 1858 | "0 barcelona messi 30.0\n", 1859 | "1 real_madrid ramos 20.0" 1860 | ] 1861 | }, 1862 | "execution_count": 94, 1863 | "metadata": {}, 1864 | "output_type": "execute_result" 1865 | } 1866 | ], 1867 | "source": [ 1868 | "df" 1869 | ] 1870 | }, 1871 | { 1872 | "cell_type": "code", 1873 | "execution_count": 95, 1874 | "metadata": {}, 1875 | "outputs": [ 1876 | { 1877 | "data": { 1878 | "text/html": [ 1879 | "
\n", 1880 | "\n", 1893 | "\n", 1894 | " \n", 1895 | " \n", 1896 | " \n", 1897 | " \n", 1898 | " \n", 1899 | " \n", 1900 | " \n", 1901 | " \n", 1902 | " \n", 1903 | " \n", 1904 | " \n", 1905 | " \n", 1906 | " \n", 1907 | " \n", 1908 | " \n", 1909 | " \n", 1910 | " \n", 1911 | " \n", 1912 | " \n", 1913 | " \n", 1914 | " \n", 1915 | " \n", 1916 | "
Football_teamFootballermoney
0barcelonabarcelonamessimessi60.0
1real_madridreal_madridramosramos40.0
\n", 1917 | "
" 1918 | ], 1919 | "text/plain": [ 1920 | " Football_team Footballer money\n", 1921 | "0 barcelonabarcelona messimessi 60.0\n", 1922 | "1 real_madridreal_madrid ramosramos 40.0" 1923 | ] 1924 | }, 1925 | "execution_count": 95, 1926 | "metadata": {}, 1927 | "output_type": "execute_result" 1928 | } 1929 | ], 1930 | "source": [ 1931 | "f = lambda x: x*2\n", 1932 | "df.apply(f)" 1933 | ] 1934 | }, 1935 | { 1936 | "cell_type": "code", 1937 | "execution_count": 97, 1938 | "metadata": {}, 1939 | "outputs": [ 1940 | { 1941 | "data": { 1942 | "text/html": [ 1943 | "
\n", 1944 | "\n", 1957 | "\n", 1958 | " \n", 1959 | " \n", 1960 | " \n", 1961 | " \n", 1962 | " \n", 1963 | " \n", 1964 | " \n", 1965 | " \n", 1966 | " \n", 1967 | " \n", 1968 | " \n", 1969 | " \n", 1970 | " \n", 1971 | " \n", 1972 | " \n", 1973 | " \n", 1974 | " \n", 1975 | " \n", 1976 | " \n", 1977 | " \n", 1978 | " \n", 1979 | " \n", 1980 | "
Football_teamFootballermoney
0barcelonabarcelonamessimessi60.0
1real_madridreal_madridramosramos40.0
\n", 1981 | "
" 1982 | ], 1983 | "text/plain": [ 1984 | " Football_team Footballer money\n", 1985 | "0 barcelonabarcelona messimessi 60.0\n", 1986 | "1 real_madridreal_madrid ramosramos 40.0" 1987 | ] 1988 | }, 1989 | "execution_count": 97, 1990 | "metadata": {}, 1991 | "output_type": "execute_result" 1992 | } 1993 | ], 1994 | "source": [ 1995 | "df.applymap(f)" 1996 | ] 1997 | }, 1998 | { 1999 | "cell_type": "markdown", 2000 | "metadata": {}, 2001 | "source": [ 2002 | "\n", 2003 | "## Data Alignment\n", 2004 | "![Title](9.png)" 2005 | ] 2006 | }, 2007 | { 2008 | "cell_type": "code", 2009 | "execution_count": 124, 2010 | "metadata": {}, 2011 | "outputs": [ 2012 | { 2013 | "data": { 2014 | "text/plain": [ 2015 | "c1 10\n", 2016 | "c2 20\n", 2017 | "c3 30\n", 2018 | "dtype: int64" 2019 | ] 2020 | }, 2021 | "execution_count": 124, 2022 | "metadata": {}, 2023 | "output_type": "execute_result" 2024 | } 2025 | ], 2026 | "source": [ 2027 | "series = pd.Series([10,20,30], index = [\"c1\",\"c2\",\"c3\"])\n", 2028 | "series" 2029 | ] 2030 | }, 2031 | { 2032 | "cell_type": "code", 2033 | "execution_count": 125, 2034 | "metadata": {}, 2035 | "outputs": [ 2036 | { 2037 | "data": { 2038 | "text/plain": [ 2039 | "c1 1\n", 2040 | "c2 2\n", 2041 | "dtype: int64" 2042 | ] 2043 | }, 2044 | "execution_count": 125, 2045 | "metadata": {}, 2046 | "output_type": "execute_result" 2047 | } 2048 | ], 2049 | "source": [ 2050 | "s = pd.Series([1,2], index = [\"c1\",\"c2\"])\n", 2051 | "s\n" 2052 | ] 2053 | }, 2054 | { 2055 | "cell_type": "code", 2056 | "execution_count": 126, 2057 | "metadata": {}, 2058 | "outputs": [ 2059 | { 2060 | "data": { 2061 | "text/plain": [ 2062 | "c1 11.0\n", 2063 | "c2 22.0\n", 2064 | "c3 NaN\n", 2065 | "dtype: float64" 2066 | ] 2067 | }, 2068 | "execution_count": 126, 2069 | "metadata": {}, 2070 | "output_type": "execute_result" 2071 | } 2072 | ], 2073 | "source": [ 2074 | "series + s" 2075 | ] 2076 | }, 2077 | { 2078 | "cell_type": "code", 2079 | "execution_count": 128, 2080 | "metadata": {}, 2081 | "outputs": [ 2082 | { 2083 | "data": { 2084 | "text/plain": [ 2085 | "c1 11.0\n", 2086 | "c2 22.0\n", 2087 | "c3 30.0\n", 2088 | "dtype: float64" 2089 | ] 2090 | }, 2091 | "execution_count": 128, 2092 | "metadata": {}, 2093 | "output_type": "execute_result" 2094 | } 2095 | ], 2096 | "source": [ 2097 | "s.add(series,fill_value=0)" 2098 | ] 2099 | }, 2100 | { 2101 | "cell_type": "code", 2102 | "execution_count": null, 2103 | "metadata": {}, 2104 | "outputs": [], 2105 | "source": [] 2106 | } 2107 | ], 2108 | "metadata": { 2109 | "kernelspec": { 2110 | "display_name": "Python 3", 2111 | "language": "python", 2112 | "name": "python3" 2113 | }, 2114 | "language_info": { 2115 | "codemirror_mode": { 2116 | "name": "ipython", 2117 | "version": 3 2118 | }, 2119 | "file_extension": ".py", 2120 | "mimetype": "text/x-python", 2121 | "name": "python", 2122 | "nbconvert_exporter": "python", 2123 | "pygments_lexer": "ipython3", 2124 | "version": "3.7.1" 2125 | } 2126 | }, 2127 | "nbformat": 4, 2128 | "nbformat_minor": 2 2129 | } 2130 | -------------------------------------------------------------------------------- /3) Pandas/Pandas.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataiteam/Data-Science-Cheat-Sheet/2ee8d83062b676ceb055865c688d9c5ebf7e3deb/3) Pandas/Pandas.pdf -------------------------------------------------------------------------------- /3) Pandas/first.csv: -------------------------------------------------------------------------------- 1 | ,Football_team,Footballer,money 2 | 0,barcelona,messi,30.0 3 | 1,real_madrid,ramos,20.0 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Data-Science-Cheat-Sheet 2 | Youtube Data Science Cheat Sheet Course 3 | --------------------------------------------------------------------------------