├── .ipynb_checkpoints ├── Python-1-checkpoint.ipynb ├── ch02-checkpoint.ipynb └── module-checkpoint.ipynb ├── Python-1.ipynb ├── README.md ├── db.sqlite3 ├── model-recommender.joblib ├── module.ipynb ├── music-recommender.dot ├── music.csv ├── products ├── __init__.py ├── admin.py ├── apps.py ├── migrations │ └── __init__.py ├── models.py ├── tests.py └── views.py ├── pyshop ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-37.pyc │ ├── settings.cpython-37.pyc │ ├── urls.cpython-37.pyc │ └── wsgi.cpython-37.pyc ├── settings.py ├── urls.py └── wsgi.py ├── transaction2.xlsx ├── transactions.xlsx └── vgsales.csv /.ipynb_checkpoints/Python-1-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Python Basic\n", 8 | "\n" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 6, 14 | "metadata": { 15 | "scrolled": true 16 | }, 17 | "outputs": [ 18 | { 19 | "name": "stdout", 20 | "output_type": "stream", 21 | "text": [ 22 | "what is name ?mosh\n", 23 | "HI mosh\n" 24 | ] 25 | } 26 | ], 27 | "source": [ 28 | "name = input(\"what is name ?\")\n", 29 | "print('HI ' +name)" 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": 8, 35 | "metadata": {}, 36 | "outputs": [ 37 | { 38 | "name": "stdout", 39 | "output_type": "stream", 40 | "text": [ 41 | "what is your birthdate ? 2000\n", 42 | "19\n" 43 | ] 44 | } 45 | ], 46 | "source": [ 47 | "name = input('what is your birthyear ? ')\n", 48 | "year = 2019 -int(name);\n", 49 | "print(year)" 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "metadata": {}, 55 | "source": [ 56 | "# Type" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": 9, 62 | "metadata": {}, 63 | "outputs": [ 64 | { 65 | "name": "stdout", 66 | "output_type": "stream", 67 | "text": [ 68 | "\n" 69 | ] 70 | } 71 | ], 72 | "source": [ 73 | "#type \n", 74 | "\n", 75 | "print(type(name))" 76 | ] 77 | }, 78 | { 79 | "cell_type": "code", 80 | "execution_count": 18, 81 | "metadata": {}, 82 | "outputs": [ 83 | { 84 | "name": "stdout", 85 | "output_type": "stream", 86 | "text": [ 87 | "what is weight 45\n", 88 | "20.25\n" 89 | ] 90 | } 91 | ], 92 | "source": [ 93 | "weight = input(\"what is weight \")\n", 94 | "final = int(weight)*0.45\n", 95 | "print(final)" 96 | ] 97 | }, 98 | { 99 | "cell_type": "code", 100 | "execution_count": 26, 101 | "metadata": {}, 102 | "outputs": [ 103 | { 104 | "name": "stdout", 105 | "output_type": "stream", 106 | "text": [ 107 | "you're awesome\n", 108 | "im \"Hritik\"\n", 109 | "\n", 110 | " Hii buddy \n", 111 | "\n", 112 | " im Hritik \n", 113 | "\n", 114 | " you look awesome \n", 115 | "\n", 116 | " thank you,\n", 117 | " \n" 118 | ] 119 | } 120 | ], 121 | "source": [ 122 | "#if want to use this type statement -> year's then we have to use double quotes \"\"\n", 123 | "string = \"you're awesome\"\n", 124 | "print(string)\n", 125 | "\n", 126 | "# if want to assign \"important msg\" like this we have to use single quote ''\n", 127 | "str = 'im \"Hritik\"'\n", 128 | "print(str)\n", 129 | "\n", 130 | "# for multitline string ''' % ''' for sending mail \n", 131 | "\n", 132 | "mail = '''\n", 133 | " Hii buddy \n", 134 | "\n", 135 | " im Hritik \n", 136 | "\n", 137 | " you look awesome \n", 138 | "\n", 139 | " thank you,\n", 140 | " '''\n", 141 | "\n", 142 | "print(mail)\n" 143 | ] 144 | }, 145 | { 146 | "cell_type": "code", 147 | "execution_count": 30, 148 | "metadata": {}, 149 | "outputs": [ 150 | { 151 | "name": "stdout", 152 | "output_type": "stream", 153 | "text": [ 154 | "p\n", 155 | "r\n", 156 | "python beginners\n", 157 | "python beginners\n", 158 | "pytho\n", 159 | "pytho\n", 160 | "yt\n", 161 | "ython beginner\n" 162 | ] 163 | } 164 | ], 165 | "source": [ 166 | "course = 'python beginners'\n", 167 | "print(course[0])\n", 168 | "print(course[-2])\n", 169 | "print(course[0:])\n", 170 | "print(course[:])\n", 171 | "print(course[:5])\n", 172 | "print(course[0:5])\n", 173 | "print(course[1:3]) #exclude 3 only takes 1,2\n", 174 | "\n", 175 | "print(course[1:-1]) # exclude -1 " 176 | ] 177 | }, 178 | { 179 | "cell_type": "markdown", 180 | "metadata": {}, 181 | "source": [ 182 | "# Inbuilt - Function" 183 | ] 184 | }, 185 | { 186 | "cell_type": "code", 187 | "execution_count": 32, 188 | "metadata": {}, 189 | "outputs": [ 190 | { 191 | "name": "stdout", 192 | "output_type": "stream", 193 | "text": [ 194 | "9\n" 195 | ] 196 | } 197 | ], 198 | "source": [ 199 | "#length of string including space\n", 200 | "c = 'hii buddy'\n", 201 | "print(len(c))" 202 | ] 203 | }, 204 | { 205 | "cell_type": "code", 206 | "execution_count": 45, 207 | "metadata": {}, 208 | "outputs": [ 209 | { 210 | "name": "stdout", 211 | "output_type": "stream", 212 | "text": [ 213 | "python is very imp lang\n", 214 | "PYTHON IS VERY IMP LANG\n", 215 | "2\n", 216 | "2\n", 217 | "Python Is Very Imp Lang\n", 218 | "python are very imp lang\n" 219 | ] 220 | } 221 | ], 222 | "source": [ 223 | "#various function \n", 224 | "msg = 'python is very imp lang'\n", 225 | "print(msg.lower())\n", 226 | "print(msg.upper())\n", 227 | "print(msg.count('i'))\n", 228 | "print(msg.find('t'))\n", 229 | "print(msg.title())\n", 230 | "print(msg.replace('is','are'))" 231 | ] 232 | }, 233 | { 234 | "cell_type": "code", 235 | "execution_count": 46, 236 | "metadata": {}, 237 | "outputs": [ 238 | { 239 | "name": "stdout", 240 | "output_type": "stream", 241 | "text": [ 242 | "22\n" 243 | ] 244 | } 245 | ], 246 | "source": [ 247 | "#ordering \n", 248 | "# exp > (mul or div) > (add or sub)\n", 249 | "exp = 10 + 3*2**2\n", 250 | "print(exp)" 251 | ] 252 | }, 253 | { 254 | "cell_type": "markdown", 255 | "metadata": {}, 256 | "source": [ 257 | "# Math function" 258 | ] 259 | }, 260 | { 261 | "cell_type": "code", 262 | "execution_count": 49, 263 | "metadata": {}, 264 | "outputs": [ 265 | { 266 | "name": "stdout", 267 | "output_type": "stream", 268 | "text": [ 269 | "6\n", 270 | "8\n" 271 | ] 272 | } 273 | ], 274 | "source": [ 275 | "#Math function\n", 276 | "# 1) round\n", 277 | "x = 6.5\n", 278 | "y = 7.66\n", 279 | "print(round(x))\n", 280 | "print(round(y))" 281 | ] 282 | }, 283 | { 284 | "cell_type": "code", 285 | "execution_count": 51, 286 | "metadata": {}, 287 | "outputs": [ 288 | { 289 | "name": "stdout", 290 | "output_type": "stream", 291 | "text": [ 292 | "3.5\n" 293 | ] 294 | } 295 | ], 296 | "source": [ 297 | "# 2) abs -> return positive no.\n", 298 | "x = -3.5\n", 299 | "print(abs(x))" 300 | ] 301 | }, 302 | { 303 | "cell_type": "code", 304 | "execution_count": 61, 305 | "metadata": {}, 306 | "outputs": [ 307 | { 308 | "name": "stdout", 309 | "output_type": "stream", 310 | "text": [ 311 | "3\n", 312 | "2\n" 313 | ] 314 | } 315 | ], 316 | "source": [ 317 | "# 3) Mathametical function\n", 318 | "import math\n", 319 | "pi = 3.142\n", 320 | "math.cos((60*pi)/180)\n", 321 | "\n", 322 | "# ceil and floor\n", 323 | "print(math.ceil(2.9))\n", 324 | "print(math.floor(2.9))\n", 325 | "\n", 326 | "#thier are many more maths module" 327 | ] 328 | }, 329 | { 330 | "cell_type": "markdown", 331 | "metadata": {}, 332 | "source": [ 333 | "# If - Statement" 334 | ] 335 | }, 336 | { 337 | "cell_type": "code", 338 | "execution_count": 81, 339 | "metadata": {}, 340 | "outputs": [ 341 | { 342 | "name": "stdout", 343 | "output_type": "stream", 344 | "text": [ 345 | "nothing\n", 346 | "SUM OF X AND Y : 15\n" 347 | ] 348 | } 349 | ], 350 | "source": [ 351 | "#if statement\n", 352 | "\n", 353 | "x = 5\n", 354 | "y = 10\n", 355 | "\n", 356 | "if (x>y):\n", 357 | " print(\"truee\")\n", 358 | "elif (x==y):\n", 359 | " print(\"falsee\")\n", 360 | "else:\n", 361 | " print(\"nothing\")\n", 362 | " \n", 363 | "print(f\"SUM OF X AND Y : {x+y}\")\n" 364 | ] 365 | }, 366 | { 367 | "cell_type": "markdown", 368 | "metadata": {}, 369 | "source": [ 370 | "# Format" 371 | ] 372 | }, 373 | { 374 | "cell_type": "code", 375 | "execution_count": null, 376 | "metadata": {}, 377 | "outputs": [], 378 | "source": [ 379 | "x = \"Hii\"\n", 380 | "y = 'Hritik {}'\n", 381 | "z = 'Jaiswal'\n", 382 | "print(f\"sum of string is x + y : {x+y}\")\n", 383 | "print(y.format(z))" 384 | ] 385 | }, 386 | { 387 | "cell_type": "code", 388 | "execution_count": 111, 389 | "metadata": {}, 390 | "outputs": [ 391 | { 392 | "name": "stdout", 393 | "output_type": "stream", 394 | "text": [ 395 | "True\n" 396 | ] 397 | } 398 | ], 399 | "source": [ 400 | "# we can use 'and' & 'or' in if statement\n", 401 | "a=2 \n", 402 | "b=3\n", 403 | "c=4\n", 404 | "if (ab):\n", 405 | " print('True')\n", 406 | "elif (a==b) or (c>a):\n", 407 | " print('Truee')\n", 408 | "elif (b>a) and not(b>c):\n", 409 | " print('Trueee')\n", 410 | "else:\n", 411 | " print('false')\n", 412 | " " 413 | ] 414 | }, 415 | { 416 | "cell_type": "code", 417 | "execution_count": 113, 418 | "metadata": {}, 419 | "outputs": [ 420 | { 421 | "name": "stdout", 422 | "output_type": "stream", 423 | "text": [ 424 | "Weight :45\n", 425 | "(L)bs or (K)gv\n", 426 | "100.0\n" 427 | ] 428 | } 429 | ], 430 | "source": [ 431 | "#Exercise\n", 432 | "\n", 433 | "weight = int(input('Weight :'))\n", 434 | "unit = input('(L)bs or (K)g')\n", 435 | "if unit.lower()=='l' or unit.upper()=='L':\n", 436 | " c = weight*0.45;\n", 437 | "else:\n", 438 | " c = weight/0.45;\n", 439 | "print(c)" 440 | ] 441 | }, 442 | { 443 | "cell_type": "markdown", 444 | "metadata": {}, 445 | "source": [ 446 | "# While loop" 447 | ] 448 | }, 449 | { 450 | "cell_type": "code", 451 | "execution_count": 116, 452 | "metadata": {}, 453 | "outputs": [ 454 | { 455 | "name": "stdout", 456 | "output_type": "stream", 457 | "text": [ 458 | "*\n", 459 | "**\n", 460 | "***\n", 461 | "****\n" 462 | ] 463 | } 464 | ], 465 | "source": [ 466 | "#while\n", 467 | "\n", 468 | "i=1\n", 469 | "while (i<5):\n", 470 | " print('*'*i)\n", 471 | " i+=1\n", 472 | " " 473 | ] 474 | }, 475 | { 476 | "cell_type": "markdown", 477 | "metadata": {}, 478 | "source": [ 479 | "# for loop" 480 | ] 481 | }, 482 | { 483 | "cell_type": "code", 484 | "execution_count": 117, 485 | "metadata": {}, 486 | "outputs": [ 487 | { 488 | "name": "stdout", 489 | "output_type": "stream", 490 | "text": [ 491 | "T\n", 492 | "e\n", 493 | "a\n", 494 | "c\n", 495 | "h\n", 496 | "e\n", 497 | "r\n" 498 | ] 499 | } 500 | ], 501 | "source": [ 502 | "#for loop\n", 503 | "for item in 'Teacher':\n", 504 | " print(item)" 505 | ] 506 | }, 507 | { 508 | "cell_type": "code", 509 | "execution_count": 128, 510 | "metadata": {}, 511 | "outputs": [ 512 | { 513 | "name": "stdout", 514 | "output_type": "stream", 515 | "text": [ 516 | "hii\n", 517 | "buddy \n", 518 | "whats\n", 519 | "up\n", 520 | "-----------------\n", 521 | "0\n", 522 | "1\n", 523 | "2\n", 524 | "3\n", 525 | "-----------------\n", 526 | "2\n", 527 | "3\n", 528 | "4\n", 529 | "5\n", 530 | "6\n", 531 | "7\n", 532 | "-----------------\n", 533 | "2\n", 534 | "5\n", 535 | "-----------------\n", 536 | "5\n", 537 | "6\n", 538 | "7\n", 539 | "8\n" 540 | ] 541 | } 542 | ], 543 | "source": [ 544 | "for i in ['hii','buddy ','whats','up']:\n", 545 | " print(i)\n", 546 | "print('-----------------')\n", 547 | "for i in range(4):\n", 548 | " print(i)\n", 549 | "print('-----------------')\n", 550 | "for i in range(2,8):\n", 551 | " print(i)\n", 552 | "print('-----------------')\n", 553 | "for i in range(2,8,3):\n", 554 | " print(i)\n", 555 | "print('-----------------')\n", 556 | "for i in [5,6,7,8]:\n", 557 | " print(i)" 558 | ] 559 | }, 560 | { 561 | "cell_type": "code", 562 | "execution_count": 132, 563 | "metadata": {}, 564 | "outputs": [ 565 | { 566 | "name": "stdout", 567 | "output_type": "stream", 568 | "text": [ 569 | "14\n", 570 | "-----------\n", 571 | "14\n" 572 | ] 573 | } 574 | ], 575 | "source": [ 576 | "r = [2,3,4,5]\n", 577 | "total = 0\n", 578 | "for i in r:\n", 579 | " total+=i\n", 580 | "print(total)\n", 581 | "print('-----------')\n", 582 | "r = [2,3,4,5]\n", 583 | "e = sum(r)\n", 584 | "print(e)" 585 | ] 586 | }, 587 | { 588 | "cell_type": "code", 589 | "execution_count": 134, 590 | "metadata": {}, 591 | "outputs": [ 592 | { 593 | "name": "stdout", 594 | "output_type": "stream", 595 | "text": [ 596 | "(0,0)\n", 597 | "(0,1)\n", 598 | "(0,2)\n", 599 | "(1,0)\n", 600 | "(1,1)\n", 601 | "(1,2)\n", 602 | "(2,0)\n", 603 | "(2,1)\n", 604 | "(2,2)\n", 605 | "(3,0)\n", 606 | "(3,1)\n", 607 | "(3,2)\n" 608 | ] 609 | } 610 | ], 611 | "source": [ 612 | "for i in range(4):\n", 613 | " for j in range(3):\n", 614 | " print(f'({i},{j})')" 615 | ] 616 | }, 617 | { 618 | "cell_type": "code", 619 | "execution_count": 137, 620 | "metadata": {}, 621 | "outputs": [ 622 | { 623 | "name": "stdout", 624 | "output_type": "stream", 625 | "text": [ 626 | "$\n", 627 | "$$\n", 628 | "$$$\n", 629 | "$$$$\n", 630 | "$$$$$\n" 631 | ] 632 | } 633 | ], 634 | "source": [ 635 | "#array\n", 636 | "num = [1,2,3,4,5]\n", 637 | "for i in num:\n", 638 | " print('$'*i)" 639 | ] 640 | }, 641 | { 642 | "cell_type": "code", 643 | "execution_count": 143, 644 | "metadata": {}, 645 | "outputs": [ 646 | { 647 | "name": "stdout", 648 | "output_type": "stream", 649 | "text": [ 650 | "ab \n", 651 | "ae\n" 652 | ] 653 | } 654 | ], 655 | "source": [ 656 | "name = ['ab ','ac','ad','ae']\n", 657 | "print(name[0])\n", 658 | "print(name[-1])" 659 | ] 660 | }, 661 | { 662 | "cell_type": "markdown", 663 | "metadata": {}, 664 | "source": [ 665 | "# List" 666 | ] 667 | }, 668 | { 669 | "cell_type": "code", 670 | "execution_count": 146, 671 | "metadata": {}, 672 | "outputs": [ 673 | { 674 | "name": "stdout", 675 | "output_type": "stream", 676 | "text": [ 677 | "[1, 2, 3]\n", 678 | "[4, 5, 6]\n", 679 | "[7, 8, 9]\n", 680 | "-----print individual item-----\n", 681 | "1\n", 682 | "2\n", 683 | "3\n", 684 | "4\n", 685 | "5\n", 686 | "6\n", 687 | "7\n", 688 | "8\n", 689 | "9\n" 690 | ] 691 | } 692 | ], 693 | "source": [ 694 | "#2D-List \n", 695 | "matrix = [[1,2,3],[4,5,6],[7,8,9]]\n", 696 | "for i in matrix:\n", 697 | " print(i)\n", 698 | "print('-----print individual item-----')\n", 699 | "for i in matrix:\n", 700 | " for j in i:\n", 701 | " print(j)" 702 | ] 703 | }, 704 | { 705 | "cell_type": "markdown", 706 | "metadata": {}, 707 | "source": [ 708 | "# Inbuilt - Function" 709 | ] 710 | }, 711 | { 712 | "cell_type": "code", 713 | "execution_count": 158, 714 | "metadata": {}, 715 | "outputs": [ 716 | { 717 | "name": "stdout", 718 | "output_type": "stream", 719 | "text": [ 720 | "-----Append---------\n", 721 | "[2, 3, 4, 6, 9]\n", 722 | "-----Insert---------\n", 723 | "[2, 3, 8, 4, 6, 9]\n", 724 | "-----Remove---------\n", 725 | "[2, 3, 4, 6, 9]\n", 726 | "-----pop---------\n", 727 | "[2, 3, 4, 6]\n", 728 | "-----clear---------\n", 729 | "[]\n" 730 | ] 731 | } 732 | ], 733 | "source": [ 734 | "#working with function \n", 735 | "# 1.append 2.insert 3.remove 4.pop 5.clear\n", 736 | "number = [2,3,4,6]\n", 737 | "print('-----Append---------')\n", 738 | "number.append(9)\n", 739 | "print(number)\n", 740 | "print('-----Insert---------')\n", 741 | "number.insert(2,8)\n", 742 | "print(number)\n", 743 | "print('-----Remove---------')\n", 744 | "number.remove(8)\n", 745 | "print(number)\n", 746 | "print('-----pop---------')\n", 747 | "number.pop()\n", 748 | "print(number)\n", 749 | "print('-----clear---------')\n", 750 | "number.clear()\n", 751 | "print(number)" 752 | ] 753 | }, 754 | { 755 | "cell_type": "code", 756 | "execution_count": 162, 757 | "metadata": {}, 758 | "outputs": [ 759 | { 760 | "name": "stdout", 761 | "output_type": "stream", 762 | "text": [ 763 | "2\n", 764 | "2\n" 765 | ] 766 | } 767 | ], 768 | "source": [ 769 | "#index \n", 770 | "list_item = [2,4,6,7,2,4]\n", 771 | "print(list_item.index(6))\n", 772 | "print(list_item.count(2))\n" 773 | ] 774 | }, 775 | { 776 | "cell_type": "code", 777 | "execution_count": 164, 778 | "metadata": {}, 779 | "outputs": [ 780 | { 781 | "name": "stdout", 782 | "output_type": "stream", 783 | "text": [ 784 | "[1, 2, 3, 5, 8]\n", 785 | "[8, 5, 3, 2, 1]\n" 786 | ] 787 | } 788 | ], 789 | "source": [ 790 | "# 1.sort 2.reverse \n", 791 | "item = [3,5,2,8,1]\n", 792 | "item.sort()\n", 793 | "print(item)\n", 794 | "item.reverse()\n", 795 | "print(item)" 796 | ] 797 | }, 798 | { 799 | "cell_type": "code", 800 | "execution_count": 4, 801 | "metadata": {}, 802 | "outputs": [ 803 | { 804 | "name": "stdout", 805 | "output_type": "stream", 806 | "text": [ 807 | "[2, 3, 4, 5]\n" 808 | ] 809 | } 810 | ], 811 | "source": [ 812 | "#list will update if we changing list item before calling copy function ,\n", 813 | "# but list will not be change when u are appending and deleting after copy function\n", 814 | "a = [2,3,4,5]\n", 815 | "b = a.copy()\n", 816 | "a.append(10)\n", 817 | "print(b)" 818 | ] 819 | }, 820 | { 821 | "cell_type": "code", 822 | "execution_count": 5, 823 | "metadata": {}, 824 | "outputs": [ 825 | { 826 | "name": "stdout", 827 | "output_type": "stream", 828 | "text": [ 829 | "[2, 3, 4, 5]\n" 830 | ] 831 | } 832 | ], 833 | "source": [ 834 | "#excercise -> remove a duplicate no. from the list\n", 835 | "numbers = [2,3,4,4,3,5]\n", 836 | "unique = []\n", 837 | "\n", 838 | "for i in numbers:\n", 839 | " if i not in unique:\n", 840 | " unique.append(i)\n", 841 | " \n", 842 | "print(unique)" 843 | ] 844 | }, 845 | { 846 | "cell_type": "markdown", 847 | "metadata": {}, 848 | "source": [ 849 | "# tuple" 850 | ] 851 | }, 852 | { 853 | "cell_type": "code", 854 | "execution_count": 11, 855 | "metadata": {}, 856 | "outputs": [ 857 | { 858 | "name": "stdout", 859 | "output_type": "stream", 860 | "text": [ 861 | "1\n" 862 | ] 863 | } 864 | ], 865 | "source": [ 866 | "#tuple -> we can not append , remove , pop , insert , u can not modify your list .\n", 867 | "#only thing u can do -> count , index a item in list\n", 868 | "number = (1,2,3)\n", 869 | "print(number[0])\n" 870 | ] 871 | }, 872 | { 873 | "cell_type": "markdown", 874 | "metadata": {}, 875 | "source": [ 876 | "# Unpacking" 877 | ] 878 | }, 879 | { 880 | "cell_type": "code", 881 | "execution_count": 13, 882 | "metadata": {}, 883 | "outputs": [ 884 | { 885 | "name": "stdout", 886 | "output_type": "stream", 887 | "text": [ 888 | "2\n" 889 | ] 890 | } 891 | ], 892 | "source": [ 893 | "#unpacking\n", 894 | "coordinates = [2,3,4]\n", 895 | "# x = coordinates[0]\n", 896 | "# y = coordinates[1]\n", 897 | "# z = coordinates[2]\n", 898 | "# instead of writing like this we can write \n", 899 | "x,y,z = coordinates #unpacking -> work with both list and tuple\n", 900 | "print(x)" 901 | ] 902 | }, 903 | { 904 | "cell_type": "markdown", 905 | "metadata": {}, 906 | "source": [ 907 | "# Dictionaries" 908 | ] 909 | }, 910 | { 911 | "cell_type": "code", 912 | "execution_count": 23, 913 | "metadata": {}, 914 | "outputs": [ 915 | { 916 | "name": "stdout", 917 | "output_type": "stream", 918 | "text": [ 919 | "Hritik Jaiswal\n", 920 | "may 31 2000\n", 921 | "None\n", 922 | "HritiK Dinesh Jaiswal\n" 923 | ] 924 | } 925 | ], 926 | "source": [ 927 | "#Dictionaries -> contain key - value pairs \n", 928 | "\n", 929 | "people = {\n", 930 | " \"name\" :\"Hritik Jaiswal\",\n", 931 | " \"age\" : 19,\n", 932 | " \"is_male\" : True\n", 933 | "}\n", 934 | "print(people[\"name\"])\n", 935 | "\n", 936 | "# u can not write like -> print(people[\"Name\"])\n", 937 | "# we can use GET method to take key-value pair if its not present and display key value pair \n", 938 | "print(people.get(\"birth\",\"may 31 2000\"))\n", 939 | "print(people.get(\"gender\")) #None -> is the object that represent absence of the value\n", 940 | "\n", 941 | "people[\"name\"] = \"HritiK Dinesh Jaiswal\" # modify name\n", 942 | "print(people.get(\"name\"))" 943 | ] 944 | }, 945 | { 946 | "cell_type": "code", 947 | "execution_count": 41, 948 | "metadata": {}, 949 | "outputs": [ 950 | { 951 | "name": "stdout", 952 | "output_type": "stream", 953 | "text": [ 954 | "phone : 105\n", 955 | "1\n", 956 | "0\n", 957 | "5\n", 958 | "One zero Five \n" 959 | ] 960 | } 961 | ], 962 | "source": [ 963 | "#excersice -> inuput 1234 display output : one two three four\n", 964 | "phone = input(\"phone : \")\n", 965 | "\n", 966 | "dict = {\n", 967 | " \"1\" :\"One\",\n", 968 | " \"2\":\"Two\",\n", 969 | " \"3\" :\"Three\",\n", 970 | " \"4\" :\"Four\",\n", 971 | " \"5\" :\"Five\",\n", 972 | " \"6\" :\"Six\",\n", 973 | " \"7\" :\"Seven\",\n", 974 | " \"8\" :\"Eight\",\n", 975 | " \"9\" :\"Nine\",\n", 976 | " \"0\" :\"zero\",\n", 977 | "}\n", 978 | "output = \"\" \n", 979 | "for i in phone:\n", 980 | " \n", 981 | " output += (dict.get(i,\"?\")) + \" \" \n", 982 | " print(i)\n", 983 | "print(output) " 984 | ] 985 | }, 986 | { 987 | "cell_type": "code", 988 | "execution_count": 12, 989 | "metadata": {}, 990 | "outputs": [ 991 | { 992 | "name": "stdout", 993 | "output_type": "stream", 994 | "text": [ 995 | "Enter the word : one seven two\n", 996 | "['one', 'seven', 'two']\n", 997 | "1\n", 998 | "7\n", 999 | "2\n" 1000 | ] 1001 | } 1002 | ], 1003 | "source": [ 1004 | "#excerisce -> opposite \n", 1005 | "words = [\"one\", \"two\",\"three\",\"four\",\"five\",\"six\", \"seven\",\"eight\",\"nine\",\"zero\"]\n", 1006 | "\n", 1007 | "word = input(\"Enter the word : \")\n", 1008 | "mapping = {\n", 1009 | " \"one\":\"1\", \n", 1010 | " \"two\":\"2\",\n", 1011 | " \"three\":\"3\",\n", 1012 | " \"four\":\"4\",\n", 1013 | " \"five\":\"5\",\n", 1014 | " \"six\":\"6\", \n", 1015 | " \"seven\":\"7\",\n", 1016 | " \"eight\":\"8\",\n", 1017 | " \"nine\":\"9\",\n", 1018 | " \"zero\":\"0\"\n", 1019 | "}\n", 1020 | "spliting = word.split()\n", 1021 | "print(spliting)\n", 1022 | "for i in spliting:\n", 1023 | " print(mapping.get(i,\"&\"))\n", 1024 | " \n", 1025 | " " 1026 | ] 1027 | }, 1028 | { 1029 | "cell_type": "code", 1030 | "execution_count": 59, 1031 | "metadata": {}, 1032 | "outputs": [ 1033 | { 1034 | "name": "stdout", 1035 | "output_type": "stream", 1036 | "text": [ 1037 | ">good morning :)\n", 1038 | "good morning 😄 \n" 1039 | ] 1040 | } 1041 | ], 1042 | "source": [ 1043 | "#excersice -> print emoji\n", 1044 | "message = input(\">\")\n", 1045 | "words= message.split()\n", 1046 | "emoji = {\n", 1047 | " \":)\" :\"😄\",\n", 1048 | " \":(\" :\"😔\"\n", 1049 | "}\n", 1050 | "output = \"\"\n", 1051 | "for i in words:\n", 1052 | " output += emoji.get(i,i) + \" \"\n", 1053 | " \n", 1054 | "print(output)" 1055 | ] 1056 | }, 1057 | { 1058 | "cell_type": "markdown", 1059 | "metadata": {}, 1060 | "source": [ 1061 | "# Function " 1062 | ] 1063 | }, 1064 | { 1065 | "cell_type": "code", 1066 | "execution_count": 60, 1067 | "metadata": {}, 1068 | "outputs": [ 1069 | { 1070 | "name": "stdout", 1071 | "output_type": "stream", 1072 | "text": [ 1073 | "hii\n", 1074 | "im hritik\n" 1075 | ] 1076 | } 1077 | ], 1078 | "source": [ 1079 | "#function\n", 1080 | "def text():\n", 1081 | " print(\"im hritik\")\n", 1082 | "print(\"hii\")\n", 1083 | "text()" 1084 | ] 1085 | }, 1086 | { 1087 | "cell_type": "markdown", 1088 | "metadata": {}, 1089 | "source": [ 1090 | "# Parameter and Arguments" 1091 | ] 1092 | }, 1093 | { 1094 | "cell_type": "code", 1095 | "execution_count": 61, 1096 | "metadata": {}, 1097 | "outputs": [ 1098 | { 1099 | "name": "stdout", 1100 | "output_type": "stream", 1101 | "text": [ 1102 | "thanks\n", 1103 | "Hii hritik and jaiswal\n" 1104 | ] 1105 | } 1106 | ], 1107 | "source": [ 1108 | "#function with parameter\n", 1109 | "#parameter ->is placeholder that we passed to the function\n", 1110 | "#argumetnt -> is actual value that u gone pass inside function\n", 1111 | "def text(f_name, l_name):\n", 1112 | " print(f'Hii {f_name} and {l_name}')\n", 1113 | "print(\"thanks\")\n", 1114 | "text('hritik','jaiswal')" 1115 | ] 1116 | }, 1117 | { 1118 | "cell_type": "markdown", 1119 | "metadata": {}, 1120 | "source": [ 1121 | "# keyword argument" 1122 | ] 1123 | }, 1124 | { 1125 | "cell_type": "code", 1126 | "execution_count": 6, 1127 | "metadata": {}, 1128 | "outputs": [ 1129 | { 1130 | "name": "stdout", 1131 | "output_type": "stream", 1132 | "text": [ 1133 | "hello\n", 1134 | "Here total is 5000 including shipping charges 2000 + discount 500\n" 1135 | ] 1136 | } 1137 | ], 1138 | "source": [ 1139 | "#keyword argument -> its helpful when u don't want to pass argument in order u can pass in any order \n", 1140 | "def text(discount , shipping ,total ):\n", 1141 | " print(f'Here total is {total} including shipping charges {shipping} + discount {discount}')\n", 1142 | "print(\"hello\")\n", 1143 | "text(shipping=2000,total=5000,discount=500)" 1144 | ] 1145 | }, 1146 | { 1147 | "cell_type": "code", 1148 | "execution_count": 1, 1149 | "metadata": {}, 1150 | "outputs": [ 1151 | { 1152 | "name": "stdout", 1153 | "output_type": "stream", 1154 | "text": [ 1155 | "25\n" 1156 | ] 1157 | } 1158 | ], 1159 | "source": [ 1160 | "#return statement \n", 1161 | "def square(num):\n", 1162 | " return num*num\n", 1163 | "result = square(5)\n", 1164 | "print(result)\n", 1165 | " " 1166 | ] 1167 | }, 1168 | { 1169 | "cell_type": "code", 1170 | "execution_count": 11, 1171 | "metadata": {}, 1172 | "outputs": [ 1173 | { 1174 | "name": "stdout", 1175 | "output_type": "stream", 1176 | "text": [ 1177 | "27\n", 1178 | "None\n" 1179 | ] 1180 | } 1181 | ], 1182 | "source": [ 1183 | "#tric -> if u don't write return statement then it will return object which is : none \n", 1184 | "def cube(n):\n", 1185 | " print(n**3)\n", 1186 | "print(cube(3))" 1187 | ] 1188 | }, 1189 | { 1190 | "cell_type": "markdown", 1191 | "metadata": {}, 1192 | "source": [ 1193 | "# Exception" 1194 | ] 1195 | }, 1196 | { 1197 | "cell_type": "code", 1198 | "execution_count": 2, 1199 | "metadata": {}, 1200 | "outputs": [ 1201 | { 1202 | "name": "stdout", 1203 | "output_type": "stream", 1204 | "text": [ 1205 | "your age : twenty\n", 1206 | "invalid value\n" 1207 | ] 1208 | } 1209 | ], 1210 | "source": [ 1211 | "#exception -> when we try to input string value instead of int \n", 1212 | "# age = int(input(\"your age\"))\n", 1213 | "# print(age)\n", 1214 | "\n", 1215 | "try:\n", 1216 | " age = int(input(\"your age : \"))\n", 1217 | " print(age)\n", 1218 | "except ValueError:\n", 1219 | " print('invalid value')" 1220 | ] 1221 | }, 1222 | { 1223 | "cell_type": "code", 1224 | "execution_count": 21, 1225 | "metadata": {}, 1226 | "outputs": [ 1227 | { 1228 | "name": "stdout", 1229 | "output_type": "stream", 1230 | "text": [ 1231 | "your age : 0\n", 1232 | "invalid value or age can't be negative \n" 1233 | ] 1234 | } 1235 | ], 1236 | "source": [ 1237 | "\n", 1238 | "try:\n", 1239 | " age = int(input(\"your age : \"))\n", 1240 | " income = 20000\n", 1241 | " risk = float(income/age);\n", 1242 | " print(f'risk is {risk}')\n", 1243 | "except ValueError and ZeroDivisionError:\n", 1244 | " print(\"invalid value or age can't be negative \")" 1245 | ] 1246 | }, 1247 | { 1248 | "cell_type": "markdown", 1249 | "metadata": {}, 1250 | "source": [ 1251 | "# Class" 1252 | ] 1253 | }, 1254 | { 1255 | "cell_type": "code", 1256 | "execution_count": 61, 1257 | "metadata": {}, 1258 | "outputs": [ 1259 | { 1260 | "name": "stdout", 1261 | "output_type": "stream", 1262 | "text": [ 1263 | "area\n" 1264 | ] 1265 | } 1266 | ], 1267 | "source": [ 1268 | "#class \n", 1269 | "# 1) type -1\n", 1270 | "\n", 1271 | "class rect:\n", 1272 | " def rect_area(self):\n", 1273 | " print(\"area\")\n", 1274 | "p = rect()\n", 1275 | "p.rect_area()\n", 1276 | "\n" 1277 | ] 1278 | }, 1279 | { 1280 | "cell_type": "code", 1281 | "execution_count": 73, 1282 | "metadata": {}, 1283 | "outputs": [ 1284 | { 1285 | "name": "stdout", 1286 | "output_type": "stream", 1287 | "text": [ 1288 | "Hritik Jaiswal\n", 1289 | "Hritik Jaiswal\n" 1290 | ] 1291 | } 1292 | ], 1293 | "source": [ 1294 | "# 2) type -2\n", 1295 | "class Employee:\n", 1296 | " def __init__(self, first, last , salary):\n", 1297 | " self.first = first\n", 1298 | " self.last = last\n", 1299 | " self.salary = salary\n", 1300 | " self.email = first + '.'+last +'@gmail.com'\n", 1301 | " \n", 1302 | " def fullname(self):\n", 1303 | " return \"{} {}\".format(self.first,self.last)\n", 1304 | "\n", 1305 | "emp1 = Employee('Hritik','Jaiswal',5000)\n", 1306 | "emp2 = Employee('Aniket','Jaiswal',6000)\n", 1307 | "\n", 1308 | "#their are two methods \n", 1309 | "print(emp1.fullname())\n", 1310 | "print(Employee.fullname(emp1))\n", 1311 | " " 1312 | ] 1313 | }, 1314 | { 1315 | "cell_type": "code", 1316 | "execution_count": 74, 1317 | "metadata": {}, 1318 | "outputs": [ 1319 | { 1320 | "name": "stdout", 1321 | "output_type": "stream", 1322 | "text": [ 1323 | "area of square :9\n", 1324 | "area of rectangle is : 6\n" 1325 | ] 1326 | } 1327 | ], 1328 | "source": [ 1329 | "# 3) type -3\n", 1330 | "class Point:\n", 1331 | " def __init__(self,a,l,h):\n", 1332 | " self.a = a\n", 1333 | " self.l = l\n", 1334 | " self.h = h\n", 1335 | " \n", 1336 | " def square(self):\n", 1337 | " print(f\"area of square :{self.a*self.a}\")\n", 1338 | " \n", 1339 | " def rectangle(self):\n", 1340 | " print(\"area of rectangle is : {}\".format(self.l*self.h))\n", 1341 | " \n", 1342 | "\n", 1343 | "#create a object \n", 1344 | "point1 = Point(3,2,3)\n", 1345 | "point1.square()\n", 1346 | "point1.rectangle()" 1347 | ] 1348 | }, 1349 | { 1350 | "cell_type": "markdown", 1351 | "metadata": {}, 1352 | "source": [ 1353 | "# Inheritance" 1354 | ] 1355 | }, 1356 | { 1357 | "cell_type": "code", 1358 | "execution_count": 9, 1359 | "metadata": {}, 1360 | "outputs": [ 1361 | { 1362 | "name": "stdout", 1363 | "output_type": "stream", 1364 | "text": [ 1365 | "bark\n", 1366 | "walk\n" 1367 | ] 1368 | } 1369 | ], 1370 | "source": [ 1371 | "#inheritance -> dog and cat are inherite a class mammel\n", 1372 | "class mammel:\n", 1373 | " def walk(self):\n", 1374 | " print(\"walk\")\n", 1375 | "\n", 1376 | "class dog(mammel):\n", 1377 | " def bark(self):\n", 1378 | " print(\"bark\")\n", 1379 | "\n", 1380 | "class cat(mammel):\n", 1381 | " pass\n", 1382 | "\n", 1383 | "dog1 = dog()\n", 1384 | "dog1.bark()\n", 1385 | "\n", 1386 | "cat1 = cat()\n", 1387 | "cat1.walk()" 1388 | ] 1389 | }, 1390 | { 1391 | "cell_type": "markdown", 1392 | "metadata": {}, 1393 | "source": [ 1394 | "# Module\n", 1395 | "\n" 1396 | ] 1397 | }, 1398 | { 1399 | "cell_type": "code", 1400 | "execution_count": 23, 1401 | "metadata": {}, 1402 | "outputs": [ 1403 | { 1404 | "name": "stdout", 1405 | "output_type": "stream", 1406 | "text": [ 1407 | "1.0\n" 1408 | ] 1409 | } 1410 | ], 1411 | "source": [ 1412 | "#module -> module.ipynb file which we have created we can directly import function also\n", 1413 | "#we need to install from anaconda prompt -> pip install import-ipynb\n", 1414 | "import import_ipynb\n", 1415 | "\n", 1416 | "import module\n", 1417 | "from module import cm2m\n", 1418 | "\n", 1419 | "cm2m(100)\n", 1420 | "m2cm" 1421 | ] 1422 | }, 1423 | { 1424 | "cell_type": "code", 1425 | "execution_count": 18, 1426 | "metadata": {}, 1427 | "outputs": [ 1428 | { 1429 | "name": "stdout", 1430 | "output_type": "stream", 1431 | "text": [ 1432 | "10\n", 1433 | "4\n" 1434 | ] 1435 | } 1436 | ], 1437 | "source": [ 1438 | "numbers = [5,4,6,8,10]\n", 1439 | "print(max(numbers))\n", 1440 | "print(min(numbers))\n" 1441 | ] 1442 | }, 1443 | { 1444 | "cell_type": "markdown", 1445 | "metadata": {}, 1446 | "source": [ 1447 | "# Packages\n" 1448 | ] 1449 | }, 1450 | { 1451 | "cell_type": "markdown", 1452 | "metadata": {}, 1453 | "source": [ 1454 | "package -: we can create a seperate .py file and extract this file and import into another file as similar to module \n", 1455 | "\n", 1456 | "package is collections of different modules\n", 1457 | "\n", 1458 | "# Type of Module\n", 1459 | "\n", 1460 | " 1) Absolute module \n", 1461 | "from mypackage.mymodule1 import class A\n", 1462 | "obj = class A\n", 1463 | "\n", 1464 | " 2) relative module\n", 1465 | "if im working in \"module1\" & i want to import Class C from \"module2\" into my \"module1\"\n", 1466 | "\n", 1467 | "from module2 import classC\n", 1468 | "obj = classC()\n", 1469 | "\n", 1470 | "\n", 1471 | " \n" 1472 | ] 1473 | }, 1474 | { 1475 | "cell_type": "markdown", 1476 | "metadata": {}, 1477 | "source": [ 1478 | "# Random\n" 1479 | ] 1480 | }, 1481 | { 1482 | "cell_type": "code", 1483 | "execution_count": 6, 1484 | "metadata": {}, 1485 | "outputs": [ 1486 | { 1487 | "name": "stdout", 1488 | "output_type": "stream", 1489 | "text": [ 1490 | "0.8556515733440572\n", 1491 | "0.9018671283206765\n", 1492 | "0.6655666651378818\n" 1493 | ] 1494 | } 1495 | ], 1496 | "source": [ 1497 | "import random\n", 1498 | "\n", 1499 | "for i in range(3):\n", 1500 | " print(random.random())" 1501 | ] 1502 | }, 1503 | { 1504 | "cell_type": "code", 1505 | "execution_count": 9, 1506 | "metadata": {}, 1507 | "outputs": [ 1508 | { 1509 | "name": "stdout", 1510 | "output_type": "stream", 1511 | "text": [ 1512 | "12\n", 1513 | "20\n", 1514 | "15\n" 1515 | ] 1516 | } 1517 | ], 1518 | "source": [ 1519 | "for i in range(3):\n", 1520 | " print(random.randint(10,20))" 1521 | ] 1522 | }, 1523 | { 1524 | "cell_type": "code", 1525 | "execution_count": 17, 1526 | "metadata": {}, 1527 | "outputs": [ 1528 | { 1529 | "name": "stdout", 1530 | "output_type": "stream", 1531 | "text": [ 1532 | "jaiswal\n" 1533 | ] 1534 | } 1535 | ], 1536 | "source": [ 1537 | "# randomly choose the value \n", 1538 | "members = ['hritik', 'jaiswal','aniket','shweta']\n", 1539 | "show = random.choice(members)\n", 1540 | "print(show)" 1541 | ] 1542 | }, 1543 | { 1544 | "cell_type": "code", 1545 | "execution_count": 33, 1546 | "metadata": {}, 1547 | "outputs": [ 1548 | { 1549 | "name": "stdout", 1550 | "output_type": "stream", 1551 | "text": [ 1552 | "(2,4)\n" 1553 | ] 1554 | } 1555 | ], 1556 | "source": [ 1557 | "#excercise -> dice thrown give random value\n", 1558 | "\n", 1559 | "class Dice:\n", 1560 | " def roll(self):\n", 1561 | " x = (1,2,3,4,5,6)\n", 1562 | " y = (1,2,3,4,5,6)\n", 1563 | " m = random.choice(x)\n", 1564 | " l = random.choice(y)\n", 1565 | " print(\"({},{})\".format(m,l))\n", 1566 | " \n", 1567 | "\n", 1568 | "r = Dice()\n", 1569 | "r.roll()\n", 1570 | "\n" 1571 | ] 1572 | }, 1573 | { 1574 | "cell_type": "code", 1575 | "execution_count": 38, 1576 | "metadata": {}, 1577 | "outputs": [ 1578 | { 1579 | "name": "stdout", 1580 | "output_type": "stream", 1581 | "text": [ 1582 | "(5, 6)\n" 1583 | ] 1584 | } 1585 | ], 1586 | "source": [ 1587 | "# another method\n", 1588 | "\n", 1589 | "class Dice:\n", 1590 | " def roll(self):\n", 1591 | " first = random.randint(1,6)\n", 1592 | " second = random.randint(1,6)\n", 1593 | " return first,second\n", 1594 | "dice = Dice()\n", 1595 | "print(dice.roll())" 1596 | ] 1597 | }, 1598 | { 1599 | "cell_type": "markdown", 1600 | "metadata": {}, 1601 | "source": [ 1602 | "# Files and Directories" 1603 | ] 1604 | }, 1605 | { 1606 | "cell_type": "code", 1607 | "execution_count": 21, 1608 | "metadata": {}, 1609 | "outputs": [ 1610 | { 1611 | "name": "stdout", 1612 | "output_type": "stream", 1613 | "text": [ 1614 | "True\n" 1615 | ] 1616 | } 1617 | ], 1618 | "source": [ 1619 | "from pathlib import Path\n", 1620 | "path = Path(\".\")\n", 1621 | "print(path.exists())\n", 1622 | "\n", 1623 | "\n", 1624 | "#if u want to make new directory\n", 1625 | "\n", 1626 | "# path1 = Path(\"Files_Directories\")\n", 1627 | "# path1.mkdir()\n", 1628 | "\n", 1629 | "#when u want to remove directory\n", 1630 | "#path.rmdir()\n", 1631 | "\n" 1632 | ] 1633 | }, 1634 | { 1635 | "cell_type": "code", 1636 | "execution_count": 5, 1637 | "metadata": {}, 1638 | "outputs": [ 1639 | { 1640 | "name": "stdout", 1641 | "output_type": "stream", 1642 | "text": [ 1643 | "ch02.ipynb\n", 1644 | "module.ipynb\n", 1645 | "Python-1.ipynb\n" 1646 | ] 1647 | } 1648 | ], 1649 | "source": [ 1650 | "path2 = Path()\n", 1651 | "for file in path2.glob(\"*.ipynb\"):\n", 1652 | " print(file)" 1653 | ] 1654 | }, 1655 | { 1656 | "cell_type": "code", 1657 | "execution_count": 6, 1658 | "metadata": {}, 1659 | "outputs": [ 1660 | { 1661 | "name": "stdout", 1662 | "output_type": "stream", 1663 | "text": [ 1664 | ".ipynb_checkpoints\n", 1665 | "ch02.ipynb\n", 1666 | "Files_Directories\n", 1667 | "module.ipynb\n", 1668 | "Python-1.ipynb\n" 1669 | ] 1670 | } 1671 | ], 1672 | "source": [ 1673 | "path3 = Path()\n", 1674 | "for file in path3.glob(\"*\"):\n", 1675 | " print(file)" 1676 | ] 1677 | }, 1678 | { 1679 | "cell_type": "markdown", 1680 | "metadata": {}, 1681 | "source": [ 1682 | "# Working with spreadsheet" 1683 | ] 1684 | }, 1685 | { 1686 | "cell_type": "code", 1687 | "execution_count": 22, 1688 | "metadata": {}, 1689 | "outputs": [ 1690 | { 1691 | "name": "stdout", 1692 | "output_type": "stream", 1693 | "text": [ 1694 | "transaction_id\n", 1695 | "4\n" 1696 | ] 1697 | } 1698 | ], 1699 | "source": [ 1700 | "import openpyxl as xl\n", 1701 | "from openpyxl.chart import BarChart,Reference\n", 1702 | "wb = xl.load_workbook(r'C:\\Users\\Hritik Jaiswal\\Downloads\\Spreadsheet\\transactions.xlsx')\n", 1703 | "sheet = wb['Sheet1']\n", 1704 | "\n", 1705 | "\n", 1706 | "#method to get a cell \n", 1707 | "\n", 1708 | "cell = sheet['a1']\n", 1709 | "#another method -> cell = sheet.cell(1,1)\n", 1710 | "\n", 1711 | "print(cell.value)\n", 1712 | "#print max row\n", 1713 | "print(sheet.max_row)" 1714 | ] 1715 | }, 1716 | { 1717 | "cell_type": "code", 1718 | "execution_count": 25, 1719 | "metadata": {}, 1720 | "outputs": [ 1721 | { 1722 | "name": "stdout", 1723 | "output_type": "stream", 1724 | "text": [ 1725 | "5.95\n", 1726 | "6.95\n", 1727 | "7.95\n" 1728 | ] 1729 | } 1730 | ], 1731 | "source": [ 1732 | "#we have to modify value of the cell and store into another excel file\n", 1733 | "\n", 1734 | "for row in range(2,sheet.max_row+1):\n", 1735 | " cell = sheet.cell(row,3) # column is 3\n", 1736 | " print(cell.value)\n", 1737 | " corrected_value = cell.value * 0.9\n", 1738 | " \n", 1739 | " #now we have to place a corrected value into anther column \n", 1740 | " corrected_value_cell = sheet.cell(row,4) #add corrected value into the 4 column\n", 1741 | " \n", 1742 | " corrected_value_cell.value = corrected_value\n", 1743 | "#Excersice \n", 1744 | "\n", 1745 | "# u have to create a bar graph in excel\n", 1746 | "\n", 1747 | "\n", 1748 | "values = Reference(sheet, \n", 1749 | " \n", 1750 | " min_row=2,max_row = sheet.max_row,\n", 1751 | " \n", 1752 | " min_col = 4 , max_col = 4\n", 1753 | " )\n", 1754 | "\n", 1755 | "chart = BarChart()\n", 1756 | "chart.add_data(values)\n", 1757 | "sheet.add_chart(chart, 'f2')\n", 1758 | "\n", 1759 | "\n", 1760 | "wb.save(\"transaction2.xlsx\")\n", 1761 | "\n" 1762 | ] 1763 | }, 1764 | { 1765 | "cell_type": "code", 1766 | "execution_count": 24, 1767 | "metadata": {}, 1768 | "outputs": [], 1769 | "source": [] 1770 | }, 1771 | { 1772 | "cell_type": "code", 1773 | "execution_count": null, 1774 | "metadata": {}, 1775 | "outputs": [], 1776 | "source": [] 1777 | } 1778 | ], 1779 | "metadata": { 1780 | "kernelspec": { 1781 | "display_name": "Python 3", 1782 | "language": "python", 1783 | "name": "python3" 1784 | }, 1785 | "language_info": { 1786 | "codemirror_mode": { 1787 | "name": "ipython", 1788 | "version": 3 1789 | }, 1790 | "file_extension": ".py", 1791 | "mimetype": "text/x-python", 1792 | "name": "python", 1793 | "nbconvert_exporter": "python", 1794 | "pygments_lexer": "ipython3", 1795 | "version": "3.6.8" 1796 | } 1797 | }, 1798 | "nbformat": 4, 1799 | "nbformat_minor": 2 1800 | } 1801 | -------------------------------------------------------------------------------- /.ipynb_checkpoints/ch02-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Python Language Basics, IPython, and Jupyter Notebooks" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": null, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "import numpy as np\n", 17 | "np.random.seed(12345)\n", 18 | "np.set_printoptions(precision=4, suppress=True)" 19 | ] 20 | }, 21 | { 22 | "cell_type": "markdown", 23 | "metadata": {}, 24 | "source": [ 25 | "## The Python Interpreter" 26 | ] 27 | }, 28 | { 29 | "cell_type": "markdown", 30 | "metadata": {}, 31 | "source": [ 32 | "```python\n", 33 | "$ python\n", 34 | "Python 3.6.0 | packaged by conda-forge | (default, Jan 13 2017, 23:17:12)\n", 35 | "[GCC 4.8.2 20140120 (Red Hat 4.8.2-15)] on linux\n", 36 | "Type \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n", 37 | ">>> a = 5\n", 38 | ">>> print(a)\n", 39 | "5\n", 40 | "```" 41 | ] 42 | }, 43 | { 44 | "cell_type": "markdown", 45 | "metadata": {}, 46 | "source": [ 47 | "```python\n", 48 | "print('Hello world')\n", 49 | "```" 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "metadata": {}, 55 | "source": [ 56 | "```python\n", 57 | "$ python hello_world.py\n", 58 | "Hello world\n", 59 | "```" 60 | ] 61 | }, 62 | { 63 | "cell_type": "markdown", 64 | "metadata": {}, 65 | "source": [ 66 | "```shell\n", 67 | "$ ipython\n", 68 | "Python 3.6.0 | packaged by conda-forge | (default, Jan 13 2017, 23:17:12)\n", 69 | "Type \"copyright\", \"credits\" or \"license\" for more information.\n", 70 | "\n", 71 | "IPython 5.1.0 -- An enhanced Interactive Python.\n", 72 | "? -> Introduction and overview of IPython's features.\n", 73 | "%quickref -> Quick reference.\n", 74 | "help -> Python's own help system.\n", 75 | "object? -> Details about 'object', use 'object??' for extra details.\n", 76 | "\n", 77 | "In [1]: %run hello_world.py\n", 78 | "Hello world\n", 79 | "\n", 80 | "In [2]:\n", 81 | "```" 82 | ] 83 | }, 84 | { 85 | "cell_type": "markdown", 86 | "metadata": {}, 87 | "source": [ 88 | "## IPython Basics" 89 | ] 90 | }, 91 | { 92 | "cell_type": "markdown", 93 | "metadata": {}, 94 | "source": [ 95 | "### Running the IPython Shell" 96 | ] 97 | }, 98 | { 99 | "cell_type": "markdown", 100 | "metadata": {}, 101 | "source": [ 102 | "$ " 103 | ] 104 | }, 105 | { 106 | "cell_type": "code", 107 | "execution_count": 1, 108 | "metadata": {}, 109 | "outputs": [ 110 | { 111 | "data": { 112 | "text/plain": [ 113 | "{0: 0.163237556162501,\n", 114 | " 1: -0.37040882274338893,\n", 115 | " 2: -0.08088067273179514,\n", 116 | " 3: -0.9098779171581127,\n", 117 | " 4: 0.25760185356933984,\n", 118 | " 5: 0.5749282673553658,\n", 119 | " 6: -0.8597249109794647}" 120 | ] 121 | }, 122 | "execution_count": 1, 123 | "metadata": {}, 124 | "output_type": "execute_result" 125 | } 126 | ], 127 | "source": [ 128 | "import numpy as np\n", 129 | "data = {i : np.random.randn() for i in range(7)}\n", 130 | "data" 131 | ] 132 | }, 133 | { 134 | "cell_type": "markdown", 135 | "metadata": {}, 136 | "source": [ 137 | ">>> from numpy.random import randn\n", 138 | ">>> data = {i : randn() for i in range(7)}\n", 139 | ">>> print(data)\n", 140 | "{0: -1.5948255432744511, 1: 0.10569006472787983, 2: 1.972367135977295,\n", 141 | "3: 0.15455217573074576, 4: -0.24058577449429575, 5: -1.2904897053651216,\n", 142 | "6: 0.3308507317325902}" 143 | ] 144 | }, 145 | { 146 | "cell_type": "markdown", 147 | "metadata": {}, 148 | "source": [ 149 | "### Running the Jupyter Notebook" 150 | ] 151 | }, 152 | { 153 | "cell_type": "markdown", 154 | "metadata": {}, 155 | "source": [ 156 | "```shell\n", 157 | "$ jupyter notebook\n", 158 | "[I 15:20:52.739 NotebookApp] Serving notebooks from local directory:\n", 159 | "/home/wesm/code/pydata-book\n", 160 | "[I 15:20:52.739 NotebookApp] 0 active kernels\n", 161 | "[I 15:20:52.739 NotebookApp] The Jupyter Notebook is running at:\n", 162 | "http://localhost:8888/\n", 163 | "[I 15:20:52.740 NotebookApp] Use Control-C to stop this server and shut down\n", 164 | "all kernels (twice to skip confirmation).\n", 165 | "Created new window in existing browser session.\n", 166 | "```" 167 | ] 168 | }, 169 | { 170 | "cell_type": "markdown", 171 | "metadata": {}, 172 | "source": [ 173 | "### Tab Completion" 174 | ] 175 | }, 176 | { 177 | "cell_type": "markdown", 178 | "metadata": {}, 179 | "source": [ 180 | "```\n", 181 | "In [1]: an_apple = 27\n", 182 | "\n", 183 | "In [2]: an_example = 42\n", 184 | "\n", 185 | "In [3]: an\n", 186 | "```" 187 | ] 188 | }, 189 | { 190 | "cell_type": "markdown", 191 | "metadata": {}, 192 | "source": [ 193 | "```\n", 194 | "In [3]: b = [1, 2, 3]\n", 195 | "\n", 196 | "In [4]: b.\n", 197 | "```" 198 | ] 199 | }, 200 | { 201 | "cell_type": "markdown", 202 | "metadata": {}, 203 | "source": [ 204 | "```\n", 205 | "In [1]: import datetime\n", 206 | "\n", 207 | "In [2]: datetime.\n", 208 | "```" 209 | ] 210 | }, 211 | { 212 | "cell_type": "markdown", 213 | "metadata": {}, 214 | "source": [ 215 | "```\n", 216 | "In [7]: datasets/movielens/\n", 217 | "```" 218 | ] 219 | }, 220 | { 221 | "cell_type": "markdown", 222 | "metadata": {}, 223 | "source": [ 224 | "### Introspection" 225 | ] 226 | }, 227 | { 228 | "cell_type": "markdown", 229 | "metadata": {}, 230 | "source": [ 231 | "```\n", 232 | "In [8]: b = [1, 2, 3]\n", 233 | "\n", 234 | "In [9]: b?\n", 235 | "Type: list\n", 236 | "String Form:[1, 2, 3]\n", 237 | "Length: 3\n", 238 | "Docstring:\n", 239 | "list() -> new empty list\n", 240 | "list(iterable) -> new list initialized from iterable's items\n", 241 | "\n", 242 | "In [10]: print?\n", 243 | "Docstring:\n", 244 | "print(value, ..., sep=' ', end='\\n', file=sys.stdout, flush=False)\n", 245 | "\n", 246 | "Prints the values to a stream, or to sys.stdout by default.\n", 247 | "Optional keyword arguments:\n", 248 | "file: a file-like object (stream); defaults to the current sys.stdout.\n", 249 | "sep: string inserted between values, default a space.\n", 250 | "end: string appended after the last value, default a newline.\n", 251 | "flush: whether to forcibly flush the stream.\n", 252 | "Type: builtin_function_or_method\n", 253 | "```" 254 | ] 255 | }, 256 | { 257 | "cell_type": "markdown", 258 | "metadata": {}, 259 | "source": [ 260 | "```python\n", 261 | "def add_numbers(a, b):\n", 262 | " \"\"\"\n", 263 | " Add two numbers together\n", 264 | "\n", 265 | " Returns\n", 266 | " -------\n", 267 | " the_sum : type of arguments\n", 268 | " \"\"\"\n", 269 | " return a + b\n", 270 | "```" 271 | ] 272 | }, 273 | { 274 | "cell_type": "markdown", 275 | "metadata": {}, 276 | "source": [ 277 | "```python\n", 278 | "In [11]: add_numbers?\n", 279 | "Signature: add_numbers(a, b)\n", 280 | "Docstring:\n", 281 | "Add two numbers together\n", 282 | "\n", 283 | "Returns\n", 284 | "-------\n", 285 | "the_sum : type of arguments\n", 286 | "File: \n", 287 | "Type: function\n", 288 | "```" 289 | ] 290 | }, 291 | { 292 | "cell_type": "markdown", 293 | "metadata": {}, 294 | "source": [ 295 | "```python\n", 296 | "In [12]: add_numbers??\n", 297 | "Signature: add_numbers(a, b)\n", 298 | "Source:\n", 299 | "def add_numbers(a, b):\n", 300 | " \"\"\"\n", 301 | " Add two numbers together\n", 302 | "\n", 303 | " Returns\n", 304 | " -------\n", 305 | " the_sum : type of arguments\n", 306 | " \"\"\"\n", 307 | " return a + b\n", 308 | "File: \n", 309 | "Type: function\n", 310 | "```" 311 | ] 312 | }, 313 | { 314 | "cell_type": "markdown", 315 | "metadata": {}, 316 | "source": [ 317 | "```python\n", 318 | "In [13]: np.*load*?\n", 319 | "np.__loader__\n", 320 | "np.load\n", 321 | "np.loads\n", 322 | "np.loadtxt\n", 323 | "np.pkgload\n", 324 | "```" 325 | ] 326 | }, 327 | { 328 | "cell_type": "markdown", 329 | "metadata": {}, 330 | "source": [ 331 | "### The %run Command" 332 | ] 333 | }, 334 | { 335 | "cell_type": "markdown", 336 | "metadata": {}, 337 | "source": [ 338 | "```python\n", 339 | "def f(x, y, z):\n", 340 | " return (x + y) / z\n", 341 | "\n", 342 | "a = 5\n", 343 | "b = 6\n", 344 | "c = 7.5\n", 345 | "\n", 346 | "result = f(a, b, c)\n", 347 | "```" 348 | ] 349 | }, 350 | { 351 | "cell_type": "markdown", 352 | "metadata": {}, 353 | "source": [ 354 | "```python\n", 355 | "In [14]: %run ipython_script_test.py\n", 356 | "```" 357 | ] 358 | }, 359 | { 360 | "cell_type": "markdown", 361 | "metadata": {}, 362 | "source": [ 363 | "```python\n", 364 | "In [15]: c\n", 365 | "Out [15]: 7.5\n", 366 | "\n", 367 | "In [16]: result\n", 368 | "Out[16]: 1.4666666666666666\n", 369 | "```" 370 | ] 371 | }, 372 | { 373 | "cell_type": "markdown", 374 | "metadata": {}, 375 | "source": [ 376 | "```python\n", 377 | ">>> %load ipython_script_test.py\n", 378 | "\n", 379 | " def f(x, y, z):\n", 380 | " return (x + y) / z\n", 381 | "\n", 382 | " a = 5\n", 383 | " b = 6\n", 384 | " c = 7.5\n", 385 | "\n", 386 | " result = f(a, b, c)\n", 387 | "```" 388 | ] 389 | }, 390 | { 391 | "cell_type": "markdown", 392 | "metadata": {}, 393 | "source": [ 394 | "#### Interrupting running code" 395 | ] 396 | }, 397 | { 398 | "cell_type": "markdown", 399 | "metadata": {}, 400 | "source": [ 401 | "### Executing Code from the Clipboard" 402 | ] 403 | }, 404 | { 405 | "cell_type": "markdown", 406 | "metadata": {}, 407 | "source": [ 408 | "```python\n", 409 | "x = 5\n", 410 | "y = 7\n", 411 | "if x > 5:\n", 412 | " x += 1\n", 413 | "\n", 414 | " y = 8\n", 415 | "```" 416 | ] 417 | }, 418 | { 419 | "cell_type": "markdown", 420 | "metadata": {}, 421 | "source": [ 422 | "```python\n", 423 | "In [17]: %paste\n", 424 | "x = 5\n", 425 | "y = 7\n", 426 | "if x > 5:\n", 427 | " x += 1\n", 428 | "\n", 429 | " y = 8\n", 430 | "## -- End pasted text --\n", 431 | "```" 432 | ] 433 | }, 434 | { 435 | "cell_type": "markdown", 436 | "metadata": {}, 437 | "source": [ 438 | "```python\n", 439 | "In [18]: %cpaste\n", 440 | "Pasting code; enter '--' alone on the line to stop or use Ctrl-D.\n", 441 | ":x = 5\n", 442 | ":y = 7\n", 443 | ":if x > 5:\n", 444 | ": x += 1\n", 445 | ":\n", 446 | ": y = 8\n", 447 | ":--\n", 448 | "```" 449 | ] 450 | }, 451 | { 452 | "cell_type": "markdown", 453 | "metadata": {}, 454 | "source": [ 455 | "### Terminal Keyboard Shortcuts" 456 | ] 457 | }, 458 | { 459 | "cell_type": "markdown", 460 | "metadata": {}, 461 | "source": [ 462 | "### About Magic Commands" 463 | ] 464 | }, 465 | { 466 | "cell_type": "markdown", 467 | "metadata": {}, 468 | "source": [ 469 | "```python\n", 470 | "In [20]: a = np.random.randn(100, 100)\n", 471 | "\n", 472 | "In [20]: %timeit np.dot(a, a)\n", 473 | "10000 loops, best of 3: 20.9 µs per loop\n", 474 | "```" 475 | ] 476 | }, 477 | { 478 | "cell_type": "markdown", 479 | "metadata": {}, 480 | "source": [ 481 | "```python\n", 482 | "In [21]: %debug?\n", 483 | "Docstring:\n", 484 | "::\n", 485 | "\n", 486 | " %debug [--breakpoint FILE:LINE] [statement [statement ...]]\n", 487 | "\n", 488 | "Activate the interactive debugger.\n", 489 | "\n", 490 | "This magic command support two ways of activating debugger.\n", 491 | "One is to activate debugger before executing code. This way, you\n", 492 | "can set a break point, to step through the code from the point.\n", 493 | "You can use this mode by giving statements to execute and optionally\n", 494 | "a breakpoint.\n", 495 | "\n", 496 | "The other one is to activate debugger in post-mortem mode. You can\n", 497 | "activate this mode simply running %debug without any argument.\n", 498 | "If an exception has just occurred, this lets you inspect its stack\n", 499 | "frames interactively. Note that this will always work only on the last\n", 500 | "traceback that occurred, so you must call this quickly after an\n", 501 | "exception that you wish to inspect has fired, because if another one\n", 502 | "occurs, it clobbers the previous one.\n", 503 | "\n", 504 | "If you want IPython to automatically do this on every exception, see\n", 505 | "the %pdb magic for more details.\n", 506 | "\n", 507 | "positional arguments:\n", 508 | " statement Code to run in debugger. You can omit this in cell\n", 509 | " magic mode.\n", 510 | "\n", 511 | "optional arguments:\n", 512 | " --breakpoint , -b \n", 513 | " Set break point at LINE in FILE.\n", 514 | "\n", 515 | "``` " 516 | ] 517 | }, 518 | { 519 | "cell_type": "markdown", 520 | "metadata": {}, 521 | "source": [ 522 | "```python\n", 523 | "In [22]: %pwd\n", 524 | "Out[22]: '/home/wesm/code/pydata-book\n", 525 | "\n", 526 | "In [23]: foo = %pwd\n", 527 | "\n", 528 | "In [24]: foo\n", 529 | "Out[24]: '/home/wesm/code/pydata-book'\n", 530 | "```" 531 | ] 532 | }, 533 | { 534 | "cell_type": "markdown", 535 | "metadata": {}, 536 | "source": [ 537 | "### Matplotlib Integration" 538 | ] 539 | }, 540 | { 541 | "cell_type": "markdown", 542 | "metadata": {}, 543 | "source": [ 544 | "```python\n", 545 | "In [26]: %matplotlib\n", 546 | "Using matplotlib backend: Qt4Agg\n", 547 | "```" 548 | ] 549 | }, 550 | { 551 | "cell_type": "markdown", 552 | "metadata": {}, 553 | "source": [ 554 | "```python\n", 555 | "In [26]: %matplotlib inline\n", 556 | "```" 557 | ] 558 | }, 559 | { 560 | "cell_type": "markdown", 561 | "metadata": {}, 562 | "source": [ 563 | "## Python Language Basics" 564 | ] 565 | }, 566 | { 567 | "cell_type": "markdown", 568 | "metadata": {}, 569 | "source": [ 570 | "### Language Semantics" 571 | ] 572 | }, 573 | { 574 | "cell_type": "markdown", 575 | "metadata": {}, 576 | "source": [ 577 | "#### Indentation, not braces" 578 | ] 579 | }, 580 | { 581 | "cell_type": "markdown", 582 | "metadata": {}, 583 | "source": [ 584 | "```python\n", 585 | "for x in array:\n", 586 | " if x < pivot:\n", 587 | " less.append(x)\n", 588 | " else:\n", 589 | " greater.append(x)\n", 590 | "```" 591 | ] 592 | }, 593 | { 594 | "cell_type": "markdown", 595 | "metadata": {}, 596 | "source": [ 597 | "```python\n", 598 | "a = 5; b = 6; c = 7\n", 599 | "```" 600 | ] 601 | }, 602 | { 603 | "cell_type": "markdown", 604 | "metadata": {}, 605 | "source": [ 606 | "#### Everything is an object" 607 | ] 608 | }, 609 | { 610 | "cell_type": "markdown", 611 | "metadata": {}, 612 | "source": [ 613 | "#### Comments" 614 | ] 615 | }, 616 | { 617 | "cell_type": "markdown", 618 | "metadata": {}, 619 | "source": [ 620 | "```python\n", 621 | "results = []\n", 622 | "for line in file_handle:\n", 623 | " # keep the empty lines for now\n", 624 | " # if len(line) == 0:\n", 625 | " # continue\n", 626 | " results.append(line.replace('foo', 'bar'))\n", 627 | "```" 628 | ] 629 | }, 630 | { 631 | "cell_type": "markdown", 632 | "metadata": {}, 633 | "source": [ 634 | "```python\n", 635 | "print(\"Reached this line\") # Simple status report\n", 636 | "```" 637 | ] 638 | }, 639 | { 640 | "cell_type": "markdown", 641 | "metadata": {}, 642 | "source": [ 643 | "#### Function and object method calls" 644 | ] 645 | }, 646 | { 647 | "cell_type": "markdown", 648 | "metadata": {}, 649 | "source": [ 650 | "```\n", 651 | "result = f(x, y, z)\n", 652 | "g()\n", 653 | "```" 654 | ] 655 | }, 656 | { 657 | "cell_type": "markdown", 658 | "metadata": {}, 659 | "source": [ 660 | "```\n", 661 | "obj.some_method(x, y, z)\n", 662 | "```" 663 | ] 664 | }, 665 | { 666 | "cell_type": "markdown", 667 | "metadata": {}, 668 | "source": [ 669 | "```python\n", 670 | "result = f(a, b, c, d=5, e='foo')\n", 671 | "```" 672 | ] 673 | }, 674 | { 675 | "cell_type": "markdown", 676 | "metadata": {}, 677 | "source": [ 678 | "#### Variables and argument passing" 679 | ] 680 | }, 681 | { 682 | "cell_type": "code", 683 | "execution_count": null, 684 | "metadata": {}, 685 | "outputs": [], 686 | "source": [ 687 | "a = [1, 2, 3]" 688 | ] 689 | }, 690 | { 691 | "cell_type": "code", 692 | "execution_count": null, 693 | "metadata": {}, 694 | "outputs": [], 695 | "source": [ 696 | "b = a" 697 | ] 698 | }, 699 | { 700 | "cell_type": "code", 701 | "execution_count": null, 702 | "metadata": {}, 703 | "outputs": [], 704 | "source": [ 705 | "a.append(4)\n", 706 | "b" 707 | ] 708 | }, 709 | { 710 | "cell_type": "markdown", 711 | "metadata": {}, 712 | "source": [ 713 | "```python\n", 714 | "def append_element(some_list, element):\n", 715 | " some_list.append(element)\n", 716 | "```" 717 | ] 718 | }, 719 | { 720 | "cell_type": "markdown", 721 | "metadata": {}, 722 | "source": [ 723 | "```python\n", 724 | "In [27]: data = [1, 2, 3]\n", 725 | "\n", 726 | "In [28]: append_element(data, 4)\n", 727 | "\n", 728 | "In [29]: data\n", 729 | "Out[29]: [1, 2, 3, 4]\n", 730 | "```" 731 | ] 732 | }, 733 | { 734 | "cell_type": "markdown", 735 | "metadata": {}, 736 | "source": [ 737 | "#### Dynamic references, strong types" 738 | ] 739 | }, 740 | { 741 | "cell_type": "code", 742 | "execution_count": null, 743 | "metadata": {}, 744 | "outputs": [], 745 | "source": [ 746 | "a = 5\n", 747 | "type(a)\n", 748 | "a = 'foo'\n", 749 | "type(a)" 750 | ] 751 | }, 752 | { 753 | "cell_type": "code", 754 | "execution_count": null, 755 | "metadata": {}, 756 | "outputs": [], 757 | "source": [ 758 | "'5' + 5" 759 | ] 760 | }, 761 | { 762 | "cell_type": "code", 763 | "execution_count": null, 764 | "metadata": {}, 765 | "outputs": [], 766 | "source": [ 767 | "a = 4.5\n", 768 | "b = 2\n", 769 | "# String formatting, to be visited later\n", 770 | "print('a is {0}, b is {1}'.format(type(a), type(b)))\n", 771 | "a / b" 772 | ] 773 | }, 774 | { 775 | "cell_type": "code", 776 | "execution_count": null, 777 | "metadata": {}, 778 | "outputs": [], 779 | "source": [ 780 | "a = 5\n", 781 | "isinstance(a, int)" 782 | ] 783 | }, 784 | { 785 | "cell_type": "code", 786 | "execution_count": null, 787 | "metadata": {}, 788 | "outputs": [], 789 | "source": [ 790 | "a = 5; b = 4.5\n", 791 | "isinstance(a, (int, float))\n", 792 | "isinstance(b, (int, float))" 793 | ] 794 | }, 795 | { 796 | "cell_type": "markdown", 797 | "metadata": {}, 798 | "source": [ 799 | "#### Attributes and methods" 800 | ] 801 | }, 802 | { 803 | "cell_type": "markdown", 804 | "metadata": {}, 805 | "source": [ 806 | "```python\n", 807 | "In [1]: a = 'foo'\n", 808 | "\n", 809 | "In [2]: a.\n", 810 | "a.capitalize a.format a.isupper a.rindex a.strip\n", 811 | "a.center a.index a.join a.rjust a.swapcase\n", 812 | "a.count a.isalnum a.ljust a.rpartition a.title\n", 813 | "a.decode a.isalpha a.lower a.rsplit a.translate\n", 814 | "a.encode a.isdigit a.lstrip a.rstrip a.upper\n", 815 | "a.endswith a.islower a.partition a.split a.zfill\n", 816 | "a.expandtabs a.isspace a.replace a.splitlines\n", 817 | "a.find a.istitle a.rfind a.startswith\n", 818 | "```" 819 | ] 820 | }, 821 | { 822 | "cell_type": "code", 823 | "execution_count": null, 824 | "metadata": {}, 825 | "outputs": [], 826 | "source": [ 827 | "a = 'foo'" 828 | ] 829 | }, 830 | { 831 | "cell_type": "code", 832 | "execution_count": null, 833 | "metadata": {}, 834 | "outputs": [], 835 | "source": [ 836 | "getattr(a, 'split')" 837 | ] 838 | }, 839 | { 840 | "cell_type": "markdown", 841 | "metadata": {}, 842 | "source": [ 843 | "#### Duck typing" 844 | ] 845 | }, 846 | { 847 | "cell_type": "code", 848 | "execution_count": null, 849 | "metadata": {}, 850 | "outputs": [], 851 | "source": [ 852 | "def isiterable(obj):\n", 853 | " try:\n", 854 | " iter(obj)\n", 855 | " return True\n", 856 | " except TypeError: # not iterable\n", 857 | " return False" 858 | ] 859 | }, 860 | { 861 | "cell_type": "code", 862 | "execution_count": null, 863 | "metadata": {}, 864 | "outputs": [], 865 | "source": [ 866 | "isiterable('a string')\n", 867 | "isiterable([1, 2, 3])\n", 868 | "isiterable(5)" 869 | ] 870 | }, 871 | { 872 | "cell_type": "markdown", 873 | "metadata": {}, 874 | "source": [ 875 | "if not isinstance(x, list) and isiterable(x):\n", 876 | " x = list(x)" 877 | ] 878 | }, 879 | { 880 | "cell_type": "markdown", 881 | "metadata": {}, 882 | "source": [ 883 | "#### Imports" 884 | ] 885 | }, 886 | { 887 | "cell_type": "markdown", 888 | "metadata": {}, 889 | "source": [ 890 | "```python\n", 891 | "# some_module.py\n", 892 | "PI = 3.14159\n", 893 | "\n", 894 | "def f(x):\n", 895 | " return x + 2\n", 896 | "\n", 897 | "def g(a, b):\n", 898 | " return a + b\n", 899 | "```" 900 | ] 901 | }, 902 | { 903 | "cell_type": "markdown", 904 | "metadata": {}, 905 | "source": [ 906 | "import some_module\n", 907 | "result = some_module.f(5)\n", 908 | "pi = some_module.PI" 909 | ] 910 | }, 911 | { 912 | "cell_type": "markdown", 913 | "metadata": {}, 914 | "source": [ 915 | "from some_module import f, g, PI\n", 916 | "result = g(5, PI)" 917 | ] 918 | }, 919 | { 920 | "cell_type": "markdown", 921 | "metadata": {}, 922 | "source": [ 923 | "import some_module as sm\n", 924 | "from some_module import PI as pi, g as gf\n", 925 | "\n", 926 | "r1 = sm.f(pi)\n", 927 | "r2 = gf(6, pi)" 928 | ] 929 | }, 930 | { 931 | "cell_type": "markdown", 932 | "metadata": {}, 933 | "source": [ 934 | "#### Binary operators and comparisons" 935 | ] 936 | }, 937 | { 938 | "cell_type": "code", 939 | "execution_count": null, 940 | "metadata": {}, 941 | "outputs": [], 942 | "source": [ 943 | "5 - 7\n", 944 | "12 + 21.5\n", 945 | "5 <= 2" 946 | ] 947 | }, 948 | { 949 | "cell_type": "code", 950 | "execution_count": null, 951 | "metadata": {}, 952 | "outputs": [], 953 | "source": [ 954 | "a = [1, 2, 3]\n", 955 | "b = a\n", 956 | "c = list(a)\n", 957 | "a is b\n", 958 | "a is not c" 959 | ] 960 | }, 961 | { 962 | "cell_type": "code", 963 | "execution_count": null, 964 | "metadata": {}, 965 | "outputs": [], 966 | "source": [ 967 | "a == c" 968 | ] 969 | }, 970 | { 971 | "cell_type": "code", 972 | "execution_count": null, 973 | "metadata": {}, 974 | "outputs": [], 975 | "source": [ 976 | "a = None\n", 977 | "a is None" 978 | ] 979 | }, 980 | { 981 | "cell_type": "markdown", 982 | "metadata": {}, 983 | "source": [ 984 | "#### Mutable and immutable objects" 985 | ] 986 | }, 987 | { 988 | "cell_type": "code", 989 | "execution_count": null, 990 | "metadata": {}, 991 | "outputs": [], 992 | "source": [ 993 | "a_list = ['foo', 2, [4, 5]]\n", 994 | "a_list[2] = (3, 4)\n", 995 | "a_list" 996 | ] 997 | }, 998 | { 999 | "cell_type": "code", 1000 | "execution_count": null, 1001 | "metadata": {}, 1002 | "outputs": [], 1003 | "source": [ 1004 | "a_tuple = (3, 5, (4, 5))\n", 1005 | "a_tuple[1] = 'four'" 1006 | ] 1007 | }, 1008 | { 1009 | "cell_type": "markdown", 1010 | "metadata": {}, 1011 | "source": [ 1012 | "### Scalar Types" 1013 | ] 1014 | }, 1015 | { 1016 | "cell_type": "markdown", 1017 | "metadata": {}, 1018 | "source": [ 1019 | "#### Numeric types" 1020 | ] 1021 | }, 1022 | { 1023 | "cell_type": "code", 1024 | "execution_count": null, 1025 | "metadata": {}, 1026 | "outputs": [], 1027 | "source": [ 1028 | "ival = 17239871\n", 1029 | "ival ** 6" 1030 | ] 1031 | }, 1032 | { 1033 | "cell_type": "code", 1034 | "execution_count": null, 1035 | "metadata": {}, 1036 | "outputs": [], 1037 | "source": [ 1038 | "fval = 7.243\n", 1039 | "fval2 = 6.78e-5" 1040 | ] 1041 | }, 1042 | { 1043 | "cell_type": "code", 1044 | "execution_count": null, 1045 | "metadata": {}, 1046 | "outputs": [], 1047 | "source": [ 1048 | "3 / 2" 1049 | ] 1050 | }, 1051 | { 1052 | "cell_type": "code", 1053 | "execution_count": null, 1054 | "metadata": {}, 1055 | "outputs": [], 1056 | "source": [ 1057 | "3 // 2" 1058 | ] 1059 | }, 1060 | { 1061 | "cell_type": "markdown", 1062 | "metadata": {}, 1063 | "source": [ 1064 | "#### Strings" 1065 | ] 1066 | }, 1067 | { 1068 | "cell_type": "markdown", 1069 | "metadata": {}, 1070 | "source": [ 1071 | "a = 'one way of writing a string'\n", 1072 | "b = \"another way\"" 1073 | ] 1074 | }, 1075 | { 1076 | "cell_type": "code", 1077 | "execution_count": null, 1078 | "metadata": {}, 1079 | "outputs": [], 1080 | "source": [ 1081 | "c = \"\"\"\n", 1082 | "This is a longer string that\n", 1083 | "spans multiple lines\n", 1084 | "\"\"\"" 1085 | ] 1086 | }, 1087 | { 1088 | "cell_type": "code", 1089 | "execution_count": null, 1090 | "metadata": {}, 1091 | "outputs": [], 1092 | "source": [ 1093 | "c.count('\\n')" 1094 | ] 1095 | }, 1096 | { 1097 | "cell_type": "code", 1098 | "execution_count": null, 1099 | "metadata": {}, 1100 | "outputs": [], 1101 | "source": [ 1102 | "a = 'this is a string'\n", 1103 | "a[10] = 'f'\n", 1104 | "b = a.replace('string', 'longer string')\n", 1105 | "b" 1106 | ] 1107 | }, 1108 | { 1109 | "cell_type": "code", 1110 | "execution_count": null, 1111 | "metadata": {}, 1112 | "outputs": [], 1113 | "source": [ 1114 | "a" 1115 | ] 1116 | }, 1117 | { 1118 | "cell_type": "code", 1119 | "execution_count": null, 1120 | "metadata": {}, 1121 | "outputs": [], 1122 | "source": [ 1123 | "a = 5.6\n", 1124 | "s = str(a)\n", 1125 | "print(s)" 1126 | ] 1127 | }, 1128 | { 1129 | "cell_type": "code", 1130 | "execution_count": null, 1131 | "metadata": {}, 1132 | "outputs": [], 1133 | "source": [ 1134 | "s = 'python'\n", 1135 | "list(s)\n", 1136 | "s[:3]" 1137 | ] 1138 | }, 1139 | { 1140 | "cell_type": "code", 1141 | "execution_count": null, 1142 | "metadata": {}, 1143 | "outputs": [], 1144 | "source": [ 1145 | "s = '12\\\\34'\n", 1146 | "print(s)" 1147 | ] 1148 | }, 1149 | { 1150 | "cell_type": "code", 1151 | "execution_count": null, 1152 | "metadata": {}, 1153 | "outputs": [], 1154 | "source": [ 1155 | "s = r'this\\has\\no\\special\\characters'\n", 1156 | "s" 1157 | ] 1158 | }, 1159 | { 1160 | "cell_type": "code", 1161 | "execution_count": null, 1162 | "metadata": {}, 1163 | "outputs": [], 1164 | "source": [ 1165 | "a = 'this is the first half '\n", 1166 | "b = 'and this is the second half'\n", 1167 | "a + b" 1168 | ] 1169 | }, 1170 | { 1171 | "cell_type": "code", 1172 | "execution_count": null, 1173 | "metadata": {}, 1174 | "outputs": [], 1175 | "source": [ 1176 | "template = '{0:.2f} {1:s} are worth US${2:d}'" 1177 | ] 1178 | }, 1179 | { 1180 | "cell_type": "code", 1181 | "execution_count": null, 1182 | "metadata": {}, 1183 | "outputs": [], 1184 | "source": [ 1185 | "template.format(4.5560, 'Argentine Pesos', 1)" 1186 | ] 1187 | }, 1188 | { 1189 | "cell_type": "markdown", 1190 | "metadata": {}, 1191 | "source": [ 1192 | "#### Bytes and Unicode" 1193 | ] 1194 | }, 1195 | { 1196 | "cell_type": "code", 1197 | "execution_count": null, 1198 | "metadata": {}, 1199 | "outputs": [], 1200 | "source": [ 1201 | "val = \"español\"\n", 1202 | "val" 1203 | ] 1204 | }, 1205 | { 1206 | "cell_type": "code", 1207 | "execution_count": null, 1208 | "metadata": {}, 1209 | "outputs": [], 1210 | "source": [ 1211 | "val_utf8 = val.encode('utf-8')\n", 1212 | "val_utf8\n", 1213 | "type(val_utf8)" 1214 | ] 1215 | }, 1216 | { 1217 | "cell_type": "code", 1218 | "execution_count": null, 1219 | "metadata": {}, 1220 | "outputs": [], 1221 | "source": [ 1222 | "val_utf8.decode('utf-8')" 1223 | ] 1224 | }, 1225 | { 1226 | "cell_type": "code", 1227 | "execution_count": null, 1228 | "metadata": {}, 1229 | "outputs": [], 1230 | "source": [ 1231 | "val.encode('latin1')\n", 1232 | "val.encode('utf-16')\n", 1233 | "val.encode('utf-16le')" 1234 | ] 1235 | }, 1236 | { 1237 | "cell_type": "code", 1238 | "execution_count": null, 1239 | "metadata": {}, 1240 | "outputs": [], 1241 | "source": [ 1242 | "bytes_val = b'this is bytes'\n", 1243 | "bytes_val\n", 1244 | "decoded = bytes_val.decode('utf8')\n", 1245 | "decoded # this is str (Unicode) now" 1246 | ] 1247 | }, 1248 | { 1249 | "cell_type": "markdown", 1250 | "metadata": {}, 1251 | "source": [ 1252 | "#### Booleans" 1253 | ] 1254 | }, 1255 | { 1256 | "cell_type": "code", 1257 | "execution_count": null, 1258 | "metadata": {}, 1259 | "outputs": [], 1260 | "source": [ 1261 | "True and True\n", 1262 | "False or True" 1263 | ] 1264 | }, 1265 | { 1266 | "cell_type": "markdown", 1267 | "metadata": {}, 1268 | "source": [ 1269 | "#### Type casting" 1270 | ] 1271 | }, 1272 | { 1273 | "cell_type": "code", 1274 | "execution_count": null, 1275 | "metadata": {}, 1276 | "outputs": [], 1277 | "source": [ 1278 | "s = '3.14159'\n", 1279 | "fval = float(s)\n", 1280 | "type(fval)\n", 1281 | "int(fval)\n", 1282 | "bool(fval)\n", 1283 | "bool(0)" 1284 | ] 1285 | }, 1286 | { 1287 | "cell_type": "markdown", 1288 | "metadata": {}, 1289 | "source": [ 1290 | "#### None" 1291 | ] 1292 | }, 1293 | { 1294 | "cell_type": "code", 1295 | "execution_count": null, 1296 | "metadata": {}, 1297 | "outputs": [], 1298 | "source": [ 1299 | "a = None\n", 1300 | "a is None\n", 1301 | "b = 5\n", 1302 | "b is not None" 1303 | ] 1304 | }, 1305 | { 1306 | "cell_type": "markdown", 1307 | "metadata": {}, 1308 | "source": [ 1309 | "def add_and_maybe_multiply(a, b, c=None):\n", 1310 | " result = a + b\n", 1311 | "\n", 1312 | " if c is not None:\n", 1313 | " result = result * c\n", 1314 | "\n", 1315 | " return result" 1316 | ] 1317 | }, 1318 | { 1319 | "cell_type": "code", 1320 | "execution_count": null, 1321 | "metadata": {}, 1322 | "outputs": [], 1323 | "source": [ 1324 | "type(None)" 1325 | ] 1326 | }, 1327 | { 1328 | "cell_type": "markdown", 1329 | "metadata": {}, 1330 | "source": [ 1331 | "#### Dates and times" 1332 | ] 1333 | }, 1334 | { 1335 | "cell_type": "code", 1336 | "execution_count": null, 1337 | "metadata": {}, 1338 | "outputs": [], 1339 | "source": [ 1340 | "from datetime import datetime, date, time\n", 1341 | "dt = datetime(2011, 10, 29, 20, 30, 21)\n", 1342 | "dt.day\n", 1343 | "dt.minute" 1344 | ] 1345 | }, 1346 | { 1347 | "cell_type": "code", 1348 | "execution_count": null, 1349 | "metadata": {}, 1350 | "outputs": [], 1351 | "source": [ 1352 | "dt.date()\n", 1353 | "dt.time()" 1354 | ] 1355 | }, 1356 | { 1357 | "cell_type": "code", 1358 | "execution_count": null, 1359 | "metadata": {}, 1360 | "outputs": [], 1361 | "source": [ 1362 | "dt.strftime('%m/%d/%Y %H:%M')" 1363 | ] 1364 | }, 1365 | { 1366 | "cell_type": "code", 1367 | "execution_count": null, 1368 | "metadata": {}, 1369 | "outputs": [], 1370 | "source": [ 1371 | "datetime.strptime('20091031', '%Y%m%d')" 1372 | ] 1373 | }, 1374 | { 1375 | "cell_type": "code", 1376 | "execution_count": null, 1377 | "metadata": {}, 1378 | "outputs": [], 1379 | "source": [ 1380 | "dt.replace(minute=0, second=0)" 1381 | ] 1382 | }, 1383 | { 1384 | "cell_type": "code", 1385 | "execution_count": null, 1386 | "metadata": {}, 1387 | "outputs": [], 1388 | "source": [ 1389 | "dt2 = datetime(2011, 11, 15, 22, 30)\n", 1390 | "delta = dt2 - dt\n", 1391 | "delta\n", 1392 | "type(delta)" 1393 | ] 1394 | }, 1395 | { 1396 | "cell_type": "code", 1397 | "execution_count": null, 1398 | "metadata": {}, 1399 | "outputs": [], 1400 | "source": [ 1401 | "dt\n", 1402 | "dt + delta" 1403 | ] 1404 | }, 1405 | { 1406 | "cell_type": "markdown", 1407 | "metadata": {}, 1408 | "source": [ 1409 | "### Control Flow" 1410 | ] 1411 | }, 1412 | { 1413 | "cell_type": "markdown", 1414 | "metadata": {}, 1415 | "source": [ 1416 | "#### if, elif, and else" 1417 | ] 1418 | }, 1419 | { 1420 | "cell_type": "markdown", 1421 | "metadata": {}, 1422 | "source": [ 1423 | "if x < 0:\n", 1424 | " print('It's negative')" 1425 | ] 1426 | }, 1427 | { 1428 | "cell_type": "markdown", 1429 | "metadata": {}, 1430 | "source": [ 1431 | "if x < 0:\n", 1432 | " print('It's negative')\n", 1433 | "elif x == 0:\n", 1434 | " print('Equal to zero')\n", 1435 | "elif 0 < x < 5:\n", 1436 | " print('Positive but smaller than 5')\n", 1437 | "else:\n", 1438 | " print('Positive and larger than or equal to 5')" 1439 | ] 1440 | }, 1441 | { 1442 | "cell_type": "code", 1443 | "execution_count": null, 1444 | "metadata": {}, 1445 | "outputs": [], 1446 | "source": [ 1447 | "a = 5; b = 7\n", 1448 | "c = 8; d = 4\n", 1449 | "if a < b or c > d:\n", 1450 | " print('Made it')" 1451 | ] 1452 | }, 1453 | { 1454 | "cell_type": "code", 1455 | "execution_count": null, 1456 | "metadata": {}, 1457 | "outputs": [], 1458 | "source": [ 1459 | "4 > 3 > 2 > 1" 1460 | ] 1461 | }, 1462 | { 1463 | "cell_type": "markdown", 1464 | "metadata": {}, 1465 | "source": [ 1466 | "#### for loops" 1467 | ] 1468 | }, 1469 | { 1470 | "cell_type": "markdown", 1471 | "metadata": {}, 1472 | "source": [ 1473 | "for value in collection:\n", 1474 | " # do something with value" 1475 | ] 1476 | }, 1477 | { 1478 | "cell_type": "markdown", 1479 | "metadata": {}, 1480 | "source": [ 1481 | "sequence = [1, 2, None, 4, None, 5]\n", 1482 | "total = 0\n", 1483 | "for value in sequence:\n", 1484 | " if value is None:\n", 1485 | " continue\n", 1486 | " total += value" 1487 | ] 1488 | }, 1489 | { 1490 | "cell_type": "markdown", 1491 | "metadata": {}, 1492 | "source": [ 1493 | "sequence = [1, 2, 0, 4, 6, 5, 2, 1]\n", 1494 | "total_until_5 = 0\n", 1495 | "for value in sequence:\n", 1496 | " if value == 5:\n", 1497 | " break\n", 1498 | " total_until_5 += value" 1499 | ] 1500 | }, 1501 | { 1502 | "cell_type": "code", 1503 | "execution_count": null, 1504 | "metadata": {}, 1505 | "outputs": [], 1506 | "source": [ 1507 | "for i in range(4):\n", 1508 | " for j in range(4):\n", 1509 | " if j > i:\n", 1510 | " break\n", 1511 | " print((i, j))" 1512 | ] 1513 | }, 1514 | { 1515 | "cell_type": "markdown", 1516 | "metadata": {}, 1517 | "source": [ 1518 | "for a, b, c in iterator:\n", 1519 | " # do something" 1520 | ] 1521 | }, 1522 | { 1523 | "cell_type": "markdown", 1524 | "metadata": {}, 1525 | "source": [ 1526 | "#### while loops" 1527 | ] 1528 | }, 1529 | { 1530 | "cell_type": "markdown", 1531 | "metadata": {}, 1532 | "source": [ 1533 | "x = 256\n", 1534 | "total = 0\n", 1535 | "while x > 0:\n", 1536 | " if total > 500:\n", 1537 | " break\n", 1538 | " total += x\n", 1539 | " x = x // 2" 1540 | ] 1541 | }, 1542 | { 1543 | "cell_type": "markdown", 1544 | "metadata": {}, 1545 | "source": [ 1546 | "#### pass" 1547 | ] 1548 | }, 1549 | { 1550 | "cell_type": "markdown", 1551 | "metadata": {}, 1552 | "source": [ 1553 | "if x < 0:\n", 1554 | " print('negative!')\n", 1555 | "elif x == 0:\n", 1556 | " # TODO: put something smart here\n", 1557 | " pass\n", 1558 | "else:\n", 1559 | " print('positive!')" 1560 | ] 1561 | }, 1562 | { 1563 | "cell_type": "markdown", 1564 | "metadata": {}, 1565 | "source": [ 1566 | "#### range" 1567 | ] 1568 | }, 1569 | { 1570 | "cell_type": "code", 1571 | "execution_count": null, 1572 | "metadata": {}, 1573 | "outputs": [], 1574 | "source": [ 1575 | "range(10)\n", 1576 | "list(range(10))" 1577 | ] 1578 | }, 1579 | { 1580 | "cell_type": "code", 1581 | "execution_count": null, 1582 | "metadata": {}, 1583 | "outputs": [], 1584 | "source": [ 1585 | "list(range(0, 20, 2))\n", 1586 | "list(range(5, 0, -1))" 1587 | ] 1588 | }, 1589 | { 1590 | "cell_type": "markdown", 1591 | "metadata": {}, 1592 | "source": [ 1593 | "seq = [1, 2, 3, 4]\n", 1594 | "for i in range(len(seq)):\n", 1595 | " val = seq[i]" 1596 | ] 1597 | }, 1598 | { 1599 | "cell_type": "markdown", 1600 | "metadata": {}, 1601 | "source": [ 1602 | "sum = 0\n", 1603 | "for i in range(100000):\n", 1604 | " # % is the modulo operator\n", 1605 | " if i % 3 == 0 or i % 5 == 0:\n", 1606 | " sum += i" 1607 | ] 1608 | }, 1609 | { 1610 | "cell_type": "markdown", 1611 | "metadata": {}, 1612 | "source": [ 1613 | "#### Ternary expressions" 1614 | ] 1615 | }, 1616 | { 1617 | "cell_type": "markdown", 1618 | "metadata": {}, 1619 | "source": [ 1620 | "value = " 1621 | ] 1622 | }, 1623 | { 1624 | "cell_type": "markdown", 1625 | "metadata": {}, 1626 | "source": [ 1627 | "if " 1628 | ] 1629 | }, 1630 | { 1631 | "cell_type": "code", 1632 | "execution_count": null, 1633 | "metadata": {}, 1634 | "outputs": [], 1635 | "source": [ 1636 | "x = 5\n", 1637 | "'Non-negative' if x >= 0 else 'Negative'" 1638 | ] 1639 | } 1640 | ], 1641 | "metadata": { 1642 | "kernelspec": { 1643 | "display_name": "Python 3", 1644 | "language": "python", 1645 | "name": "python3" 1646 | }, 1647 | "language_info": { 1648 | "codemirror_mode": { 1649 | "name": "ipython", 1650 | "version": 3 1651 | }, 1652 | "file_extension": ".py", 1653 | "mimetype": "text/x-python", 1654 | "name": "python", 1655 | "nbconvert_exporter": "python", 1656 | "pygments_lexer": "ipython3", 1657 | "version": "3.6.8" 1658 | } 1659 | }, 1660 | "nbformat": 4, 1661 | "nbformat_minor": 1 1662 | } 1663 | -------------------------------------------------------------------------------- /.ipynb_checkpoints/module-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 7, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "def cm2m(value):\n", 10 | " value = value/100\n", 11 | " print(value)\n", 12 | " \n", 13 | "def m2cm(value):\n", 14 | " value = value*100\n", 15 | " print(value)\n" 16 | ] 17 | }, 18 | { 19 | "cell_type": "code", 20 | "execution_count": null, 21 | "metadata": {}, 22 | "outputs": [], 23 | "source": [] 24 | } 25 | ], 26 | "metadata": { 27 | "kernelspec": { 28 | "display_name": "Python 3", 29 | "language": "python", 30 | "name": "python3" 31 | }, 32 | "language_info": { 33 | "codemirror_mode": { 34 | "name": "ipython", 35 | "version": 3 36 | }, 37 | "file_extension": ".py", 38 | "mimetype": "text/x-python", 39 | "name": "python", 40 | "nbconvert_exporter": "python", 41 | "pygments_lexer": "ipython3", 42 | "version": "3.6.8" 43 | } 44 | }, 45 | "nbformat": 4, 46 | "nbformat_minor": 2 47 | } 48 | -------------------------------------------------------------------------------- /Python-1.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Python Basic\n", 8 | "\n" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 6, 14 | "metadata": { 15 | "scrolled": true 16 | }, 17 | "outputs": [ 18 | { 19 | "name": "stdout", 20 | "output_type": "stream", 21 | "text": [ 22 | "what is name ?mosh\n", 23 | "HI mosh\n" 24 | ] 25 | } 26 | ], 27 | "source": [ 28 | "name = input(\"what is name ?\")\n", 29 | "print('HI ' +name)" 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": 8, 35 | "metadata": {}, 36 | "outputs": [ 37 | { 38 | "name": "stdout", 39 | "output_type": "stream", 40 | "text": [ 41 | "what is your birthdate ? 2000\n", 42 | "19\n" 43 | ] 44 | } 45 | ], 46 | "source": [ 47 | "name = input('what is your birthyear ? ')\n", 48 | "year = 2019 -int(name);\n", 49 | "print(year)" 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "metadata": {}, 55 | "source": [ 56 | "# Type" 57 | ] 58 | }, 59 | { 60 | "cell_type": "code", 61 | "execution_count": 9, 62 | "metadata": {}, 63 | "outputs": [ 64 | { 65 | "name": "stdout", 66 | "output_type": "stream", 67 | "text": [ 68 | "\n" 69 | ] 70 | } 71 | ], 72 | "source": [ 73 | "#type \n", 74 | "\n", 75 | "print(type(name))" 76 | ] 77 | }, 78 | { 79 | "cell_type": "code", 80 | "execution_count": 18, 81 | "metadata": {}, 82 | "outputs": [ 83 | { 84 | "name": "stdout", 85 | "output_type": "stream", 86 | "text": [ 87 | "what is weight 45\n", 88 | "20.25\n" 89 | ] 90 | } 91 | ], 92 | "source": [ 93 | "weight = input(\"what is weight \")\n", 94 | "final = int(weight)*0.45\n", 95 | "print(final)" 96 | ] 97 | }, 98 | { 99 | "cell_type": "code", 100 | "execution_count": 26, 101 | "metadata": {}, 102 | "outputs": [ 103 | { 104 | "name": "stdout", 105 | "output_type": "stream", 106 | "text": [ 107 | "you're awesome\n", 108 | "im \"Hritik\"\n", 109 | "\n", 110 | " Hii buddy \n", 111 | "\n", 112 | " im Hritik \n", 113 | "\n", 114 | " you look awesome \n", 115 | "\n", 116 | " thank you,\n", 117 | " \n" 118 | ] 119 | } 120 | ], 121 | "source": [ 122 | "#if want to use this type statement -> year's then we have to use double quotes \"\"\n", 123 | "string = \"you're awesome\"\n", 124 | "print(string)\n", 125 | "\n", 126 | "# if want to assign \"important msg\" like this we have to use single quote ''\n", 127 | "str = 'im \"Hritik\"'\n", 128 | "print(str)\n", 129 | "\n", 130 | "# for multitline string ''' % ''' for sending mail \n", 131 | "\n", 132 | "mail = '''\n", 133 | " Hii buddy \n", 134 | "\n", 135 | " im Hritik \n", 136 | "\n", 137 | " you look awesome \n", 138 | "\n", 139 | " thank you,\n", 140 | " '''\n", 141 | "\n", 142 | "print(mail)\n" 143 | ] 144 | }, 145 | { 146 | "cell_type": "code", 147 | "execution_count": 30, 148 | "metadata": {}, 149 | "outputs": [ 150 | { 151 | "name": "stdout", 152 | "output_type": "stream", 153 | "text": [ 154 | "p\n", 155 | "r\n", 156 | "python beginners\n", 157 | "python beginners\n", 158 | "pytho\n", 159 | "pytho\n", 160 | "yt\n", 161 | "ython beginner\n" 162 | ] 163 | } 164 | ], 165 | "source": [ 166 | "course = 'python beginners'\n", 167 | "print(course[0])\n", 168 | "print(course[-2])\n", 169 | "print(course[0:])\n", 170 | "print(course[:])\n", 171 | "print(course[:5])\n", 172 | "print(course[0:5])\n", 173 | "print(course[1:3]) #exclude 3 only takes 1,2\n", 174 | "\n", 175 | "print(course[1:-1]) # exclude -1 " 176 | ] 177 | }, 178 | { 179 | "cell_type": "markdown", 180 | "metadata": {}, 181 | "source": [ 182 | "# Inbuilt - Function" 183 | ] 184 | }, 185 | { 186 | "cell_type": "code", 187 | "execution_count": 32, 188 | "metadata": {}, 189 | "outputs": [ 190 | { 191 | "name": "stdout", 192 | "output_type": "stream", 193 | "text": [ 194 | "9\n" 195 | ] 196 | } 197 | ], 198 | "source": [ 199 | "#length of string including space\n", 200 | "c = 'hii buddy'\n", 201 | "print(len(c))" 202 | ] 203 | }, 204 | { 205 | "cell_type": "code", 206 | "execution_count": 45, 207 | "metadata": {}, 208 | "outputs": [ 209 | { 210 | "name": "stdout", 211 | "output_type": "stream", 212 | "text": [ 213 | "python is very imp lang\n", 214 | "PYTHON IS VERY IMP LANG\n", 215 | "2\n", 216 | "2\n", 217 | "Python Is Very Imp Lang\n", 218 | "python are very imp lang\n" 219 | ] 220 | } 221 | ], 222 | "source": [ 223 | "#various function \n", 224 | "msg = 'python is very imp lang'\n", 225 | "print(msg.lower())\n", 226 | "print(msg.upper())\n", 227 | "print(msg.count('i'))\n", 228 | "print(msg.find('t'))\n", 229 | "print(msg.title())\n", 230 | "print(msg.replace('is','are'))" 231 | ] 232 | }, 233 | { 234 | "cell_type": "code", 235 | "execution_count": 46, 236 | "metadata": {}, 237 | "outputs": [ 238 | { 239 | "name": "stdout", 240 | "output_type": "stream", 241 | "text": [ 242 | "22\n" 243 | ] 244 | } 245 | ], 246 | "source": [ 247 | "#ordering \n", 248 | "# exp > (mul or div) > (add or sub)\n", 249 | "exp = 10 + 3*2**2\n", 250 | "print(exp)" 251 | ] 252 | }, 253 | { 254 | "cell_type": "markdown", 255 | "metadata": {}, 256 | "source": [ 257 | "# Math function" 258 | ] 259 | }, 260 | { 261 | "cell_type": "code", 262 | "execution_count": 49, 263 | "metadata": {}, 264 | "outputs": [ 265 | { 266 | "name": "stdout", 267 | "output_type": "stream", 268 | "text": [ 269 | "6\n", 270 | "8\n" 271 | ] 272 | } 273 | ], 274 | "source": [ 275 | "#Math function\n", 276 | "# 1) round\n", 277 | "x = 6.5\n", 278 | "y = 7.66\n", 279 | "print(round(x))\n", 280 | "print(round(y))" 281 | ] 282 | }, 283 | { 284 | "cell_type": "code", 285 | "execution_count": 51, 286 | "metadata": {}, 287 | "outputs": [ 288 | { 289 | "name": "stdout", 290 | "output_type": "stream", 291 | "text": [ 292 | "3.5\n" 293 | ] 294 | } 295 | ], 296 | "source": [ 297 | "# 2) abs -> return positive no.\n", 298 | "x = -3.5\n", 299 | "print(abs(x))" 300 | ] 301 | }, 302 | { 303 | "cell_type": "code", 304 | "execution_count": 61, 305 | "metadata": {}, 306 | "outputs": [ 307 | { 308 | "name": "stdout", 309 | "output_type": "stream", 310 | "text": [ 311 | "3\n", 312 | "2\n" 313 | ] 314 | } 315 | ], 316 | "source": [ 317 | "# 3) Mathametical function\n", 318 | "import math\n", 319 | "pi = 3.142\n", 320 | "math.cos((60*pi)/180)\n", 321 | "\n", 322 | "# ceil and floor\n", 323 | "print(math.ceil(2.9))\n", 324 | "print(math.floor(2.9))\n", 325 | "\n", 326 | "#thier are many more maths module" 327 | ] 328 | }, 329 | { 330 | "cell_type": "markdown", 331 | "metadata": {}, 332 | "source": [ 333 | "# If - Statement" 334 | ] 335 | }, 336 | { 337 | "cell_type": "code", 338 | "execution_count": 81, 339 | "metadata": {}, 340 | "outputs": [ 341 | { 342 | "name": "stdout", 343 | "output_type": "stream", 344 | "text": [ 345 | "nothing\n", 346 | "SUM OF X AND Y : 15\n" 347 | ] 348 | } 349 | ], 350 | "source": [ 351 | "#if statement\n", 352 | "\n", 353 | "x = 5\n", 354 | "y = 10\n", 355 | "\n", 356 | "if (x>y):\n", 357 | " print(\"truee\")\n", 358 | "elif (x==y):\n", 359 | " print(\"falsee\")\n", 360 | "else:\n", 361 | " print(\"nothing\")\n", 362 | " \n", 363 | "print(f\"SUM OF X AND Y : {x+y}\")\n" 364 | ] 365 | }, 366 | { 367 | "cell_type": "markdown", 368 | "metadata": {}, 369 | "source": [ 370 | "# Format" 371 | ] 372 | }, 373 | { 374 | "cell_type": "code", 375 | "execution_count": null, 376 | "metadata": {}, 377 | "outputs": [], 378 | "source": [ 379 | "x = \"Hii\"\n", 380 | "y = 'Hritik {}'\n", 381 | "z = 'Jaiswal'\n", 382 | "print(f\"sum of string is x + y : {x+y}\")\n", 383 | "print(y.format(z))" 384 | ] 385 | }, 386 | { 387 | "cell_type": "code", 388 | "execution_count": 111, 389 | "metadata": {}, 390 | "outputs": [ 391 | { 392 | "name": "stdout", 393 | "output_type": "stream", 394 | "text": [ 395 | "True\n" 396 | ] 397 | } 398 | ], 399 | "source": [ 400 | "# we can use 'and' & 'or' in if statement\n", 401 | "a=2 \n", 402 | "b=3\n", 403 | "c=4\n", 404 | "if (ab):\n", 405 | " print('True')\n", 406 | "elif (a==b) or (c>a):\n", 407 | " print('Truee')\n", 408 | "elif (b>a) and not(b>c):\n", 409 | " print('Trueee')\n", 410 | "else:\n", 411 | " print('false')\n", 412 | " " 413 | ] 414 | }, 415 | { 416 | "cell_type": "code", 417 | "execution_count": 113, 418 | "metadata": {}, 419 | "outputs": [ 420 | { 421 | "name": "stdout", 422 | "output_type": "stream", 423 | "text": [ 424 | "Weight :45\n", 425 | "(L)bs or (K)gv\n", 426 | "100.0\n" 427 | ] 428 | } 429 | ], 430 | "source": [ 431 | "#Exercise\n", 432 | "\n", 433 | "weight = int(input('Weight :'))\n", 434 | "unit = input('(L)bs or (K)g')\n", 435 | "if unit.lower()=='l' or unit.upper()=='L':\n", 436 | " c = weight*0.45;\n", 437 | "else:\n", 438 | " c = weight/0.45;\n", 439 | "print(c)" 440 | ] 441 | }, 442 | { 443 | "cell_type": "markdown", 444 | "metadata": {}, 445 | "source": [ 446 | "# While loop" 447 | ] 448 | }, 449 | { 450 | "cell_type": "code", 451 | "execution_count": 116, 452 | "metadata": {}, 453 | "outputs": [ 454 | { 455 | "name": "stdout", 456 | "output_type": "stream", 457 | "text": [ 458 | "*\n", 459 | "**\n", 460 | "***\n", 461 | "****\n" 462 | ] 463 | } 464 | ], 465 | "source": [ 466 | "#while\n", 467 | "\n", 468 | "i=1\n", 469 | "while (i<5):\n", 470 | " print('*'*i)\n", 471 | " i+=1\n", 472 | " " 473 | ] 474 | }, 475 | { 476 | "cell_type": "markdown", 477 | "metadata": {}, 478 | "source": [ 479 | "# for loop" 480 | ] 481 | }, 482 | { 483 | "cell_type": "code", 484 | "execution_count": 117, 485 | "metadata": {}, 486 | "outputs": [ 487 | { 488 | "name": "stdout", 489 | "output_type": "stream", 490 | "text": [ 491 | "T\n", 492 | "e\n", 493 | "a\n", 494 | "c\n", 495 | "h\n", 496 | "e\n", 497 | "r\n" 498 | ] 499 | } 500 | ], 501 | "source": [ 502 | "#for loop\n", 503 | "for item in 'Teacher':\n", 504 | " print(item)" 505 | ] 506 | }, 507 | { 508 | "cell_type": "code", 509 | "execution_count": 128, 510 | "metadata": {}, 511 | "outputs": [ 512 | { 513 | "name": "stdout", 514 | "output_type": "stream", 515 | "text": [ 516 | "hii\n", 517 | "buddy \n", 518 | "whats\n", 519 | "up\n", 520 | "-----------------\n", 521 | "0\n", 522 | "1\n", 523 | "2\n", 524 | "3\n", 525 | "-----------------\n", 526 | "2\n", 527 | "3\n", 528 | "4\n", 529 | "5\n", 530 | "6\n", 531 | "7\n", 532 | "-----------------\n", 533 | "2\n", 534 | "5\n", 535 | "-----------------\n", 536 | "5\n", 537 | "6\n", 538 | "7\n", 539 | "8\n" 540 | ] 541 | } 542 | ], 543 | "source": [ 544 | "for i in ['hii','buddy ','whats','up']:\n", 545 | " print(i)\n", 546 | "print('-----------------')\n", 547 | "for i in range(4):\n", 548 | " print(i)\n", 549 | "print('-----------------')\n", 550 | "for i in range(2,8):\n", 551 | " print(i)\n", 552 | "print('-----------------')\n", 553 | "for i in range(2,8,3):\n", 554 | " print(i)\n", 555 | "print('-----------------')\n", 556 | "for i in [5,6,7,8]:\n", 557 | " print(i)" 558 | ] 559 | }, 560 | { 561 | "cell_type": "code", 562 | "execution_count": 132, 563 | "metadata": {}, 564 | "outputs": [ 565 | { 566 | "name": "stdout", 567 | "output_type": "stream", 568 | "text": [ 569 | "14\n", 570 | "-----------\n", 571 | "14\n" 572 | ] 573 | } 574 | ], 575 | "source": [ 576 | "r = [2,3,4,5]\n", 577 | "total = 0\n", 578 | "for i in r:\n", 579 | " total+=i\n", 580 | "print(total)\n", 581 | "print('-----------')\n", 582 | "r = [2,3,4,5]\n", 583 | "e = sum(r)\n", 584 | "print(e)" 585 | ] 586 | }, 587 | { 588 | "cell_type": "code", 589 | "execution_count": 134, 590 | "metadata": {}, 591 | "outputs": [ 592 | { 593 | "name": "stdout", 594 | "output_type": "stream", 595 | "text": [ 596 | "(0,0)\n", 597 | "(0,1)\n", 598 | "(0,2)\n", 599 | "(1,0)\n", 600 | "(1,1)\n", 601 | "(1,2)\n", 602 | "(2,0)\n", 603 | "(2,1)\n", 604 | "(2,2)\n", 605 | "(3,0)\n", 606 | "(3,1)\n", 607 | "(3,2)\n" 608 | ] 609 | } 610 | ], 611 | "source": [ 612 | "for i in range(4):\n", 613 | " for j in range(3):\n", 614 | " print(f'({i},{j})')" 615 | ] 616 | }, 617 | { 618 | "cell_type": "code", 619 | "execution_count": 137, 620 | "metadata": {}, 621 | "outputs": [ 622 | { 623 | "name": "stdout", 624 | "output_type": "stream", 625 | "text": [ 626 | "$\n", 627 | "$$\n", 628 | "$$$\n", 629 | "$$$$\n", 630 | "$$$$$\n" 631 | ] 632 | } 633 | ], 634 | "source": [ 635 | "#array\n", 636 | "num = [1,2,3,4,5]\n", 637 | "for i in num:\n", 638 | " print('$'*i)" 639 | ] 640 | }, 641 | { 642 | "cell_type": "code", 643 | "execution_count": 143, 644 | "metadata": {}, 645 | "outputs": [ 646 | { 647 | "name": "stdout", 648 | "output_type": "stream", 649 | "text": [ 650 | "ab \n", 651 | "ae\n" 652 | ] 653 | } 654 | ], 655 | "source": [ 656 | "name = ['ab ','ac','ad','ae']\n", 657 | "print(name[0])\n", 658 | "print(name[-1])" 659 | ] 660 | }, 661 | { 662 | "cell_type": "markdown", 663 | "metadata": {}, 664 | "source": [ 665 | "# List" 666 | ] 667 | }, 668 | { 669 | "cell_type": "code", 670 | "execution_count": 146, 671 | "metadata": {}, 672 | "outputs": [ 673 | { 674 | "name": "stdout", 675 | "output_type": "stream", 676 | "text": [ 677 | "[1, 2, 3]\n", 678 | "[4, 5, 6]\n", 679 | "[7, 8, 9]\n", 680 | "-----print individual item-----\n", 681 | "1\n", 682 | "2\n", 683 | "3\n", 684 | "4\n", 685 | "5\n", 686 | "6\n", 687 | "7\n", 688 | "8\n", 689 | "9\n" 690 | ] 691 | } 692 | ], 693 | "source": [ 694 | "#2D-List \n", 695 | "matrix = [[1,2,3],[4,5,6],[7,8,9]]\n", 696 | "for i in matrix:\n", 697 | " print(i)\n", 698 | "print('-----print individual item-----')\n", 699 | "for i in matrix:\n", 700 | " for j in i:\n", 701 | " print(j)" 702 | ] 703 | }, 704 | { 705 | "cell_type": "markdown", 706 | "metadata": {}, 707 | "source": [ 708 | "# Inbuilt - Function" 709 | ] 710 | }, 711 | { 712 | "cell_type": "code", 713 | "execution_count": 158, 714 | "metadata": {}, 715 | "outputs": [ 716 | { 717 | "name": "stdout", 718 | "output_type": "stream", 719 | "text": [ 720 | "-----Append---------\n", 721 | "[2, 3, 4, 6, 9]\n", 722 | "-----Insert---------\n", 723 | "[2, 3, 8, 4, 6, 9]\n", 724 | "-----Remove---------\n", 725 | "[2, 3, 4, 6, 9]\n", 726 | "-----pop---------\n", 727 | "[2, 3, 4, 6]\n", 728 | "-----clear---------\n", 729 | "[]\n" 730 | ] 731 | } 732 | ], 733 | "source": [ 734 | "#working with function \n", 735 | "# 1.append 2.insert 3.remove 4.pop 5.clear\n", 736 | "number = [2,3,4,6]\n", 737 | "print('-----Append---------')\n", 738 | "number.append(9)\n", 739 | "print(number)\n", 740 | "print('-----Insert---------')\n", 741 | "number.insert(2,8)\n", 742 | "print(number)\n", 743 | "print('-----Remove---------')\n", 744 | "number.remove(8)\n", 745 | "print(number)\n", 746 | "print('-----pop---------')\n", 747 | "number.pop()\n", 748 | "print(number)\n", 749 | "print('-----clear---------')\n", 750 | "number.clear()\n", 751 | "print(number)" 752 | ] 753 | }, 754 | { 755 | "cell_type": "code", 756 | "execution_count": 162, 757 | "metadata": {}, 758 | "outputs": [ 759 | { 760 | "name": "stdout", 761 | "output_type": "stream", 762 | "text": [ 763 | "2\n", 764 | "2\n" 765 | ] 766 | } 767 | ], 768 | "source": [ 769 | "#index \n", 770 | "list_item = [2,4,6,7,2,4]\n", 771 | "print(list_item.index(6))\n", 772 | "print(list_item.count(2))\n" 773 | ] 774 | }, 775 | { 776 | "cell_type": "code", 777 | "execution_count": 164, 778 | "metadata": {}, 779 | "outputs": [ 780 | { 781 | "name": "stdout", 782 | "output_type": "stream", 783 | "text": [ 784 | "[1, 2, 3, 5, 8]\n", 785 | "[8, 5, 3, 2, 1]\n" 786 | ] 787 | } 788 | ], 789 | "source": [ 790 | "# 1.sort 2.reverse \n", 791 | "item = [3,5,2,8,1]\n", 792 | "item.sort()\n", 793 | "print(item)\n", 794 | "item.reverse()\n", 795 | "print(item)" 796 | ] 797 | }, 798 | { 799 | "cell_type": "code", 800 | "execution_count": 4, 801 | "metadata": {}, 802 | "outputs": [ 803 | { 804 | "name": "stdout", 805 | "output_type": "stream", 806 | "text": [ 807 | "[2, 3, 4, 5]\n" 808 | ] 809 | } 810 | ], 811 | "source": [ 812 | "#list will update if we changing list item before calling copy function ,\n", 813 | "# but list will not be change when u are appending and deleting after copy function\n", 814 | "a = [2,3,4,5]\n", 815 | "b = a.copy()\n", 816 | "a.append(10)\n", 817 | "print(b)" 818 | ] 819 | }, 820 | { 821 | "cell_type": "code", 822 | "execution_count": 5, 823 | "metadata": {}, 824 | "outputs": [ 825 | { 826 | "name": "stdout", 827 | "output_type": "stream", 828 | "text": [ 829 | "[2, 3, 4, 5]\n" 830 | ] 831 | } 832 | ], 833 | "source": [ 834 | "#excercise -> remove a duplicate no. from the list\n", 835 | "numbers = [2,3,4,4,3,5]\n", 836 | "unique = []\n", 837 | "\n", 838 | "for i in numbers:\n", 839 | " if i not in unique:\n", 840 | " unique.append(i)\n", 841 | " \n", 842 | "print(unique)" 843 | ] 844 | }, 845 | { 846 | "cell_type": "markdown", 847 | "metadata": {}, 848 | "source": [ 849 | "# tuple" 850 | ] 851 | }, 852 | { 853 | "cell_type": "code", 854 | "execution_count": 2, 855 | "metadata": {}, 856 | "outputs": [ 857 | { 858 | "name": "stdout", 859 | "output_type": "stream", 860 | "text": [ 861 | "1\n" 862 | ] 863 | } 864 | ], 865 | "source": [ 866 | "#tuple -> we can not append , remove , pop , insert , u can not modify your list .\n", 867 | "#only thing u can do -> count , index a item in list\n", 868 | "\n", 869 | "## The main diffrence between tuple and list is :- tuple is immutable and list is mutable\n", 870 | "## that mean we can not change tuple value by modifying it but in list we can do that.\n", 871 | "number = (1,2,3)\n", 872 | "print(number[0])\n", 873 | "\n", 874 | "# this will throw error :\n", 875 | "# number[0] = 5\n" 876 | ] 877 | }, 878 | { 879 | "cell_type": "markdown", 880 | "metadata": {}, 881 | "source": [ 882 | "# Set" 883 | ] 884 | }, 885 | { 886 | "cell_type": "code", 887 | "execution_count": 3, 888 | "metadata": {}, 889 | "outputs": [ 890 | { 891 | "data": { 892 | "text/plain": [ 893 | "{1, 2, 3}" 894 | ] 895 | }, 896 | "execution_count": 3, 897 | "metadata": {}, 898 | "output_type": "execute_result" 899 | } 900 | ], 901 | "source": [ 902 | "{1,2,3}" 903 | ] 904 | }, 905 | { 906 | "cell_type": "code", 907 | "execution_count": 5, 908 | "metadata": {}, 909 | "outputs": [ 910 | { 911 | "data": { 912 | "text/plain": [ 913 | "{1, 2, 4, 5}" 914 | ] 915 | }, 916 | "execution_count": 5, 917 | "metadata": {}, 918 | "output_type": "execute_result" 919 | } 920 | ], 921 | "source": [ 922 | "# display unique value \n", 923 | "{1,1,4,2,2,5}" 924 | ] 925 | }, 926 | { 927 | "cell_type": "code", 928 | "execution_count": 9, 929 | "metadata": {}, 930 | "outputs": [ 931 | { 932 | "data": { 933 | "text/plain": [ 934 | "{1, 2, 4, 8}" 935 | ] 936 | }, 937 | "execution_count": 9, 938 | "metadata": {}, 939 | "output_type": "execute_result" 940 | } 941 | ], 942 | "source": [ 943 | "set([1,2,4,4,8,8,4])" 944 | ] 945 | }, 946 | { 947 | "cell_type": "code", 948 | "execution_count": 10, 949 | "metadata": {}, 950 | "outputs": [], 951 | "source": [ 952 | "# add value to the set\n", 953 | "s = {1,2,3}\n", 954 | "s.add(5)" 955 | ] 956 | }, 957 | { 958 | "cell_type": "code", 959 | "execution_count": 11, 960 | "metadata": {}, 961 | "outputs": [ 962 | { 963 | "data": { 964 | "text/plain": [ 965 | "{1, 2, 3, 5}" 966 | ] 967 | }, 968 | "execution_count": 11, 969 | "metadata": {}, 970 | "output_type": "execute_result" 971 | } 972 | ], 973 | "source": [ 974 | "s" 975 | ] 976 | }, 977 | { 978 | "cell_type": "markdown", 979 | "metadata": {}, 980 | "source": [ 981 | "# Map" 982 | ] 983 | }, 984 | { 985 | "cell_type": "code", 986 | "execution_count": 15, 987 | "metadata": {}, 988 | "outputs": [], 989 | "source": [ 990 | "def times(var):\n", 991 | " return var*2;\n", 992 | " " 993 | ] 994 | }, 995 | { 996 | "cell_type": "code", 997 | "execution_count": 16, 998 | "metadata": {}, 999 | "outputs": [ 1000 | { 1001 | "data": { 1002 | "text/plain": [ 1003 | "4" 1004 | ] 1005 | }, 1006 | "execution_count": 16, 1007 | "metadata": {}, 1008 | "output_type": "execute_result" 1009 | } 1010 | ], 1011 | "source": [ 1012 | "times(2)" 1013 | ] 1014 | }, 1015 | { 1016 | "cell_type": "code", 1017 | "execution_count": 17, 1018 | "metadata": {}, 1019 | "outputs": [ 1020 | { 1021 | "data": { 1022 | "text/plain": [ 1023 | "[2, 4, 6]" 1024 | ] 1025 | }, 1026 | "execution_count": 17, 1027 | "metadata": {}, 1028 | "output_type": "execute_result" 1029 | } 1030 | ], 1031 | "source": [ 1032 | "seq = [1,2,3]\n", 1033 | "\n", 1034 | "list(map(times,seq))" 1035 | ] 1036 | }, 1037 | { 1038 | "cell_type": "markdown", 1039 | "metadata": {}, 1040 | "source": [ 1041 | "# Lambda " 1042 | ] 1043 | }, 1044 | { 1045 | "cell_type": "code", 1046 | "execution_count": 21, 1047 | "metadata": {}, 1048 | "outputs": [], 1049 | "source": [ 1050 | "# instead of writing like this we can write \n", 1051 | "# def times(var):\n", 1052 | "# return var*2;\n", 1053 | "\n", 1054 | "t = lambda var : var*2" 1055 | ] 1056 | }, 1057 | { 1058 | "cell_type": "code", 1059 | "execution_count": 22, 1060 | "metadata": {}, 1061 | "outputs": [ 1062 | { 1063 | "data": { 1064 | "text/plain": [ 1065 | "6" 1066 | ] 1067 | }, 1068 | "execution_count": 22, 1069 | "metadata": {}, 1070 | "output_type": "execute_result" 1071 | } 1072 | ], 1073 | "source": [ 1074 | "t(3)" 1075 | ] 1076 | }, 1077 | { 1078 | "cell_type": "code", 1079 | "execution_count": 23, 1080 | "metadata": {}, 1081 | "outputs": [ 1082 | { 1083 | "data": { 1084 | "text/plain": [ 1085 | "[2, 4, 6]" 1086 | ] 1087 | }, 1088 | "execution_count": 23, 1089 | "metadata": {}, 1090 | "output_type": "execute_result" 1091 | } 1092 | ], 1093 | "source": [ 1094 | "list(map(t,seq))" 1095 | ] 1096 | }, 1097 | { 1098 | "cell_type": "markdown", 1099 | "metadata": {}, 1100 | "source": [ 1101 | "# Filter" 1102 | ] 1103 | }, 1104 | { 1105 | "cell_type": "code", 1106 | "execution_count": 25, 1107 | "metadata": {}, 1108 | "outputs": [ 1109 | { 1110 | "data": { 1111 | "text/plain": [ 1112 | "[False, True, False]" 1113 | ] 1114 | }, 1115 | "execution_count": 25, 1116 | "metadata": {}, 1117 | "output_type": "execute_result" 1118 | } 1119 | ], 1120 | "source": [ 1121 | "list(map(lambda num : num %2 ==0,seq))" 1122 | ] 1123 | }, 1124 | { 1125 | "cell_type": "code", 1126 | "execution_count": 26, 1127 | "metadata": {}, 1128 | "outputs": [ 1129 | { 1130 | "data": { 1131 | "text/plain": [ 1132 | "[2]" 1133 | ] 1134 | }, 1135 | "execution_count": 26, 1136 | "metadata": {}, 1137 | "output_type": "execute_result" 1138 | } 1139 | ], 1140 | "source": [ 1141 | "list(filter(lambda num : num %2 ==0,seq))" 1142 | ] 1143 | }, 1144 | { 1145 | "cell_type": "markdown", 1146 | "metadata": {}, 1147 | "source": [ 1148 | "# Unpacking" 1149 | ] 1150 | }, 1151 | { 1152 | "cell_type": "code", 1153 | "execution_count": 13, 1154 | "metadata": {}, 1155 | "outputs": [ 1156 | { 1157 | "name": "stdout", 1158 | "output_type": "stream", 1159 | "text": [ 1160 | "2\n" 1161 | ] 1162 | } 1163 | ], 1164 | "source": [ 1165 | "#unpacking\n", 1166 | "coordinates = [2,3,4]\n", 1167 | "# x = coordinates[0]\n", 1168 | "# y = coordinates[1]\n", 1169 | "# z = coordinates[2]\n", 1170 | "# instead of writing like this we can write \n", 1171 | "x,y,z = coordinates #unpacking -> work with both list and tuple\n", 1172 | "print(x)" 1173 | ] 1174 | }, 1175 | { 1176 | "cell_type": "markdown", 1177 | "metadata": {}, 1178 | "source": [ 1179 | "## Enumerate" 1180 | ] 1181 | }, 1182 | { 1183 | "cell_type": "code", 1184 | "execution_count": 10, 1185 | "metadata": {}, 1186 | "outputs": [ 1187 | { 1188 | "name": "stdout", 1189 | "output_type": "stream", 1190 | "text": [ 1191 | "type : \n", 1192 | "[(0, 'sam'), (1, 'bob'), (2, 'mike')]\n", 1193 | "[(2, 'sam'), (3, 'bob'), (4, 'mike')]\n" 1194 | ] 1195 | } 1196 | ], 1197 | "source": [ 1198 | "string1 = [\"sam\",\"bob\",\"mike\"]\n", 1199 | "string2 = 'python'\n", 1200 | "\n", 1201 | "obj1 = enumerate(string1)\n", 1202 | "obj2 = enumerate(string2)\n", 1203 | "\n", 1204 | "print(\"type : {}\".format(obj1))\n", 1205 | "\n", 1206 | "# return a position with string\n", 1207 | "print(list(enumerate(string1)))\n", 1208 | "\n", 1209 | "# return a position which is start from 2 \n", 1210 | "print(list(enumerate(string1,2)))\n", 1211 | "\n" 1212 | ] 1213 | }, 1214 | { 1215 | "cell_type": "code", 1216 | "execution_count": 12, 1217 | "metadata": {}, 1218 | "outputs": [ 1219 | { 1220 | "name": "stdout", 1221 | "output_type": "stream", 1222 | "text": [ 1223 | "bucky you are in position 0\n", 1224 | "Mike you are in position 1\n", 1225 | "Dustin you are in position 2\n" 1226 | ] 1227 | } 1228 | ], 1229 | "source": [ 1230 | "import numpy as np\n", 1231 | "\n", 1232 | "name = np.array(['bucky','Mike','Dustin'])\n", 1233 | "\n", 1234 | "for i,c in enumerate(name):\n", 1235 | " print(\"{} you are in position {}\".format(c,i))" 1236 | ] 1237 | }, 1238 | { 1239 | "cell_type": "markdown", 1240 | "metadata": {}, 1241 | "source": [ 1242 | "# Dictionaries" 1243 | ] 1244 | }, 1245 | { 1246 | "cell_type": "code", 1247 | "execution_count": 23, 1248 | "metadata": {}, 1249 | "outputs": [ 1250 | { 1251 | "name": "stdout", 1252 | "output_type": "stream", 1253 | "text": [ 1254 | "Hritik Jaiswal\n", 1255 | "may 31 2000\n", 1256 | "None\n", 1257 | "HritiK Dinesh Jaiswal\n" 1258 | ] 1259 | } 1260 | ], 1261 | "source": [ 1262 | "#Dictionaries -> contain key - value pairs \n", 1263 | "\n", 1264 | "people = {\n", 1265 | " \"name\" :\"Hritik Jaiswal\",\n", 1266 | " \"age\" : 19,\n", 1267 | " \"is_male\" : True\n", 1268 | "}\n", 1269 | "print(people[\"name\"])\n", 1270 | "\n", 1271 | "# u can not write like -> print(people[\"Name\"])\n", 1272 | "# we can use GET method to take key-value pair if its not present and display key value pair \n", 1273 | "print(people.get(\"birth\",\"may 31 2000\"))\n", 1274 | "print(people.get(\"gender\")) #None -> is the object that represent absence of the value\n", 1275 | "\n", 1276 | "people[\"name\"] = \"HritiK Dinesh Jaiswal\" # modify name\n", 1277 | "print(people.get(\"name\"))" 1278 | ] 1279 | }, 1280 | { 1281 | "cell_type": "code", 1282 | "execution_count": 41, 1283 | "metadata": {}, 1284 | "outputs": [ 1285 | { 1286 | "name": "stdout", 1287 | "output_type": "stream", 1288 | "text": [ 1289 | "phone : 105\n", 1290 | "1\n", 1291 | "0\n", 1292 | "5\n", 1293 | "One zero Five \n" 1294 | ] 1295 | } 1296 | ], 1297 | "source": [ 1298 | "#excersice -> inuput 1234 display output : one two three four\n", 1299 | "phone = input(\"phone : \")\n", 1300 | "\n", 1301 | "dict = {\n", 1302 | " \"1\" :\"One\",\n", 1303 | " \"2\":\"Two\",\n", 1304 | " \"3\" :\"Three\",\n", 1305 | " \"4\" :\"Four\",\n", 1306 | " \"5\" :\"Five\",\n", 1307 | " \"6\" :\"Six\",\n", 1308 | " \"7\" :\"Seven\",\n", 1309 | " \"8\" :\"Eight\",\n", 1310 | " \"9\" :\"Nine\",\n", 1311 | " \"0\" :\"zero\",\n", 1312 | "}\n", 1313 | "output = \"\" \n", 1314 | "for i in phone:\n", 1315 | " \n", 1316 | " output += (dict.get(i,\"?\")) + \" \" \n", 1317 | " print(i)\n", 1318 | "print(output) " 1319 | ] 1320 | }, 1321 | { 1322 | "cell_type": "code", 1323 | "execution_count": 12, 1324 | "metadata": {}, 1325 | "outputs": [ 1326 | { 1327 | "name": "stdout", 1328 | "output_type": "stream", 1329 | "text": [ 1330 | "Enter the word : one seven two\n", 1331 | "['one', 'seven', 'two']\n", 1332 | "1\n", 1333 | "7\n", 1334 | "2\n" 1335 | ] 1336 | } 1337 | ], 1338 | "source": [ 1339 | "#excerisce -> opposite \n", 1340 | "words = [\"one\", \"two\",\"three\",\"four\",\"five\",\"six\", \"seven\",\"eight\",\"nine\",\"zero\"]\n", 1341 | "\n", 1342 | "word = input(\"Enter the word : \")\n", 1343 | "mapping = {\n", 1344 | " \"one\":\"1\", \n", 1345 | " \"two\":\"2\",\n", 1346 | " \"three\":\"3\",\n", 1347 | " \"four\":\"4\",\n", 1348 | " \"five\":\"5\",\n", 1349 | " \"six\":\"6\", \n", 1350 | " \"seven\":\"7\",\n", 1351 | " \"eight\":\"8\",\n", 1352 | " \"nine\":\"9\",\n", 1353 | " \"zero\":\"0\"\n", 1354 | "}\n", 1355 | "spliting = word.split()\n", 1356 | "print(spliting)\n", 1357 | "for i in spliting:\n", 1358 | " print(mapping.get(i,\"&\"))\n", 1359 | " \n", 1360 | " " 1361 | ] 1362 | }, 1363 | { 1364 | "cell_type": "code", 1365 | "execution_count": 59, 1366 | "metadata": {}, 1367 | "outputs": [ 1368 | { 1369 | "name": "stdout", 1370 | "output_type": "stream", 1371 | "text": [ 1372 | ">good morning :)\n", 1373 | "good morning 😄 \n" 1374 | ] 1375 | } 1376 | ], 1377 | "source": [ 1378 | "#excersice -> print emoji\n", 1379 | "message = input(\">\")\n", 1380 | "words= message.split()\n", 1381 | "emoji = {\n", 1382 | " \":)\" :\"😄\",\n", 1383 | " \":(\" :\"😔\"\n", 1384 | "}\n", 1385 | "output = \"\"\n", 1386 | "for i in words:\n", 1387 | " output += emoji.get(i,i) + \" \"\n", 1388 | " \n", 1389 | "print(output)" 1390 | ] 1391 | }, 1392 | { 1393 | "cell_type": "markdown", 1394 | "metadata": {}, 1395 | "source": [ 1396 | "# Function " 1397 | ] 1398 | }, 1399 | { 1400 | "cell_type": "code", 1401 | "execution_count": 60, 1402 | "metadata": {}, 1403 | "outputs": [ 1404 | { 1405 | "name": "stdout", 1406 | "output_type": "stream", 1407 | "text": [ 1408 | "hii\n", 1409 | "im hritik\n" 1410 | ] 1411 | } 1412 | ], 1413 | "source": [ 1414 | "#function\n", 1415 | "def text():\n", 1416 | " print(\"im hritik\")\n", 1417 | "print(\"hii\")\n", 1418 | "text()" 1419 | ] 1420 | }, 1421 | { 1422 | "cell_type": "markdown", 1423 | "metadata": {}, 1424 | "source": [ 1425 | "# Parameter and Arguments" 1426 | ] 1427 | }, 1428 | { 1429 | "cell_type": "code", 1430 | "execution_count": 61, 1431 | "metadata": {}, 1432 | "outputs": [ 1433 | { 1434 | "name": "stdout", 1435 | "output_type": "stream", 1436 | "text": [ 1437 | "thanks\n", 1438 | "Hii hritik and jaiswal\n" 1439 | ] 1440 | } 1441 | ], 1442 | "source": [ 1443 | "#function with parameter\n", 1444 | "#parameter ->is placeholder that we passed to the function\n", 1445 | "#argumetnt -> is actual value that u gone pass inside function\n", 1446 | "def text(f_name, l_name):\n", 1447 | " print(f'Hii {f_name} and {l_name}')\n", 1448 | "print(\"thanks\")\n", 1449 | "text('hritik','jaiswal')" 1450 | ] 1451 | }, 1452 | { 1453 | "cell_type": "markdown", 1454 | "metadata": {}, 1455 | "source": [ 1456 | "# keyword argument" 1457 | ] 1458 | }, 1459 | { 1460 | "cell_type": "code", 1461 | "execution_count": 6, 1462 | "metadata": {}, 1463 | "outputs": [ 1464 | { 1465 | "name": "stdout", 1466 | "output_type": "stream", 1467 | "text": [ 1468 | "hello\n", 1469 | "Here total is 5000 including shipping charges 2000 + discount 500\n" 1470 | ] 1471 | } 1472 | ], 1473 | "source": [ 1474 | "#keyword argument -> its helpful when u don't want to pass argument in order u can pass in any order \n", 1475 | "def text(discount , shipping ,total ):\n", 1476 | " print(f'Here total is {total} including shipping charges {shipping} + discount {discount}')\n", 1477 | "print(\"hello\")\n", 1478 | "text(shipping=2000,total=5000,discount=500)" 1479 | ] 1480 | }, 1481 | { 1482 | "cell_type": "code", 1483 | "execution_count": 1, 1484 | "metadata": {}, 1485 | "outputs": [ 1486 | { 1487 | "name": "stdout", 1488 | "output_type": "stream", 1489 | "text": [ 1490 | "25\n" 1491 | ] 1492 | } 1493 | ], 1494 | "source": [ 1495 | "#return statement \n", 1496 | "def square(num):\n", 1497 | " return num*num\n", 1498 | "result = square(5)\n", 1499 | "print(result)\n", 1500 | " " 1501 | ] 1502 | }, 1503 | { 1504 | "cell_type": "code", 1505 | "execution_count": 11, 1506 | "metadata": {}, 1507 | "outputs": [ 1508 | { 1509 | "name": "stdout", 1510 | "output_type": "stream", 1511 | "text": [ 1512 | "27\n", 1513 | "None\n" 1514 | ] 1515 | } 1516 | ], 1517 | "source": [ 1518 | "#tric -> if u don't write return statement then it will return object which is : none \n", 1519 | "def cube(n):\n", 1520 | " print(n**3)\n", 1521 | "print(cube(3))" 1522 | ] 1523 | }, 1524 | { 1525 | "cell_type": "markdown", 1526 | "metadata": {}, 1527 | "source": [ 1528 | "# Exception" 1529 | ] 1530 | }, 1531 | { 1532 | "cell_type": "code", 1533 | "execution_count": 2, 1534 | "metadata": {}, 1535 | "outputs": [ 1536 | { 1537 | "name": "stdout", 1538 | "output_type": "stream", 1539 | "text": [ 1540 | "your age : twenty\n", 1541 | "invalid value\n" 1542 | ] 1543 | } 1544 | ], 1545 | "source": [ 1546 | "#exception -> when we try to input string value instead of int \n", 1547 | "# age = int(input(\"your age\"))\n", 1548 | "# print(age)\n", 1549 | "\n", 1550 | "try:\n", 1551 | " age = int(input(\"your age : \"))\n", 1552 | " print(age)\n", 1553 | "except ValueError:\n", 1554 | " print('invalid value')" 1555 | ] 1556 | }, 1557 | { 1558 | "cell_type": "code", 1559 | "execution_count": 21, 1560 | "metadata": {}, 1561 | "outputs": [ 1562 | { 1563 | "name": "stdout", 1564 | "output_type": "stream", 1565 | "text": [ 1566 | "your age : 0\n", 1567 | "invalid value or age can't be negative \n" 1568 | ] 1569 | } 1570 | ], 1571 | "source": [ 1572 | "\n", 1573 | "try:\n", 1574 | " age = int(input(\"your age : \"))\n", 1575 | " income = 20000\n", 1576 | " risk = float(income/age);\n", 1577 | " print(f'risk is {risk}')\n", 1578 | "except ValueError and ZeroDivisionError:\n", 1579 | " print(\"invalid value or age can't be negative \")" 1580 | ] 1581 | }, 1582 | { 1583 | "cell_type": "markdown", 1584 | "metadata": {}, 1585 | "source": [ 1586 | "# Class" 1587 | ] 1588 | }, 1589 | { 1590 | "cell_type": "code", 1591 | "execution_count": 61, 1592 | "metadata": {}, 1593 | "outputs": [ 1594 | { 1595 | "name": "stdout", 1596 | "output_type": "stream", 1597 | "text": [ 1598 | "area\n" 1599 | ] 1600 | } 1601 | ], 1602 | "source": [ 1603 | "#class \n", 1604 | "# 1) type -1\n", 1605 | "\n", 1606 | "class rect:\n", 1607 | " def rect_area(self):\n", 1608 | " print(\"area\")\n", 1609 | "p = rect()\n", 1610 | "p.rect_area()\n", 1611 | "\n" 1612 | ] 1613 | }, 1614 | { 1615 | "cell_type": "code", 1616 | "execution_count": 73, 1617 | "metadata": {}, 1618 | "outputs": [ 1619 | { 1620 | "name": "stdout", 1621 | "output_type": "stream", 1622 | "text": [ 1623 | "Hritik Jaiswal\n", 1624 | "Hritik Jaiswal\n" 1625 | ] 1626 | } 1627 | ], 1628 | "source": [ 1629 | "# 2) type -2\n", 1630 | "class Employee:\n", 1631 | " def __init__(self, first, last , salary):\n", 1632 | " self.first = first\n", 1633 | " self.last = last\n", 1634 | " self.salary = salary\n", 1635 | " self.email = first + '.'+last +'@gmail.com'\n", 1636 | " \n", 1637 | " def fullname(self):\n", 1638 | " return \"{} {}\".format(self.first,self.last)\n", 1639 | "\n", 1640 | "emp1 = Employee('Hritik','Jaiswal',5000)\n", 1641 | "emp2 = Employee('Aniket','Jaiswal',6000)\n", 1642 | "\n", 1643 | "#their are two methods \n", 1644 | "print(emp1.fullname())\n", 1645 | "print(Employee.fullname(emp1))\n", 1646 | " " 1647 | ] 1648 | }, 1649 | { 1650 | "cell_type": "code", 1651 | "execution_count": 74, 1652 | "metadata": {}, 1653 | "outputs": [ 1654 | { 1655 | "name": "stdout", 1656 | "output_type": "stream", 1657 | "text": [ 1658 | "area of square :9\n", 1659 | "area of rectangle is : 6\n" 1660 | ] 1661 | } 1662 | ], 1663 | "source": [ 1664 | "# 3) type -3\n", 1665 | "class Point:\n", 1666 | " def __init__(self,a,l,h):\n", 1667 | " self.a = a\n", 1668 | " self.l = l\n", 1669 | " self.h = h\n", 1670 | " \n", 1671 | " def square(self):\n", 1672 | " print(f\"area of square :{self.a*self.a}\")\n", 1673 | " \n", 1674 | " def rectangle(self):\n", 1675 | " print(\"area of rectangle is : {}\".format(self.l*self.h))\n", 1676 | " \n", 1677 | "\n", 1678 | "#create a object \n", 1679 | "point1 = Point(3,2,3)\n", 1680 | "point1.square()\n", 1681 | "point1.rectangle()" 1682 | ] 1683 | }, 1684 | { 1685 | "cell_type": "markdown", 1686 | "metadata": {}, 1687 | "source": [ 1688 | "# Inheritance" 1689 | ] 1690 | }, 1691 | { 1692 | "cell_type": "code", 1693 | "execution_count": 9, 1694 | "metadata": {}, 1695 | "outputs": [ 1696 | { 1697 | "name": "stdout", 1698 | "output_type": "stream", 1699 | "text": [ 1700 | "bark\n", 1701 | "walk\n" 1702 | ] 1703 | } 1704 | ], 1705 | "source": [ 1706 | "#inheritance -> dog and cat are inherite a class mammel\n", 1707 | "class mammel:\n", 1708 | " def walk(self):\n", 1709 | " print(\"walk\")\n", 1710 | "\n", 1711 | "class dog(mammel):\n", 1712 | " def bark(self):\n", 1713 | " print(\"bark\")\n", 1714 | "\n", 1715 | "class cat(mammel):\n", 1716 | " pass\n", 1717 | "\n", 1718 | "dog1 = dog()\n", 1719 | "dog1.bark()\n", 1720 | "\n", 1721 | "cat1 = cat()\n", 1722 | "cat1.walk()" 1723 | ] 1724 | }, 1725 | { 1726 | "cell_type": "markdown", 1727 | "metadata": {}, 1728 | "source": [ 1729 | "# Module\n", 1730 | "\n" 1731 | ] 1732 | }, 1733 | { 1734 | "cell_type": "code", 1735 | "execution_count": 23, 1736 | "metadata": {}, 1737 | "outputs": [ 1738 | { 1739 | "name": "stdout", 1740 | "output_type": "stream", 1741 | "text": [ 1742 | "1.0\n" 1743 | ] 1744 | } 1745 | ], 1746 | "source": [ 1747 | "#module -> module.ipynb file which we have created we can directly import function also\n", 1748 | "#we need to install from anaconda prompt -> pip install import-ipynb\n", 1749 | "import import_ipynb\n", 1750 | "\n", 1751 | "import module\n", 1752 | "from module import cm2m\n", 1753 | "\n", 1754 | "cm2m(100)\n", 1755 | "m2cm" 1756 | ] 1757 | }, 1758 | { 1759 | "cell_type": "code", 1760 | "execution_count": 18, 1761 | "metadata": {}, 1762 | "outputs": [ 1763 | { 1764 | "name": "stdout", 1765 | "output_type": "stream", 1766 | "text": [ 1767 | "10\n", 1768 | "4\n" 1769 | ] 1770 | } 1771 | ], 1772 | "source": [ 1773 | "numbers = [5,4,6,8,10]\n", 1774 | "print(max(numbers))\n", 1775 | "print(min(numbers))\n" 1776 | ] 1777 | }, 1778 | { 1779 | "cell_type": "markdown", 1780 | "metadata": {}, 1781 | "source": [ 1782 | "# Packages\n" 1783 | ] 1784 | }, 1785 | { 1786 | "cell_type": "markdown", 1787 | "metadata": {}, 1788 | "source": [ 1789 | "package -: we can create a seperate .py file and extract this file and import into another file as similar to module \n", 1790 | "\n", 1791 | "package is collections of different modules\n", 1792 | "\n", 1793 | "# Type of Module\n", 1794 | "\n", 1795 | " 1) Absolute module \n", 1796 | "from mypackage.mymodule1 import class A\n", 1797 | "obj = class A\n", 1798 | "\n", 1799 | " 2) relative module\n", 1800 | "if im working in \"module1\" & i want to import Class C from \"module2\" into my \"module1\"\n", 1801 | "\n", 1802 | "from module2 import classC\n", 1803 | "obj = classC()\n", 1804 | "\n", 1805 | "\n", 1806 | " \n" 1807 | ] 1808 | }, 1809 | { 1810 | "cell_type": "markdown", 1811 | "metadata": {}, 1812 | "source": [ 1813 | "# Random\n" 1814 | ] 1815 | }, 1816 | { 1817 | "cell_type": "code", 1818 | "execution_count": 6, 1819 | "metadata": {}, 1820 | "outputs": [ 1821 | { 1822 | "name": "stdout", 1823 | "output_type": "stream", 1824 | "text": [ 1825 | "0.8556515733440572\n", 1826 | "0.9018671283206765\n", 1827 | "0.6655666651378818\n" 1828 | ] 1829 | } 1830 | ], 1831 | "source": [ 1832 | "import random\n", 1833 | "\n", 1834 | "for i in range(3):\n", 1835 | " print(random.random())" 1836 | ] 1837 | }, 1838 | { 1839 | "cell_type": "code", 1840 | "execution_count": 9, 1841 | "metadata": {}, 1842 | "outputs": [ 1843 | { 1844 | "name": "stdout", 1845 | "output_type": "stream", 1846 | "text": [ 1847 | "12\n", 1848 | "20\n", 1849 | "15\n" 1850 | ] 1851 | } 1852 | ], 1853 | "source": [ 1854 | "for i in range(3):\n", 1855 | " print(random.randint(10,20))" 1856 | ] 1857 | }, 1858 | { 1859 | "cell_type": "code", 1860 | "execution_count": 17, 1861 | "metadata": {}, 1862 | "outputs": [ 1863 | { 1864 | "name": "stdout", 1865 | "output_type": "stream", 1866 | "text": [ 1867 | "jaiswal\n" 1868 | ] 1869 | } 1870 | ], 1871 | "source": [ 1872 | "# randomly choose the value \n", 1873 | "members = ['hritik', 'jaiswal','aniket','shweta']\n", 1874 | "show = random.choice(members)\n", 1875 | "print(show)" 1876 | ] 1877 | }, 1878 | { 1879 | "cell_type": "code", 1880 | "execution_count": 33, 1881 | "metadata": {}, 1882 | "outputs": [ 1883 | { 1884 | "name": "stdout", 1885 | "output_type": "stream", 1886 | "text": [ 1887 | "(2,4)\n" 1888 | ] 1889 | } 1890 | ], 1891 | "source": [ 1892 | "#excercise -> dice thrown give random value\n", 1893 | "\n", 1894 | "class Dice:\n", 1895 | " def roll(self):\n", 1896 | " x = (1,2,3,4,5,6)\n", 1897 | " y = (1,2,3,4,5,6)\n", 1898 | " m = random.choice(x)\n", 1899 | " l = random.choice(y)\n", 1900 | " print(\"({},{})\".format(m,l))\n", 1901 | " \n", 1902 | "\n", 1903 | "r = Dice()\n", 1904 | "r.roll()\n", 1905 | "\n" 1906 | ] 1907 | }, 1908 | { 1909 | "cell_type": "code", 1910 | "execution_count": 38, 1911 | "metadata": {}, 1912 | "outputs": [ 1913 | { 1914 | "name": "stdout", 1915 | "output_type": "stream", 1916 | "text": [ 1917 | "(5, 6)\n" 1918 | ] 1919 | } 1920 | ], 1921 | "source": [ 1922 | "# another method\n", 1923 | "\n", 1924 | "class Dice:\n", 1925 | " def roll(self):\n", 1926 | " first = random.randint(1,6)\n", 1927 | " second = random.randint(1,6)\n", 1928 | " return first,second\n", 1929 | "dice = Dice()\n", 1930 | "print(dice.roll())" 1931 | ] 1932 | }, 1933 | { 1934 | "cell_type": "markdown", 1935 | "metadata": {}, 1936 | "source": [ 1937 | "# Files and Directories" 1938 | ] 1939 | }, 1940 | { 1941 | "cell_type": "code", 1942 | "execution_count": 21, 1943 | "metadata": {}, 1944 | "outputs": [ 1945 | { 1946 | "name": "stdout", 1947 | "output_type": "stream", 1948 | "text": [ 1949 | "True\n" 1950 | ] 1951 | } 1952 | ], 1953 | "source": [ 1954 | "from pathlib import Path\n", 1955 | "path = Path(\".\")\n", 1956 | "print(path.exists())\n", 1957 | "\n", 1958 | "\n", 1959 | "#if u want to make new directory\n", 1960 | "\n", 1961 | "# path1 = Path(\"Files_Directories\")\n", 1962 | "# path1.mkdir()\n", 1963 | "\n", 1964 | "#when u want to remove directory\n", 1965 | "#path.rmdir()\n", 1966 | "\n" 1967 | ] 1968 | }, 1969 | { 1970 | "cell_type": "code", 1971 | "execution_count": 5, 1972 | "metadata": {}, 1973 | "outputs": [ 1974 | { 1975 | "name": "stdout", 1976 | "output_type": "stream", 1977 | "text": [ 1978 | "ch02.ipynb\n", 1979 | "module.ipynb\n", 1980 | "Python-1.ipynb\n" 1981 | ] 1982 | } 1983 | ], 1984 | "source": [ 1985 | "path2 = Path()\n", 1986 | "for file in path2.glob(\"*.ipynb\"):\n", 1987 | " print(file)" 1988 | ] 1989 | }, 1990 | { 1991 | "cell_type": "code", 1992 | "execution_count": 6, 1993 | "metadata": {}, 1994 | "outputs": [ 1995 | { 1996 | "name": "stdout", 1997 | "output_type": "stream", 1998 | "text": [ 1999 | ".ipynb_checkpoints\n", 2000 | "ch02.ipynb\n", 2001 | "Files_Directories\n", 2002 | "module.ipynb\n", 2003 | "Python-1.ipynb\n" 2004 | ] 2005 | } 2006 | ], 2007 | "source": [ 2008 | "path3 = Path()\n", 2009 | "for file in path3.glob(\"*\"):\n", 2010 | " print(file)" 2011 | ] 2012 | }, 2013 | { 2014 | "cell_type": "markdown", 2015 | "metadata": {}, 2016 | "source": [ 2017 | "# Working with spreadsheet" 2018 | ] 2019 | }, 2020 | { 2021 | "cell_type": "code", 2022 | "execution_count": 28, 2023 | "metadata": {}, 2024 | "outputs": [ 2025 | { 2026 | "name": "stdout", 2027 | "output_type": "stream", 2028 | "text": [ 2029 | "transaction_id\n", 2030 | "4\n" 2031 | ] 2032 | } 2033 | ], 2034 | "source": [ 2035 | "import openpyxl as xl\n", 2036 | "from openpyxl.chart import BarChart,Reference\n", 2037 | "\n", 2038 | "# Here openpyxl -> package , chart -> module , BarChart -> class\n", 2039 | "#instead of passing a file name -> we can use function and store the path in \"filename\" variable and pass as argument to function \n", 2040 | "\n", 2041 | "wb = xl.load_workbook(r'C:\\Users\\Hritik Jaiswal\\Downloads\\Spreadsheet\\transactions.xlsx')\n", 2042 | "sheet = wb['Sheet1']\n", 2043 | "\n", 2044 | "\n", 2045 | "#method to get a cell \n", 2046 | "\n", 2047 | "cell = sheet['a1']\n", 2048 | "#another method -> cell = sheet.cell(1,1)\n", 2049 | "\n", 2050 | "print(cell.value)\n", 2051 | "#print max row\n", 2052 | "print(sheet.max_row)" 2053 | ] 2054 | }, 2055 | { 2056 | "cell_type": "code", 2057 | "execution_count": 29, 2058 | "metadata": {}, 2059 | "outputs": [ 2060 | { 2061 | "name": "stdout", 2062 | "output_type": "stream", 2063 | "text": [ 2064 | "5.95\n", 2065 | "6.95\n", 2066 | "7.95\n" 2067 | ] 2068 | } 2069 | ], 2070 | "source": [ 2071 | "#we have to modify value of the cell and store into another excel file\n", 2072 | "\n", 2073 | "for row in range(2,sheet.max_row+1):\n", 2074 | " cell = sheet.cell(row,3) # column is 3\n", 2075 | " print(cell.value)\n", 2076 | " corrected_value = cell.value * 0.9\n", 2077 | " \n", 2078 | " #now we have to place a corrected value into anther column \n", 2079 | " corrected_value_cell = sheet.cell(row,4) #add corrected value into the 4 column\n", 2080 | " \n", 2081 | " corrected_value_cell.value = corrected_value\n", 2082 | "#Excersice \n", 2083 | "\n", 2084 | "# u have to create a bar graph in excel\n", 2085 | "\n", 2086 | "\n", 2087 | "values = Reference(sheet, \n", 2088 | " \n", 2089 | " min_row=2,max_row = sheet.max_row,\n", 2090 | " \n", 2091 | " min_col = 4 , max_col = 4\n", 2092 | " )\n", 2093 | "\n", 2094 | "chart = BarChart()\n", 2095 | "chart.add_data(values)\n", 2096 | "sheet.add_chart(chart, 'f2')\n", 2097 | "\n", 2098 | "\n", 2099 | "wb.save(\"transaction2.xlsx\")\n", 2100 | "\n" 2101 | ] 2102 | }, 2103 | { 2104 | "cell_type": "markdown", 2105 | "metadata": {}, 2106 | "source": [ 2107 | "# Machine learning" 2108 | ] 2109 | }, 2110 | { 2111 | "cell_type": "markdown", 2112 | "metadata": {}, 2113 | "source": [ 2114 | "# Steps :\n", 2115 | " \n", 2116 | " 1) Import the Data \n", 2117 | " 2) clean the Data\n", 2118 | " 3) split the Data into training/test sets\n", 2119 | " 4) create a model\n", 2120 | " 5) train the model\n", 2121 | " 6) make prediction\n", 2122 | " 7) Evaluate and Improve\n", 2123 | " " 2124 | ] 2125 | }, 2126 | { 2127 | "cell_type": "code", 2128 | "execution_count": 31, 2129 | "metadata": {}, 2130 | "outputs": [ 2131 | { 2132 | "data": { 2133 | "text/plain": [ 2134 | "(16598, 11)" 2135 | ] 2136 | }, 2137 | "execution_count": 31, 2138 | "metadata": {}, 2139 | "output_type": "execute_result" 2140 | } 2141 | ], 2142 | "source": [ 2143 | "#Importing a data set\n", 2144 | "import pandas as pd\n", 2145 | "df = pd.read_csv('vgsales.csv')\n", 2146 | "df.shape" 2147 | ] 2148 | }, 2149 | { 2150 | "cell_type": "code", 2151 | "execution_count": 32, 2152 | "metadata": {}, 2153 | "outputs": [ 2154 | { 2155 | "data": { 2156 | "text/html": [ 2157 | "
\n", 2158 | "\n", 2171 | "\n", 2172 | " \n", 2173 | " \n", 2174 | " \n", 2175 | " \n", 2176 | " \n", 2177 | " \n", 2178 | " \n", 2179 | " \n", 2180 | " \n", 2181 | " \n", 2182 | " \n", 2183 | " \n", 2184 | " \n", 2185 | " \n", 2186 | " \n", 2187 | " \n", 2188 | " \n", 2189 | " \n", 2190 | " \n", 2191 | " \n", 2192 | " \n", 2193 | " \n", 2194 | " \n", 2195 | " \n", 2196 | " \n", 2197 | " \n", 2198 | " \n", 2199 | " \n", 2200 | " \n", 2201 | " \n", 2202 | " \n", 2203 | " \n", 2204 | " \n", 2205 | " \n", 2206 | " \n", 2207 | " \n", 2208 | " \n", 2209 | " \n", 2210 | " \n", 2211 | " \n", 2212 | " \n", 2213 | " \n", 2214 | " \n", 2215 | " \n", 2216 | " \n", 2217 | " \n", 2218 | " \n", 2219 | " \n", 2220 | " \n", 2221 | " \n", 2222 | " \n", 2223 | " \n", 2224 | " \n", 2225 | " \n", 2226 | " \n", 2227 | " \n", 2228 | " \n", 2229 | " \n", 2230 | " \n", 2231 | " \n", 2232 | " \n", 2233 | " \n", 2234 | " \n", 2235 | " \n", 2236 | " \n", 2237 | " \n", 2238 | " \n", 2239 | " \n", 2240 | " \n", 2241 | " \n", 2242 | " \n", 2243 | " \n", 2244 | " \n", 2245 | " \n", 2246 | " \n", 2247 | " \n", 2248 | " \n", 2249 | " \n", 2250 | " \n", 2251 | " \n", 2252 | " \n", 2253 | " \n", 2254 | " \n", 2255 | " \n", 2256 | " \n", 2257 | " \n", 2258 | " \n", 2259 | " \n", 2260 | " \n", 2261 | " \n", 2262 | " \n", 2263 | " \n", 2264 | " \n", 2265 | " \n", 2266 | "
RankYearNA_SalesEU_SalesJP_SalesOther_SalesGlobal_Sales
count16598.00000016327.00000016598.00000016598.00000016598.00000016598.00000016598.000000
mean8300.6052542006.4064430.2646670.1466520.0777820.0480630.537441
std4791.8539335.8289810.8166830.5053510.3092910.1885881.555028
min1.0000001980.0000000.0000000.0000000.0000000.0000000.010000
25%4151.2500002003.0000000.0000000.0000000.0000000.0000000.060000
50%8300.5000002007.0000000.0800000.0200000.0000000.0100000.170000
75%12449.7500002010.0000000.2400000.1100000.0400000.0400000.470000
max16600.0000002020.00000041.49000029.02000010.22000010.57000082.740000
\n", 2267 | "
" 2268 | ], 2269 | "text/plain": [ 2270 | " Rank Year NA_Sales EU_Sales JP_Sales \\\n", 2271 | "count 16598.000000 16327.000000 16598.000000 16598.000000 16598.000000 \n", 2272 | "mean 8300.605254 2006.406443 0.264667 0.146652 0.077782 \n", 2273 | "std 4791.853933 5.828981 0.816683 0.505351 0.309291 \n", 2274 | "min 1.000000 1980.000000 0.000000 0.000000 0.000000 \n", 2275 | "25% 4151.250000 2003.000000 0.000000 0.000000 0.000000 \n", 2276 | "50% 8300.500000 2007.000000 0.080000 0.020000 0.000000 \n", 2277 | "75% 12449.750000 2010.000000 0.240000 0.110000 0.040000 \n", 2278 | "max 16600.000000 2020.000000 41.490000 29.020000 10.220000 \n", 2279 | "\n", 2280 | " Other_Sales Global_Sales \n", 2281 | "count 16598.000000 16598.000000 \n", 2282 | "mean 0.048063 0.537441 \n", 2283 | "std 0.188588 1.555028 \n", 2284 | "min 0.000000 0.010000 \n", 2285 | "25% 0.000000 0.060000 \n", 2286 | "50% 0.010000 0.170000 \n", 2287 | "75% 0.040000 0.470000 \n", 2288 | "max 10.570000 82.740000 " 2289 | ] 2290 | }, 2291 | "execution_count": 32, 2292 | "metadata": {}, 2293 | "output_type": "execute_result" 2294 | } 2295 | ], 2296 | "source": [ 2297 | "df.describe()" 2298 | ] 2299 | }, 2300 | { 2301 | "cell_type": "code", 2302 | "execution_count": 33, 2303 | "metadata": {}, 2304 | "outputs": [ 2305 | { 2306 | "data": { 2307 | "text/plain": [ 2308 | "array([[1, 'Wii Sports', 'Wii', ..., 3.77, 8.46, 82.74],\n", 2309 | " [2, 'Super Mario Bros.', 'NES', ..., 6.81, 0.77, 40.24],\n", 2310 | " [3, 'Mario Kart Wii', 'Wii', ..., 3.79, 3.31, 35.82],\n", 2311 | " ...,\n", 2312 | " [16598, 'SCORE International Baja 1000: The Official Game', 'PS2',\n", 2313 | " ..., 0.0, 0.0, 0.01],\n", 2314 | " [16599, 'Know How 2', 'DS', ..., 0.0, 0.0, 0.01],\n", 2315 | " [16600, 'Spirits & Spells', 'GBA', ..., 0.0, 0.0, 0.01]],\n", 2316 | " dtype=object)" 2317 | ] 2318 | }, 2319 | "execution_count": 33, 2320 | "metadata": {}, 2321 | "output_type": "execute_result" 2322 | } 2323 | ], 2324 | "source": [ 2325 | "df.values" 2326 | ] 2327 | }, 2328 | { 2329 | "cell_type": "markdown", 2330 | "metadata": {}, 2331 | "source": [ 2332 | "# Shortcut" 2333 | ] 2334 | }, 2335 | { 2336 | "cell_type": "markdown", 2337 | "metadata": {}, 2338 | "source": [ 2339 | "we can use shift-tab to describe function\n", 2340 | "\n", 2341 | "all shortcut is present when we click 'h' in editor" 2342 | ] 2343 | }, 2344 | { 2345 | "cell_type": "markdown", 2346 | "metadata": {}, 2347 | "source": [ 2348 | "# Real world problem\n", 2349 | "\n", 2350 | "recommend various music albums thier likely to buy based on age and gender\n" 2351 | ] 2352 | }, 2353 | { 2354 | "cell_type": "markdown", 2355 | "metadata": {}, 2356 | "source": [ 2357 | "# Importing Data " 2358 | ] 2359 | }, 2360 | { 2361 | "cell_type": "code", 2362 | "execution_count": 18, 2363 | "metadata": {}, 2364 | "outputs": [ 2365 | { 2366 | "data": { 2367 | "text/html": [ 2368 | "
\n", 2369 | "\n", 2382 | "\n", 2383 | " \n", 2384 | " \n", 2385 | " \n", 2386 | " \n", 2387 | " \n", 2388 | " \n", 2389 | " \n", 2390 | " \n", 2391 | " \n", 2392 | " \n", 2393 | " \n", 2394 | " \n", 2395 | " \n", 2396 | " \n", 2397 | " \n", 2398 | " \n", 2399 | " \n", 2400 | " \n", 2401 | " \n", 2402 | " \n", 2403 | " \n", 2404 | " \n", 2405 | " \n", 2406 | " \n", 2407 | " \n", 2408 | " \n", 2409 | " \n", 2410 | " \n", 2411 | " \n", 2412 | " \n", 2413 | " \n", 2414 | " \n", 2415 | " \n", 2416 | " \n", 2417 | " \n", 2418 | " \n", 2419 | " \n", 2420 | " \n", 2421 | " \n", 2422 | " \n", 2423 | " \n", 2424 | " \n", 2425 | " \n", 2426 | " \n", 2427 | " \n", 2428 | " \n", 2429 | " \n", 2430 | " \n", 2431 | " \n", 2432 | " \n", 2433 | " \n", 2434 | " \n", 2435 | " \n", 2436 | " \n", 2437 | " \n", 2438 | " \n", 2439 | " \n", 2440 | " \n", 2441 | " \n", 2442 | " \n", 2443 | " \n", 2444 | " \n", 2445 | " \n", 2446 | " \n", 2447 | " \n", 2448 | " \n", 2449 | " \n", 2450 | " \n", 2451 | " \n", 2452 | " \n", 2453 | " \n", 2454 | " \n", 2455 | " \n", 2456 | " \n", 2457 | " \n", 2458 | " \n", 2459 | " \n", 2460 | " \n", 2461 | " \n", 2462 | " \n", 2463 | " \n", 2464 | " \n", 2465 | " \n", 2466 | " \n", 2467 | " \n", 2468 | " \n", 2469 | " \n", 2470 | " \n", 2471 | " \n", 2472 | " \n", 2473 | " \n", 2474 | " \n", 2475 | " \n", 2476 | " \n", 2477 | " \n", 2478 | " \n", 2479 | " \n", 2480 | " \n", 2481 | " \n", 2482 | " \n", 2483 | " \n", 2484 | " \n", 2485 | " \n", 2486 | " \n", 2487 | " \n", 2488 | " \n", 2489 | " \n", 2490 | " \n", 2491 | " \n", 2492 | " \n", 2493 | " \n", 2494 | " \n", 2495 | " \n", 2496 | " \n", 2497 | " \n", 2498 | " \n", 2499 | " \n", 2500 | " \n", 2501 | "
agegendergenre
0201HipHop
1231HipHop
2251HipHop
3261Jazz
4291Jazz
5301Jazz
6311Classical
7331Classical
8371Classical
9200Dance
10210Dance
11250Dance
12260Acoustic
13270Acoustic
14300Acoustic
15310Classical
16340Classical
17350Classical
\n", 2502 | "
" 2503 | ], 2504 | "text/plain": [ 2505 | " age gender genre\n", 2506 | "0 20 1 HipHop\n", 2507 | "1 23 1 HipHop\n", 2508 | "2 25 1 HipHop\n", 2509 | "3 26 1 Jazz\n", 2510 | "4 29 1 Jazz\n", 2511 | "5 30 1 Jazz\n", 2512 | "6 31 1 Classical\n", 2513 | "7 33 1 Classical\n", 2514 | "8 37 1 Classical\n", 2515 | "9 20 0 Dance\n", 2516 | "10 21 0 Dance\n", 2517 | "11 25 0 Dance\n", 2518 | "12 26 0 Acoustic\n", 2519 | "13 27 0 Acoustic\n", 2520 | "14 30 0 Acoustic\n", 2521 | "15 31 0 Classical\n", 2522 | "16 34 0 Classical\n", 2523 | "17 35 0 Classical" 2524 | ] 2525 | }, 2526 | "execution_count": 18, 2527 | "metadata": {}, 2528 | "output_type": "execute_result" 2529 | } 2530 | ], 2531 | "source": [ 2532 | "import pandas as pd\n", 2533 | "\n", 2534 | "data = pd.read_csv('music.csv')\n", 2535 | "data\n" 2536 | ] 2537 | }, 2538 | { 2539 | "cell_type": "code", 2540 | "execution_count": 19, 2541 | "metadata": {}, 2542 | "outputs": [ 2543 | { 2544 | "data": { 2545 | "text/html": [ 2546 | "
\n", 2547 | "\n", 2560 | "\n", 2561 | " \n", 2562 | " \n", 2563 | " \n", 2564 | " \n", 2565 | " \n", 2566 | " \n", 2567 | " \n", 2568 | " \n", 2569 | " \n", 2570 | " \n", 2571 | " \n", 2572 | " \n", 2573 | " \n", 2574 | " \n", 2575 | " \n", 2576 | " \n", 2577 | " \n", 2578 | " \n", 2579 | " \n", 2580 | " \n", 2581 | " \n", 2582 | " \n", 2583 | " \n", 2584 | " \n", 2585 | " \n", 2586 | " \n", 2587 | " \n", 2588 | " \n", 2589 | " \n", 2590 | " \n", 2591 | " \n", 2592 | " \n", 2593 | " \n", 2594 | " \n", 2595 | " \n", 2596 | " \n", 2597 | " \n", 2598 | " \n", 2599 | " \n", 2600 | " \n", 2601 | " \n", 2602 | " \n", 2603 | " \n", 2604 | " \n", 2605 | " \n", 2606 | " \n", 2607 | " \n", 2608 | " \n", 2609 | " \n", 2610 | "
agegender
count18.00000018.000000
mean27.9444440.500000
std5.1274600.514496
min20.0000000.000000
25%25.0000000.000000
50%28.0000000.500000
75%31.0000001.000000
max37.0000001.000000
\n", 2611 | "
" 2612 | ], 2613 | "text/plain": [ 2614 | " age gender\n", 2615 | "count 18.000000 18.000000\n", 2616 | "mean 27.944444 0.500000\n", 2617 | "std 5.127460 0.514496\n", 2618 | "min 20.000000 0.000000\n", 2619 | "25% 25.000000 0.000000\n", 2620 | "50% 28.000000 0.500000\n", 2621 | "75% 31.000000 1.000000\n", 2622 | "max 37.000000 1.000000" 2623 | ] 2624 | }, 2625 | "execution_count": 19, 2626 | "metadata": {}, 2627 | "output_type": "execute_result" 2628 | } 2629 | ], 2630 | "source": [ 2631 | "data.describe()" 2632 | ] 2633 | }, 2634 | { 2635 | "cell_type": "code", 2636 | "execution_count": 20, 2637 | "metadata": {}, 2638 | "outputs": [], 2639 | "source": [ 2640 | "# we will create two input data set that will be 'age' and 'gender'\n", 2641 | "# we will pass 'age' and 'gender' and based on the input we predict the output \n", 2642 | "# output will be stored in 'genre' \n", 2643 | "\n", 2644 | "X = data.drop(columns=['genre'])\n", 2645 | "\n", 2646 | "Y = data['genre']\n" 2647 | ] 2648 | }, 2649 | { 2650 | "cell_type": "markdown", 2651 | "metadata": {}, 2652 | "source": [ 2653 | "# Learning and Predicting" 2654 | ] 2655 | }, 2656 | { 2657 | "cell_type": "code", 2658 | "execution_count": 24, 2659 | "metadata": {}, 2660 | "outputs": [ 2661 | { 2662 | "data": { 2663 | "text/plain": [ 2664 | "array(['Dance', 'HipHop'], dtype=object)" 2665 | ] 2666 | }, 2667 | "execution_count": 24, 2668 | "metadata": {}, 2669 | "output_type": "execute_result" 2670 | } 2671 | ], 2672 | "source": [ 2673 | "from sklearn.tree import DecisionTreeClassifier\n", 2674 | "\n", 2675 | "model = DecisionTreeClassifier()\n", 2676 | "# takes two attributes 1. input dataset 2. output dataset\n", 2677 | "model.fit(X,Y)\n", 2678 | "\n", 2679 | "\n", 2680 | "#let make a prediction by passing input Here 22 is age and 0 is female\n", 2681 | "\n", 2682 | "prediction = model.predict([[22,0],[25,1]])\n", 2683 | "prediction\n", 2684 | "\n" 2685 | ] 2686 | }, 2687 | { 2688 | "cell_type": "markdown", 2689 | "metadata": {}, 2690 | "source": [ 2691 | "# Calculating the Accuracy" 2692 | ] 2693 | }, 2694 | { 2695 | "cell_type": "code", 2696 | "execution_count": 26, 2697 | "metadata": {}, 2698 | "outputs": [ 2699 | { 2700 | "name": "stdout", 2701 | "output_type": "stream", 2702 | "text": [ 2703 | " age gender\n", 2704 | "0 20 1\n", 2705 | "3 26 1\n", 2706 | "5 30 1\n", 2707 | "6 31 1\n", 2708 | "12 26 0\n", 2709 | "9 20 0\n", 2710 | "11 25 0\n", 2711 | "2 25 1\n", 2712 | "10 21 0\n", 2713 | "Accuracy is : 0.6666666666666666\n" 2714 | ] 2715 | } 2716 | ], 2717 | "source": [ 2718 | "# for calculating the accuracy we need to test and train the model \n", 2719 | "# generally 70-80% data need to training and 20-30% for testing\n", 2720 | "\n", 2721 | "from sklearn.model_selection import train_test_split \n", 2722 | "\n", 2723 | "# Here we use 20% for testing and check with respect to the predicted value\n", 2724 | "# the function will return 4 tuple we have to get that result into a variable \n", 2725 | "\n", 2726 | "X_train,X_test,Y_train,Y_test = train_test_split(X,Y,test_size = 0.5)\n", 2727 | "print(X_train)\n", 2728 | "model.fit(X_train,Y_train)\n", 2729 | "\n", 2730 | "# we pass input as X_test in attribute\n", 2731 | "prediction = model.predict(X_test)\n", 2732 | "\n", 2733 | "# now to check accurancy we have to compair the prediction with y_test()\n", 2734 | "from sklearn.metrics import accuracy_score\n", 2735 | "\n", 2736 | "score = accuracy_score(Y_test,prediction)\n", 2737 | "print(\"Accuracy is : {}\".format(score))\n", 2738 | "\n", 2739 | "#every time we run are model accuracy will be changing" 2740 | ] 2741 | }, 2742 | { 2743 | "cell_type": "markdown", 2744 | "metadata": {}, 2745 | "source": [ 2746 | "# Model Persistance" 2747 | ] 2748 | }, 2749 | { 2750 | "cell_type": "markdown", 2751 | "metadata": {}, 2752 | "source": [ 2753 | "\n", 2754 | "for training model again again takes lot of time instead \n", 2755 | "we can save the trained model in one joblib file \n", 2756 | "\n", 2757 | "run these piece of code after applying model i.e after :\n", 2758 | "\n", 2759 | " model = DecisionTreeClassifier()\n", 2760 | " \n", 2761 | " from sklearn.externals import joblib \n", 2762 | " joblib.dump(model,'model-recommender.joblib')\n", 2763 | "\n", 2764 | "after runing these commment the trained model syntax and and then direclty load \n", 2765 | "\n", 2766 | " joblib.load('model-recommender.joblib')\n" 2767 | ] 2768 | }, 2769 | { 2770 | "cell_type": "markdown", 2771 | "metadata": {}, 2772 | "source": [ 2773 | "\n", 2774 | "# Visualizing a Decision Tree\n" 2775 | ] 2776 | }, 2777 | { 2778 | "cell_type": "code", 2779 | "execution_count": 28, 2780 | "metadata": {}, 2781 | "outputs": [], 2782 | "source": [ 2783 | "# u can see a graph i.e decision tree on visual studio code \n", 2784 | "# by clicking a sidebar preview button\n", 2785 | " \n", 2786 | "from sklearn import tree\n", 2787 | "tree.export_graphviz(model,\n", 2788 | " out_file = \"music-recommender.dot\",\n", 2789 | " class_names = sorted(Y.unique()),\n", 2790 | " label = 'all',\n", 2791 | " rounded =True ,\n", 2792 | " filled= True\n", 2793 | " )\n", 2794 | "\n" 2795 | ] 2796 | }, 2797 | { 2798 | "cell_type": "markdown", 2799 | "metadata": {}, 2800 | "source": [] 2801 | }, 2802 | { 2803 | "cell_type": "code", 2804 | "execution_count": null, 2805 | "metadata": {}, 2806 | "outputs": [], 2807 | "source": [] 2808 | } 2809 | ], 2810 | "metadata": { 2811 | "kernelspec": { 2812 | "display_name": "Python 3", 2813 | "language": "python", 2814 | "name": "python3" 2815 | }, 2816 | "language_info": { 2817 | "codemirror_mode": { 2818 | "name": "ipython", 2819 | "version": 3 2820 | }, 2821 | "file_extension": ".py", 2822 | "mimetype": "text/x-python", 2823 | "name": "python", 2824 | "nbconvert_exporter": "python", 2825 | "pygments_lexer": "ipython3", 2826 | "version": "3.6.8" 2827 | } 2828 | }, 2829 | "nbformat": 4, 2830 | "nbformat_minor": 2 2831 | } 2832 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Python for beginners 2 | - [Python Basic](#PythonBasic) 3 | - [Type](#Type) 4 | 5 | - [Inbuilt-Function](#Inbuilt-Function) 6 | - [Math function](#bold) 7 | - [If - Statement](#strike-through) 8 | - [Format](#horizontal-rule) 9 | - [While loop](#blockquote) 10 | - [for loop](#link) 11 | - [List](#unorder-list) 12 | - [Basic Inbuilt - Function](#order-list) 13 | - [tuple](#image) 14 | - [set](#image) 15 | - [map](#image) 16 | - [lambda](#image) 17 | - [filter](#image) 18 | - [Unpacking](#GIF) 19 | - [Enumerate](#GIF) 20 | - [Dictionaries](#code-blocks) 21 | - [Function](#tables) 22 | - [Parameter and Arguments](#task-list) 23 | - [keyword argument](#code-blocks) 24 | - [Exception](#tables) 25 | - [Class](#task-list) 26 | - [Inheritance](#task-list) 27 | - [Module](#code-blocks) 28 | - [Packages](#tables) 29 | - [Random-Function](#task-list) 30 | - [Inheritance](#task-list) 31 | - [Files and Directories](#code-blocks) 32 | - [Working with spreadsheet](#tables) 33 | 34 | ### Basic of Machine Learning 35 | #### Steps : 36 | 37 | 1) Import the Data 38 | 2) clean the Data 39 | 3) split the Data into training/test sets 40 | 4) create a model 41 | 5) train the model 42 | 6) make prediction 43 | 7) Evaluate and Improve 44 | ### Real world problem 45 | - [Importing a data set](#task-list) 46 | - [Importing Data ](#task-list) 47 | - [Learning and Predicting](#task-list) 48 | - [ Calculating the Accuracy](#task-list) 49 | - [Model Persistance](#task-list) 50 | - [Visualizing a Decision Tree](#task-list) - -------------------------------------------------------------------------------- /db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hritik5102/Python-for-beginners/095577687efcb94645a79bdebf918b7a2053c13b/db.sqlite3 -------------------------------------------------------------------------------- /model-recommender.joblib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hritik5102/Python-for-beginners/095577687efcb94645a79bdebf918b7a2053c13b/model-recommender.joblib -------------------------------------------------------------------------------- /module.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 7, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "def cm2m(value):\n", 10 | " value = value/100\n", 11 | " print(value)\n", 12 | " \n", 13 | "def m2cm(value):\n", 14 | " value = value*100\n", 15 | " print(value)\n" 16 | ] 17 | }, 18 | { 19 | "cell_type": "code", 20 | "execution_count": null, 21 | "metadata": {}, 22 | "outputs": [], 23 | "source": [] 24 | } 25 | ], 26 | "metadata": { 27 | "kernelspec": { 28 | "display_name": "Python 3", 29 | "language": "python", 30 | "name": "python3" 31 | }, 32 | "language_info": { 33 | "codemirror_mode": { 34 | "name": "ipython", 35 | "version": 3 36 | }, 37 | "file_extension": ".py", 38 | "mimetype": "text/x-python", 39 | "name": "python", 40 | "nbconvert_exporter": "python", 41 | "pygments_lexer": "ipython3", 42 | "version": "3.6.8" 43 | } 44 | }, 45 | "nbformat": 4, 46 | "nbformat_minor": 2 47 | } 48 | -------------------------------------------------------------------------------- /music-recommender.dot: -------------------------------------------------------------------------------- 1 | digraph Tree { 2 | node [shape=box, style="filled, rounded", color="black", fontname=helvetica] ; 3 | edge [fontname=helvetica] ; 4 | 0 [label="X[1] <= 0.5\ngini = 0.765\nsamples = 9\nvalue = [1, 1, 3, 2, 2]\nclass = Dance", fillcolor="#39e5c524"] ; 5 | 1 [label="X[0] <= 25.5\ngini = 0.375\nsamples = 4\nvalue = [1, 0, 3, 0, 0]\nclass = Dance", fillcolor="#39e5c5aa"] ; 6 | 0 -> 1 [labeldistance=2.5, labelangle=45, headlabel="True"] ; 7 | 2 [label="gini = 0.0\nsamples = 3\nvalue = [0, 0, 3, 0, 0]\nclass = Dance", fillcolor="#39e5c5ff"] ; 8 | 1 -> 2 ; 9 | 3 [label="gini = 0.0\nsamples = 1\nvalue = [1, 0, 0, 0, 0]\nclass = Acoustic", fillcolor="#e58139ff"] ; 10 | 1 -> 3 ; 11 | 4 [label="X[0] <= 25.5\ngini = 0.64\nsamples = 5\nvalue = [0, 1, 0, 2, 2]\nclass = HipHop", fillcolor="#3c39e500"] ; 12 | 0 -> 4 [labeldistance=2.5, labelangle=-45, headlabel="False"] ; 13 | 5 [label="gini = 0.0\nsamples = 2\nvalue = [0, 0, 0, 2, 0]\nclass = HipHop", fillcolor="#3c39e5ff"] ; 14 | 4 -> 5 ; 15 | 6 [label="X[0] <= 30.5\ngini = 0.444\nsamples = 3\nvalue = [0, 1, 0, 0, 2]\nclass = Jazz", fillcolor="#e539c07f"] ; 16 | 4 -> 6 ; 17 | 7 [label="gini = 0.0\nsamples = 2\nvalue = [0, 0, 0, 0, 2]\nclass = Jazz", fillcolor="#e539c0ff"] ; 18 | 6 -> 7 ; 19 | 8 [label="gini = 0.0\nsamples = 1\nvalue = [0, 1, 0, 0, 0]\nclass = Classical", fillcolor="#7be539ff"] ; 20 | 6 -> 8 ; 21 | } -------------------------------------------------------------------------------- /music.csv: -------------------------------------------------------------------------------- 1 | age,gender,genre 2 | 20,1,HipHop 3 | 23,1,HipHop 4 | 25,1,HipHop 5 | 26,1,Jazz 6 | 29,1,Jazz 7 | 30,1,Jazz 8 | 31,1,Classical 9 | 33,1,Classical 10 | 37,1,Classical 11 | 20,0,Dance 12 | 21,0,Dance 13 | 25,0,Dance 14 | 26,0,Acoustic 15 | 27,0,Acoustic 16 | 30,0,Acoustic 17 | 31,0,Classical 18 | 34,0,Classical 19 | 35,0,Classical -------------------------------------------------------------------------------- /products/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hritik5102/Python-for-beginners/095577687efcb94645a79bdebf918b7a2053c13b/products/__init__.py -------------------------------------------------------------------------------- /products/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /products/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class ProductsConfig(AppConfig): 5 | name = 'products' 6 | -------------------------------------------------------------------------------- /products/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hritik5102/Python-for-beginners/095577687efcb94645a79bdebf918b7a2053c13b/products/migrations/__init__.py -------------------------------------------------------------------------------- /products/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | -------------------------------------------------------------------------------- /products/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /products/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | from django.http import HttpResponse 3 | 4 | # it takes a request and send to view function 5 | def index(request) : 6 | return HttpResponse('Hellow world') 7 | 8 | 9 | -------------------------------------------------------------------------------- /pyshop/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hritik5102/Python-for-beginners/095577687efcb94645a79bdebf918b7a2053c13b/pyshop/__init__.py -------------------------------------------------------------------------------- /pyshop/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hritik5102/Python-for-beginners/095577687efcb94645a79bdebf918b7a2053c13b/pyshop/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /pyshop/__pycache__/settings.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hritik5102/Python-for-beginners/095577687efcb94645a79bdebf918b7a2053c13b/pyshop/__pycache__/settings.cpython-37.pyc -------------------------------------------------------------------------------- /pyshop/__pycache__/urls.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hritik5102/Python-for-beginners/095577687efcb94645a79bdebf918b7a2053c13b/pyshop/__pycache__/urls.cpython-37.pyc -------------------------------------------------------------------------------- /pyshop/__pycache__/wsgi.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hritik5102/Python-for-beginners/095577687efcb94645a79bdebf918b7a2053c13b/pyshop/__pycache__/wsgi.cpython-37.pyc -------------------------------------------------------------------------------- /pyshop/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for pyshop project. 3 | 4 | Generated by 'django-admin startproject' using Django 2.1. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.1/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/2.1/ref/settings/ 11 | """ 12 | 13 | import os 14 | 15 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = '1(gvy(q&7$maimdaun#7j75831dcju1r2!_m&v-xi#)z7^o8z4' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = [] 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = [ 34 | 'django.contrib.admin', 35 | 'django.contrib.auth', 36 | 'django.contrib.contenttypes', 37 | 'django.contrib.sessions', 38 | 'django.contrib.messages', 39 | 'django.contrib.staticfiles', 40 | ] 41 | 42 | MIDDLEWARE = [ 43 | 'django.middleware.security.SecurityMiddleware', 44 | 'django.contrib.sessions.middleware.SessionMiddleware', 45 | 'django.middleware.common.CommonMiddleware', 46 | 'django.middleware.csrf.CsrfViewMiddleware', 47 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 48 | 'django.contrib.messages.middleware.MessageMiddleware', 49 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 50 | ] 51 | 52 | ROOT_URLCONF = 'pyshop.urls' 53 | 54 | TEMPLATES = [ 55 | { 56 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 57 | 'DIRS': [], 58 | 'APP_DIRS': True, 59 | 'OPTIONS': { 60 | 'context_processors': [ 61 | 'django.template.context_processors.debug', 62 | 'django.template.context_processors.request', 63 | 'django.contrib.auth.context_processors.auth', 64 | 'django.contrib.messages.context_processors.messages', 65 | ], 66 | }, 67 | }, 68 | ] 69 | 70 | WSGI_APPLICATION = 'pyshop.wsgi.application' 71 | 72 | 73 | # Database 74 | # https://docs.djangoproject.com/en/2.1/ref/settings/#databases 75 | 76 | DATABASES = { 77 | 'default': { 78 | 'ENGINE': 'django.db.backends.sqlite3', 79 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 80 | } 81 | } 82 | 83 | 84 | # Password validation 85 | # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators 86 | 87 | AUTH_PASSWORD_VALIDATORS = [ 88 | { 89 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 90 | }, 91 | { 92 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 93 | }, 94 | { 95 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 96 | }, 97 | { 98 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 99 | }, 100 | ] 101 | 102 | 103 | # Internationalization 104 | # https://docs.djangoproject.com/en/2.1/topics/i18n/ 105 | 106 | LANGUAGE_CODE = 'en-us' 107 | 108 | TIME_ZONE = 'UTC' 109 | 110 | USE_I18N = True 111 | 112 | USE_L10N = True 113 | 114 | USE_TZ = True 115 | 116 | 117 | # Static files (CSS, JavaScript, Images) 118 | # https://docs.djangoproject.com/en/2.1/howto/static-files/ 119 | 120 | STATIC_URL = '/static/' 121 | -------------------------------------------------------------------------------- /pyshop/urls.py: -------------------------------------------------------------------------------- 1 | """pyshop URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/2.1/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import path 18 | 19 | urlpatterns = [ 20 | path('admin/', admin.site.urls), 21 | ] 22 | -------------------------------------------------------------------------------- /pyshop/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for pyshop project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pyshop.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /transaction2.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hritik5102/Python-for-beginners/095577687efcb94645a79bdebf918b7a2053c13b/transaction2.xlsx -------------------------------------------------------------------------------- /transactions.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hritik5102/Python-for-beginners/095577687efcb94645a79bdebf918b7a2053c13b/transactions.xlsx --------------------------------------------------------------------------------