├── Mastering Python Loops ├── Master Loops in Python.pdf └── Mastering Python Loops - LIVE!.ipynb ├── Mastering Python Strings ├── Mastering Python Strings - LIVE!.pdf └── Mastering_Python_Strings_LIVE.ipynb ├── Mastering Functions in Python ├── Mastering Functions in Python.pdf └── Mastering_Functions_in_Python.ipynb ├── Mastering Recursion in Python ├── Mastering Recursion in Python - LIVE!.pdf └── Mastering_Recursion_in_Python.ipynb ├── Mastering Variables in Python ├── Mastering Variables in Python - LIVE!.pdf └── Mastering Variables in Python - LIVE!.ipynb ├── Mastering Python's Functional Tools ├── Mastering Python Functional Tools.pdf └── Mastering_Python's_Functional_Tools.ipynb ├── Python Mastery: A Step by Step Roadmap └── Python Mastery-A Step-by-Step Roadmap.pdf ├── Mastering Conditionals in Python - LIVE! ├── Mastering Conditionals in Python - LIVE!.pdf └── Mastering_Conditionals_in_Python_LIVE!.ipynb ├── Mastering Data Visualization with Seaborn - LIVE! └── Mastering Data Visualization with Seaborn - LIVE!.pdf ├── README.md ├── Mastering Object Oriented Programming in Python └── Mastering_OOPs_in_Python.ipynb ├── Mastering Exception Handling in Python - Live!! └── Mastering_Exception_Handling_in_Python_Live!!.ipynb ├── Python Interview Questions Explained - LIVE! └── Python's_Interview_Questions_Explained.ipynb ├── Mastering the Power Of NumPy in Python - LIVE! └── Mastering_the_Power_Of_NumPy.ipynb └── Mastering the Power Of Pandas: LIVE! └── Mastering_the_Power_Of_Pandas_LIVE.ipynb /Mastering Python Loops/Master Loops in Python.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/priya6971/Python-Programming-The-Ultimate-Playlist/HEAD/Mastering Python Loops/Master Loops in Python.pdf -------------------------------------------------------------------------------- /Mastering Python Strings/Mastering Python Strings - LIVE!.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/priya6971/Python-Programming-The-Ultimate-Playlist/HEAD/Mastering Python Strings/Mastering Python Strings - LIVE!.pdf -------------------------------------------------------------------------------- /Mastering Functions in Python/Mastering Functions in Python.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/priya6971/Python-Programming-The-Ultimate-Playlist/HEAD/Mastering Functions in Python/Mastering Functions in Python.pdf -------------------------------------------------------------------------------- /Mastering Recursion in Python/Mastering Recursion in Python - LIVE!.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/priya6971/Python-Programming-The-Ultimate-Playlist/HEAD/Mastering Recursion in Python/Mastering Recursion in Python - LIVE!.pdf -------------------------------------------------------------------------------- /Mastering Variables in Python/Mastering Variables in Python - LIVE!.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/priya6971/Python-Programming-The-Ultimate-Playlist/HEAD/Mastering Variables in Python/Mastering Variables in Python - LIVE!.pdf -------------------------------------------------------------------------------- /Mastering Python's Functional Tools/Mastering Python Functional Tools.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/priya6971/Python-Programming-The-Ultimate-Playlist/HEAD/Mastering Python's Functional Tools/Mastering Python Functional Tools.pdf -------------------------------------------------------------------------------- /Python Mastery: A Step by Step Roadmap/Python Mastery-A Step-by-Step Roadmap.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/priya6971/Python-Programming-The-Ultimate-Playlist/HEAD/Python Mastery: A Step by Step Roadmap/Python Mastery-A Step-by-Step Roadmap.pdf -------------------------------------------------------------------------------- /Mastering Conditionals in Python - LIVE!/Mastering Conditionals in Python - LIVE!.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/priya6971/Python-Programming-The-Ultimate-Playlist/HEAD/Mastering Conditionals in Python - LIVE!/Mastering Conditionals in Python - LIVE!.pdf -------------------------------------------------------------------------------- /Mastering Data Visualization with Seaborn - LIVE!/Mastering Data Visualization with Seaborn - LIVE!.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/priya6971/Python-Programming-The-Ultimate-Playlist/HEAD/Mastering Data Visualization with Seaborn - LIVE!/Mastering Data Visualization with Seaborn - LIVE!.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Python-Programming-The-Ultimate-Playlist 2 | This playlist is designed to be your one-stop resource for learning Python, covering everything from foundational skills to advanced techniques. Whether you're just getting started or looking to deepen your understanding, this series provides a structured pathway to Python mastery. 3 | -------------------------------------------------------------------------------- /Mastering Functions in Python/Mastering_Functions_in_Python.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [] 7 | }, 8 | "kernelspec": { 9 | "name": "python3", 10 | "display_name": "Python 3" 11 | }, 12 | "language_info": { 13 | "name": "python" 14 | } 15 | }, 16 | "cells": [ 17 | { 18 | "cell_type": "code", 19 | "execution_count": 3, 20 | "metadata": { 21 | "id": "MF3D6O4boVA7", 22 | "colab": { 23 | "base_uri": "https://localhost:8080/" 24 | }, 25 | "outputId": "98dddd0c-c126-44e6-98de-1c1f51dde4c1" 26 | }, 27 | "outputs": [ 28 | { 29 | "output_type": "stream", 30 | "name": "stdout", 31 | "text": [ 32 | "[1, 6, 7, 5, 3]\n" 33 | ] 34 | } 35 | ], 36 | "source": [ 37 | "## function definition\n", 38 | "## approach: Two Pointers Approach\n", 39 | "## time complexity: O(n)\n", 40 | "## space complexity: O(1)\n", 41 | "\n", 42 | "def reverse(list1):\n", 43 | " low, high = 0, len(list1) - 1\n", 44 | " while low < high:\n", 45 | " ## 1. swap list[low] with list1[high]\n", 46 | " list1[low], list1[high] = list1[high], list1[low]\n", 47 | " ## 2. increment the value of low\n", 48 | " low += 1\n", 49 | " ## 3. decrement the value of high\n", 50 | " high -= 1\n", 51 | " return list1\n", 52 | "\n", 53 | "\n", 54 | "## Driver code\n", 55 | "list1 = [2, 5, 7, 12, 10]\n", 56 | "list2 = [3, 5, 7, 6, 1]\n", 57 | "## function calling\n", 58 | "## application: reuse the logic of reversal in any of the given list entered by the user\n", 59 | "print(reverse(list2))" 60 | ] 61 | }, 62 | { 63 | "cell_type": "markdown", 64 | "source": [ 65 | "**Practice Problems**\n", 66 | "\n", 67 | "\n", 68 | "* Create a function that accepts a list of numbers and returns the sum of all the even numbers in a list.\n", 69 | "\n", 70 | "list1 = [2, 5, 8, 9]\n", 71 | "\n", 72 | "output = 2 + 8 = 10\n", 73 | "\n", 74 | "* Create a function to calculate the fibonacci sequence.\n", 75 | "\n", 76 | "fib(5) = 5\n", 77 | "\n", 78 | "fib(0) = 0\n", 79 | "\n", 80 | "fib(1) = 1\n", 81 | "\n", 82 | "fib(2) = 1\n", 83 | "\n", 84 | "fib(3) = 2\n", 85 | "\n", 86 | "fib(4) = 3\n", 87 | "\n", 88 | "fib(5) = 5\n" 89 | ], 90 | "metadata": { 91 | "id": "_E_GIi1Nv6OD" 92 | } 93 | }, 94 | { 95 | "cell_type": "code", 96 | "source": [], 97 | "metadata": { 98 | "id": "knGgFrar7s6b" 99 | }, 100 | "execution_count": null, 101 | "outputs": [] 102 | } 103 | ] 104 | } -------------------------------------------------------------------------------- /Mastering Object Oriented Programming in Python/Mastering_OOPs_in_Python.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [] 7 | }, 8 | "kernelspec": { 9 | "name": "python3", 10 | "display_name": "Python 3" 11 | }, 12 | "language_info": { 13 | "name": "python" 14 | } 15 | }, 16 | "cells": [ 17 | { 18 | "cell_type": "code", 19 | "execution_count": 11, 20 | "metadata": { 21 | "colab": { 22 | "base_uri": "https://localhost:8080/" 23 | }, 24 | "id": "Un5IfNKSS1cw", 25 | "outputId": "01a1527d-2505-4b28-cc59-d53b3e4e5d53" 26 | }, 27 | "outputs": [ 28 | { 29 | "output_type": "stream", 30 | "name": "stdout", 31 | "text": [ 32 | "7-Days SQL Bootcamp\n", 33 | "Priya Bhatia\n", 34 | "1\n", 35 | "1 7-Days SQL Bootcamp\n", 36 | "Course ID: 1\n", 37 | "Course Name: 7-Days SQL Bootcamp\n", 38 | " Instructor Name: Priya Bhatia\n", 39 | "Akhil\n", 40 | "17\n", 41 | "Course ID: 1\n", 42 | "Course Name: 7-Days SQL Bootcamp\n", 43 | " Instructor Name: Priya Bhatia\n", 44 | " Student ID: 17\n", 45 | " Student Name: Akhil\n" 46 | ] 47 | } 48 | ], 49 | "source": [ 50 | "class TechforAllWithPriya:\n", 51 | " ## initialization\n", 52 | " def __init__(self, courseId, courseName, instructorName):\n", 53 | " self.courseID = courseId\n", 54 | " self.course_Name = courseName\n", 55 | " self.instructor = instructorName\n", 56 | "\n", 57 | " ## to get the details of course\n", 58 | " def course_details(self):\n", 59 | " return f\"{self.courseID} {self.course_Name}\"\n", 60 | "\n", 61 | " ## to display the complete data\n", 62 | " ## concept of polymorphism\n", 63 | " def display_details(self):\n", 64 | " details = \"Course ID: {}\\nCourse Name: {}\\n Instructor Name: {}\".format(self.courseID, self.course_Name, self.instructor)\n", 65 | " return details\n", 66 | "\n", 67 | "## inheritance\n", 68 | "## Learners: Derived class\n", 69 | "## TechforAllWithPriya: Parent class\n", 70 | "class Learners(TechforAllWithPriya):\n", 71 | " ## initialization\n", 72 | " def __init__(self, courseId, courseName, instructorName, studentId, studentName):\n", 73 | " super().__init__(courseId, courseName, instructorName)\n", 74 | " self.studentId = studentId\n", 75 | " self.student_Name = studentName\n", 76 | "\n", 77 | " ## to display the complete data\n", 78 | " ## concept of polymorphism\n", 79 | " def display_details(self):\n", 80 | " parent_details = super().display_details()\n", 81 | " details = \"{}\\n Student ID: {}\\n Student Name: {}\".format(parent_details, self.studentId, self.student_Name)\n", 82 | " return details\n", 83 | "\n", 84 | "## object of TechforAllWithPriya class\n", 85 | "sqlcourse = TechforAllWithPriya(1, \"7-Days SQL Bootcamp\", \"Priya Bhatia\")\n", 86 | "print(sqlcourse.course_Name)\n", 87 | "print(sqlcourse.instructor)\n", 88 | "print(sqlcourse.courseID)\n", 89 | "print(sqlcourse.course_details())\n", 90 | "print(sqlcourse.display_details())\n", 91 | "\n", 92 | "## object of Learners class\n", 93 | "enrolledLearner = Learners(1, \"7-Days SQL Bootcamp\", \"Priya Bhatia\", 17, \"Akhil\")\n", 94 | "print(enrolledLearner.student_Name)\n", 95 | "print(enrolledLearner.studentId)\n", 96 | "print(enrolledLearner.display_details())" 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "source": [ 102 | "## Encapsulation" 103 | ], 104 | "metadata": { 105 | "id": "4-NEiFzwVMbN" 106 | }, 107 | "execution_count": null, 108 | "outputs": [] 109 | } 110 | ] 111 | } -------------------------------------------------------------------------------- /Mastering Recursion in Python/Mastering_Recursion_in_Python.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [] 7 | }, 8 | "kernelspec": { 9 | "name": "python3", 10 | "display_name": "Python 3" 11 | }, 12 | "language_info": { 13 | "name": "python" 14 | } 15 | }, 16 | "cells": [ 17 | { 18 | "cell_type": "markdown", 19 | "source": [ 20 | "Advantage of using Recursion:\n", 21 | "\n", 22 | "\n", 23 | "* Understanding\n", 24 | "* Clarity\n", 25 | "* Lesser lines of code(Base case condition and recursive function calls)\n", 26 | "* Avoid recusion at the time of overlapping subproblem because it leads to the exponential time complexity at that time, so we can optimize the code via using the dynamic programming approach.\n", 27 | "\n" 28 | ], 29 | "metadata": { 30 | "id": "e5IBIiNW6vfY" 31 | } 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "source": [ 36 | "All the codes available in this file contains recursion only." 37 | ], 38 | "metadata": { 39 | "id": "IGNGjtpXzjP_" 40 | } 41 | }, 42 | { 43 | "cell_type": "markdown", 44 | "source": [ 45 | "**Factorial of a given number**" 46 | ], 47 | "metadata": { 48 | "id": "uAV8A1Quy6Oq" 49 | } 50 | }, 51 | { 52 | "cell_type": "code", 53 | "execution_count": 2, 54 | "metadata": { 55 | "id": "1PN2ut4v2-BB", 56 | "colab": { 57 | "base_uri": "https://localhost:8080/" 58 | }, 59 | "outputId": "08aa6b01-f466-4c95-edae-c1b3b6a02828" 60 | }, 61 | "outputs": [ 62 | { 63 | "output_type": "stream", 64 | "name": "stdout", 65 | "text": [ 66 | "479001600\n" 67 | ] 68 | } 69 | ], 70 | "source": [ 71 | "## function definition\n", 72 | "def fact(n):\n", 73 | " ## 1. Base case condition\n", 74 | " if n <= 1:\n", 75 | " return 1\n", 76 | " ## 2. Recursive function calls\n", 77 | " else:\n", 78 | " return n * fact(n-1)\n", 79 | "\n", 80 | "## Driver code\n", 81 | "n = 12\n", 82 | "print(fact(n))" 83 | ] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "source": [ 88 | "**Fibonacci Number in a given series**" 89 | ], 90 | "metadata": { 91 | "id": "VDsodLgN45vR" 92 | } 93 | }, 94 | { 95 | "cell_type": "code", 96 | "source": [ 97 | "## Method definition\n", 98 | "def fibonacci(n):\n", 99 | " ## 1. Base case condition\n", 100 | " if n <= 1:\n", 101 | " return n\n", 102 | " ## 2. Recursive function call\n", 103 | " else:\n", 104 | " return fibonacci(n-1) + fibonacci(n-2)\n", 105 | "\n", 106 | "## Driver code\n", 107 | "num = 5\n", 108 | "print(fibonacci(num))" 109 | ], 110 | "metadata": { 111 | "colab": { 112 | "base_uri": "https://localhost:8080/" 113 | }, 114 | "id": "zGVfyZv_zaxv", 115 | "outputId": "cce01f10-4060-4429-c7c7-afbe02931921" 116 | }, 117 | "execution_count": 4, 118 | "outputs": [ 119 | { 120 | "output_type": "stream", 121 | "name": "stdout", 122 | "text": [ 123 | "5\n" 124 | ] 125 | } 126 | ] 127 | }, 128 | { 129 | "cell_type": "markdown", 130 | "source": [ 131 | "Sum of the digits\n", 132 | "\n", 133 | "num = 1234\n", 134 | "\n", 135 | "output = 1 + 2 + 3 + 4 = 10" 136 | ], 137 | "metadata": { 138 | "id": "4RgYX65O5Um0" 139 | } 140 | }, 141 | { 142 | "cell_type": "code", 143 | "source": [ 144 | "def sumOfDigits(n):\n", 145 | " ## 1. Base case condition\n", 146 | " if n < 10:\n", 147 | " return n\n", 148 | " ## 2. Recursive function call\n", 149 | " else:\n", 150 | " return ((n % 10) + sumOfDigits(n//10))\n", 151 | "\n", 152 | "## Driver code\n", 153 | "n = 1234\n", 154 | "print(sumOfDigits(n))\n" 155 | ], 156 | "metadata": { 157 | "colab": { 158 | "base_uri": "https://localhost:8080/" 159 | }, 160 | "id": "Ou1v-THq5J2t", 161 | "outputId": "c911c7ff-8afe-4c53-b95c-a42391cdc254" 162 | }, 163 | "execution_count": 10, 164 | "outputs": [ 165 | { 166 | "output_type": "stream", 167 | "name": "stdout", 168 | "text": [ 169 | "10\n" 170 | ] 171 | } 172 | ] 173 | }, 174 | { 175 | "cell_type": "code", 176 | "source": [], 177 | "metadata": { 178 | "id": "wEZ6h-G46T6w" 179 | }, 180 | "execution_count": null, 181 | "outputs": [] 182 | } 183 | ] 184 | } -------------------------------------------------------------------------------- /Mastering Python Loops/Mastering Python Loops - LIVE!.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"authorship_tag":"ABX9TyPtQBtyEv2+Pr/TeTS56cbB"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"code","execution_count":1,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"P6v7VOBxp-lf","executionInfo":{"status":"ok","timestamp":1696776128224,"user_tz":-330,"elapsed":16,"user":{"displayName":"priya bhatia","userId":"00515267356904697155"}},"outputId":"77472b85-c08a-418a-e02a-c103c5c16ec7"},"outputs":[{"output_type":"stream","name":"stdout","text":["P\n","r\n","i\n","y\n","a\n"]}],"source":["str1 = \"Priya\"\n","for i in str1:\n"," print(i)"]},{"cell_type":"code","source":["for i in str1:\n"," print(i.upper())"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"8TpRjb6CvP5U","executionInfo":{"status":"ok","timestamp":1696776221535,"user_tz":-330,"elapsed":13,"user":{"displayName":"priya bhatia","userId":"00515267356904697155"}},"outputId":"cf38b1e2-34f8-49ca-c7b3-4ce48e21c1ed"},"execution_count":2,"outputs":[{"output_type":"stream","name":"stdout","text":["P\n","R\n","I\n","Y\n","A\n"]}]},{"cell_type":"markdown","source":["**Given a list, print all the even numbers in the list**"],"metadata":{"id":"rGOIAyTWwH4N"}},{"cell_type":"code","source":["list1 = [2, 3, 6, 8, 12, 13, 17]\n","for num in list1:\n"," if num % 2 == 0:\n"," print(num)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"pjKbRfslvm5t","executionInfo":{"status":"ok","timestamp":1696776592386,"user_tz":-330,"elapsed":15,"user":{"displayName":"priya bhatia","userId":"00515267356904697155"}},"outputId":"5ddb67c3-35df-4f72-d010-7742f68d8637"},"execution_count":3,"outputs":[{"output_type":"stream","name":"stdout","text":["2\n","6\n","8\n","12\n"]}]},{"cell_type":"code","source":["list1 = [2, 3, 6, 8, 12, 13, 17]\n","list2 = []\n","for num in list1:\n"," if num % 2 == 0:\n"," list2.append(num)\n","\n","print(list2)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"PjSZcoBVxBFT","executionInfo":{"status":"ok","timestamp":1696776688238,"user_tz":-330,"elapsed":598,"user":{"displayName":"priya bhatia","userId":"00515267356904697155"}},"outputId":"cd817c95-b241-4c0c-c1e0-b6e3a946b34b"},"execution_count":4,"outputs":[{"output_type":"stream","name":"stdout","text":["[2, 6, 8, 12]\n"]}]},{"cell_type":"markdown","source":["**Summation of all the values available in the given list**"],"metadata":{"id":"f3lQWgnk0QiF"}},{"cell_type":"code","source":["sum = 0\n","for num in list1:\n"," sum = sum + num\n","\n","print(sum)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"tgozaX3F0WBv","executionInfo":{"status":"ok","timestamp":1696777529363,"user_tz":-330,"elapsed":1080,"user":{"displayName":"priya bhatia","userId":"00515267356904697155"}},"outputId":"8fb25482-9636-4580-bf92-8d251e293d31"},"execution_count":7,"outputs":[{"output_type":"stream","name":"stdout","text":["61\n"]}]},{"cell_type":"markdown","source":["**for-else usecase in loops in Python**"],"metadata":{"id":"CHSWpnow0s5z"}},{"cell_type":"code","source":["str2 = \"Ankit\"\n","for i in str2:\n"," print(i)\n","else:\n"," print(\"Loop executed successfully\")"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"xn16Y7L00pn3","executionInfo":{"status":"ok","timestamp":1696777631625,"user_tz":-330,"elapsed":808,"user":{"displayName":"priya bhatia","userId":"00515267356904697155"}},"outputId":"238058c7-9dd8-4874-cf17-b576ee8670d4"},"execution_count":9,"outputs":[{"output_type":"stream","name":"stdout","text":["A\n","n\n","k\n","i\n","t\n","Loop executed successfully\n"]}]},{"cell_type":"code","source":["for i in list1:\n"," print(i)\n"," if i == 8:\n"," break\n","else:\n"," print(\"Loop executed successfully\")"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"ytv1KdGT1OfJ","executionInfo":{"status":"ok","timestamp":1696777838074,"user_tz":-330,"elapsed":874,"user":{"displayName":"priya bhatia","userId":"00515267356904697155"}},"outputId":"dbfbc6fb-e1c3-47a7-c24c-550196652471"},"execution_count":11,"outputs":[{"output_type":"stream","name":"stdout","text":["2\n","3\n","6\n","8\n"]}]},{"cell_type":"markdown","source":["**Implementation of the same code via applying the for loop**"],"metadata":{"id":"-k6er6SZ0Ad8"}},{"cell_type":"code","source":["num = 6\n","factorial = 1\n","while num > 0:\n"," factorial = factorial * num\n"," num -= 1\n","print(factorial)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"_JvLKcJIxYZx","executionInfo":{"status":"ok","timestamp":1696777345970,"user_tz":-330,"elapsed":11,"user":{"displayName":"priya bhatia","userId":"00515267356904697155"}},"outputId":"7403d70c-feaa-4600-daea-5d4ddf18e5d9"},"execution_count":6,"outputs":[{"output_type":"stream","name":"stdout","text":["720\n"]}]},{"cell_type":"markdown","source":["\n","**Reverse a list**\n","\n","list2 = [2, 5, 8, 12, 17]\n","\n","output = [17, 12, 8, 5, 2]"],"metadata":{"id":"VEwpBiPL2XHs"}},{"cell_type":"markdown","source":["**Two Pointer Technique**"],"metadata":{"id":"ok98XGhJ2n4-"}},{"cell_type":"code","source":["list2 = [2, 5, 8, 12, 17]\n","low = 0\n","high = len(list2) - 1\n","while low < high:\n"," ## swap list2[low] with the list2[high]\n"," list2[low], list2[high] = list2[high], list2[low]\n"," ## increment the low pointer and decrement the high pointer\n"," low += 1\n"," high -= 1\n","\n","print(list2)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"fjAtwcdXz3Gx","executionInfo":{"status":"ok","timestamp":1696778939925,"user_tz":-330,"elapsed":14,"user":{"displayName":"priya bhatia","userId":"00515267356904697155"}},"outputId":"f8570f57-3ad4-49b0-ed96-030eee27aaf2"},"execution_count":12,"outputs":[{"output_type":"stream","name":"stdout","text":["[17, 12, 8, 5, 2]\n"]}]},{"cell_type":"markdown","source":["**Write a code to check whether the num is a prime number or not?**\n","\n","num = 16\n","It is not a prime number\n","\n","num = 2\n","It is a prime number"],"metadata":{"id":"o8LO5zHI6S0A"}},{"cell_type":"code","source":[],"metadata":{"id":"VWtDDw7k5-Na"},"execution_count":null,"outputs":[]}]} -------------------------------------------------------------------------------- /Mastering Conditionals in Python - LIVE!/Mastering_Conditionals_in_Python_LIVE!.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [] 7 | }, 8 | "kernelspec": { 9 | "name": "python3", 10 | "display_name": "Python 3" 11 | }, 12 | "language_info": { 13 | "name": "python" 14 | } 15 | }, 16 | "cells": [ 17 | { 18 | "cell_type": "markdown", 19 | "source": [ 20 | "1. How to take input from the user - input()\n", 21 | "2. By default, it will take str as the input datatype" 22 | ], 23 | "metadata": { 24 | "id": "cGLTK1KpKFXC" 25 | } 26 | }, 27 | { 28 | "cell_type": "code", 29 | "source": [ 30 | "percentage = input()" 31 | ], 32 | "metadata": { 33 | "colab": { 34 | "base_uri": "https://localhost:8080/" 35 | }, 36 | "id": "ZB9GCXLzJjUw", 37 | "outputId": "e1597ac7-640a-4123-cdbc-1d1d92e7bb85" 38 | }, 39 | "execution_count": 1, 40 | "outputs": [ 41 | { 42 | "name": "stdout", 43 | "output_type": "stream", 44 | "text": [ 45 | "87\n" 46 | ] 47 | } 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "source": [ 53 | "type(percentage)" 54 | ], 55 | "metadata": { 56 | "colab": { 57 | "base_uri": "https://localhost:8080/" 58 | }, 59 | "id": "mFsVsGJyJz7i", 60 | "outputId": "c8f13c14-8bb1-4e37-da2b-c0f85f673c07" 61 | }, 62 | "execution_count": 2, 63 | "outputs": [ 64 | { 65 | "output_type": "execute_result", 66 | "data": { 67 | "text/plain": [ 68 | "str" 69 | ] 70 | }, 71 | "metadata": {}, 72 | "execution_count": 2 73 | } 74 | ] 75 | }, 76 | { 77 | "cell_type": "markdown", 78 | "source": [ 79 | "**Typecasting - conversion of str type to the float data type**" 80 | ], 81 | "metadata": { 82 | "id": "xRAoUxQzKXCn" 83 | } 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "source": [ 88 | "**Conditional Statements**" 89 | ], 90 | "metadata": { 91 | "id": "xIX62F_lLJmM" 92 | } 93 | }, 94 | { 95 | "cell_type": "code", 96 | "execution_count": 4, 97 | "metadata": { 98 | "colab": { 99 | "base_uri": "https://localhost:8080/" 100 | }, 101 | "id": "FhgqZ3o0FMiQ", 102 | "outputId": "f949ce94-acf9-4992-8d4f-5e60885e6688" 103 | }, 104 | "outputs": [ 105 | { 106 | "output_type": "stream", 107 | "name": "stdout", 108 | "text": [ 109 | "Enter your percentage: 86\n", 110 | "Sorry, you didn't met the selection criteria\n" 111 | ] 112 | } 113 | ], 114 | "source": [ 115 | "iit_shortlist_percentage = 90.0\n", 116 | "candidate_percentage = float(input(\"Enter your percentage: \"))\n", 117 | "\n", 118 | "if candidate_percentage >= iit_shortlist_percentage:\n", 119 | " print(\"Congratulations! You are selected to an IIT college\")\n", 120 | "else:\n", 121 | " print(\"Sorry, you didn't met the selection criteria\")" 122 | ] 123 | }, 124 | { 125 | "cell_type": "code", 126 | "source": [ 127 | "iit_shortlist_percentage = 90.0\n", 128 | "candidate_percentage = float(input(\"Enter your percentage: \"))\n", 129 | "\n", 130 | "if candidate_percentage >= iit_shortlist_percentage:\n", 131 | " print(\"Congratulations! You are selected to an IIT college\")\n", 132 | "elif candidate_percentage < iit_shortlist_percentage and candidate_percentage > 88:\n", 133 | " print(\"You are in the waiting list\")\n", 134 | "else:\n", 135 | " print(\"Sorry, you didn't met the selection criteria\")" 136 | ], 137 | "metadata": { 138 | "colab": { 139 | "base_uri": "https://localhost:8080/" 140 | }, 141 | "id": "xT1qFd_8LPyQ", 142 | "outputId": "d95a1596-eda0-4528-e837-cc75f8d4e383" 143 | }, 144 | "execution_count": 7, 145 | "outputs": [ 146 | { 147 | "output_type": "stream", 148 | "name": "stdout", 149 | "text": [ 150 | "Enter your percentage: 98\n", 151 | "Congratulations! You are selected to an IIT college\n" 152 | ] 153 | } 154 | ] 155 | }, 156 | { 157 | "cell_type": "markdown", 158 | "source": [ 159 | "**Movie Ticket Pricing**" 160 | ], 161 | "metadata": { 162 | "id": "3oisCWbyOquz" 163 | } 164 | }, 165 | { 166 | "cell_type": "code", 167 | "source": [ 168 | "age = int(input(\"Enter your age: \"))\n", 169 | "day = input(\"Is it a weekday or weekend? \").lower()\n", 170 | "\n", 171 | "if age < 5:\n", 172 | " price = 0\n", 173 | "elif age <= 12:\n", 174 | " price = 100\n", 175 | "elif age >= 65:\n", 176 | " price = 80\n", 177 | "else:\n", 178 | " price = 200\n", 179 | "\n", 180 | "## apply surplus charge for the weekend\n", 181 | "if day == \"weekend\":\n", 182 | " price += 200\n", 183 | "\n", 184 | "print(\"Movie ticket price\", price, \"INR\")" 185 | ], 186 | "metadata": { 187 | "colab": { 188 | "base_uri": "https://localhost:8080/" 189 | }, 190 | "id": "QZ3bZ3rqMdA5", 191 | "outputId": "83920e11-451b-47a0-c020-5a0d658ddfcb" 192 | }, 193 | "execution_count": 9, 194 | "outputs": [ 195 | { 196 | "output_type": "stream", 197 | "name": "stdout", 198 | "text": [ 199 | "Enter your age: 80\n", 200 | "Is it a weekday or weekend? weekday\n", 201 | "Movie ticket price 80 INR\n" 202 | ] 203 | } 204 | ] 205 | }, 206 | { 207 | "cell_type": "markdown", 208 | "source": [ 209 | "Practice Problems:\n", 210 | "\n", 211 | "\n", 212 | "1. Check whether a string is a palindromic string or not\n", 213 | "for example: 'mom' - true, otherwise false\n", 214 | "\n", 215 | "2. Check whether the character entered by the user is a vowel or a consonant\n", 216 | "'a' - this char is a vowel\n", 217 | "'z' - this is a consonant\n", 218 | "\n" 219 | ], 220 | "metadata": { 221 | "id": "MSyc23zgQ8rN" 222 | } 223 | }, 224 | { 225 | "cell_type": "code", 226 | "source": [], 227 | "metadata": { 228 | "id": "4UUpibn_QAq4" 229 | }, 230 | "execution_count": null, 231 | "outputs": [] 232 | } 233 | ] 234 | } -------------------------------------------------------------------------------- /Mastering Exception Handling in Python - Live!!/Mastering_Exception_Handling_in_Python_Live!!.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [] 7 | }, 8 | "kernelspec": { 9 | "name": "python3", 10 | "display_name": "Python 3" 11 | }, 12 | "language_info": { 13 | "name": "python" 14 | } 15 | }, 16 | "cells": [ 17 | { 18 | "cell_type": "code", 19 | "source": [ 20 | "a = 6\n", 21 | "b = 0\n", 22 | "c = a/b\n", 23 | "print(c)\n", 24 | "print(\"Hello World\")" 25 | ], 26 | "metadata": { 27 | "colab": { 28 | "base_uri": "https://localhost:8080/", 29 | "height": 250 30 | }, 31 | "id": "qfIwfOXDkX8u", 32 | "outputId": "a00d2982-56e0-44e6-9f7e-c19773857671" 33 | }, 34 | "execution_count": 3, 35 | "outputs": [ 36 | { 37 | "output_type": "error", 38 | "ename": "ZeroDivisionError", 39 | "evalue": "ignored", 40 | "traceback": [ 41 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 42 | "\u001b[0;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", 43 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0ma\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m6\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mc\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Hello World\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", 44 | "\u001b[0;31mZeroDivisionError\u001b[0m: division by zero" 45 | ] 46 | } 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "source": [ 52 | "try :\n", 53 | " a = int(input())\n", 54 | " b = int(input())\n", 55 | " c = a/b\n", 56 | " print(c)\n", 57 | "except:\n", 58 | " pass\n", 59 | "print(\"Hello World\")" 60 | ], 61 | "metadata": { 62 | "colab": { 63 | "base_uri": "https://localhost:8080/" 64 | }, 65 | "id": "_Asmg5NqlEDU", 66 | "outputId": "5be2a836-850d-43c0-a146-5188b82ff4da" 67 | }, 68 | "execution_count": 5, 69 | "outputs": [ 70 | { 71 | "output_type": "stream", 72 | "name": "stdout", 73 | "text": [ 74 | "6\n", 75 | "0\n", 76 | "Hello World\n" 77 | ] 78 | } 79 | ] 80 | }, 81 | { 82 | "cell_type": "code", 83 | "source": [ 84 | "try :\n", 85 | " a = int(input())\n", 86 | " b = int(input())\n", 87 | " c = a/b\n", 88 | " print(c)\n", 89 | "except ZeroDivisionError as z:\n", 90 | " print(z)\n", 91 | "\n", 92 | "except ValueError as v:\n", 93 | " print(v)\n", 94 | "print(\"Hello World\")" 95 | ], 96 | "metadata": { 97 | "colab": { 98 | "base_uri": "https://localhost:8080/" 99 | }, 100 | "id": "VCX3GDfkmtyr", 101 | "outputId": "7c1f8138-de2f-4dc1-8662-23b84941cd60" 102 | }, 103 | "execution_count": 10, 104 | "outputs": [ 105 | { 106 | "output_type": "stream", 107 | "name": "stdout", 108 | "text": [ 109 | "6\n", 110 | "0\n", 111 | "division by zero\n", 112 | "Hello World\n" 113 | ] 114 | } 115 | ] 116 | }, 117 | { 118 | "cell_type": "code", 119 | "source": [ 120 | "try :\n", 121 | " l = [10, 20, 40, 70, 90]\n", 122 | " l[10]\n", 123 | "except Exception as e:\n", 124 | " print(e)" 125 | ], 126 | "metadata": { 127 | "colab": { 128 | "base_uri": "https://localhost:8080/" 129 | }, 130 | "id": "4M-9G-o-n986", 131 | "outputId": "9ed9c150-e7f8-4cc7-90a4-94f687fcc5a7" 132 | }, 133 | "execution_count": 8, 134 | "outputs": [ 135 | { 136 | "output_type": "stream", 137 | "name": "stdout", 138 | "text": [ 139 | "list index out of range\n" 140 | ] 141 | } 142 | ] 143 | }, 144 | { 145 | "cell_type": "code", 146 | "source": [ 147 | "try :\n", 148 | " records = {\"name\":\"Priya\", \"phoneNum\":876902313, \"emailID\":\"priya@gmail.com\"}\n", 149 | " records[\"age\"]\n", 150 | "except Exception as e:\n", 151 | " print(e)" 152 | ], 153 | "metadata": { 154 | "colab": { 155 | "base_uri": "https://localhost:8080/" 156 | }, 157 | "id": "Ir02TyKcot4J", 158 | "outputId": "62e09a04-d631-4d1e-805f-4a566a39e07a" 159 | }, 160 | "execution_count": 9, 161 | "outputs": [ 162 | { 163 | "output_type": "stream", 164 | "name": "stdout", 165 | "text": [ 166 | "'age'\n" 167 | ] 168 | } 169 | ] 170 | }, 171 | { 172 | "cell_type": "code", 173 | "source": [ 174 | "try :\n", 175 | " a = int(input())\n", 176 | " b = int(input())\n", 177 | " c = a/b\n", 178 | " print(c)\n", 179 | "\n", 180 | "except Exception as e:\n", 181 | " print(e)\n", 182 | "\n", 183 | "else:\n", 184 | " print(\"It will execute only when your try block will execute successfully\")" 185 | ], 186 | "metadata": { 187 | "colab": { 188 | "base_uri": "https://localhost:8080/" 189 | }, 190 | "id": "XAueMalOpZqB", 191 | "outputId": "f7d9bf44-56a2-42dc-f8b5-3d2afdc35cc9" 192 | }, 193 | "execution_count": 12, 194 | "outputs": [ 195 | { 196 | "output_type": "stream", 197 | "name": "stdout", 198 | "text": [ 199 | "6\n", 200 | "0\n", 201 | "division by zero\n" 202 | ] 203 | } 204 | ] 205 | }, 206 | { 207 | "cell_type": "code", 208 | "source": [ 209 | "try :\n", 210 | " a = int(input())\n", 211 | " b = int(input())\n", 212 | " c = a/b\n", 213 | " print(c)\n", 214 | "\n", 215 | "except Exception as e:\n", 216 | " print(e)\n", 217 | "\n", 218 | "else:\n", 219 | " print(\"This block will execute only when your try block will execute successfully\")\n", 220 | "\n", 221 | "finally:\n", 222 | " print(\"This block will execute always\")" 223 | ], 224 | "metadata": { 225 | "colab": { 226 | "base_uri": "https://localhost:8080/" 227 | }, 228 | "id": "pP56rF9YqUtt", 229 | "outputId": "e52724a6-1b8a-48d1-c46e-2dee67519412" 230 | }, 231 | "execution_count": 14, 232 | "outputs": [ 233 | { 234 | "output_type": "stream", 235 | "name": "stdout", 236 | "text": [ 237 | "6\n", 238 | "0\n", 239 | "division by zero\n", 240 | "This block will execute always\n" 241 | ] 242 | } 243 | ] 244 | }, 245 | { 246 | "cell_type": "markdown", 247 | "source": [ 248 | "**Data Preprocessing Phase**" 249 | ], 250 | "metadata": { 251 | "id": "y9JKmt4EsmQG" 252 | } 253 | }, 254 | { 255 | "cell_type": "code", 256 | "source": [ 257 | "try :\n", 258 | " file_path = \"/content/demo.txt\"\n", 259 | " f = open(file_path)\n", 260 | " f.read()\n", 261 | "\n", 262 | "except Exception as e:\n", 263 | " print(e)\n", 264 | "\n", 265 | "else:\n", 266 | " print(\"EDA Stuff\")\n" 267 | ], 268 | "metadata": { 269 | "colab": { 270 | "base_uri": "https://localhost:8080/" 271 | }, 272 | "id": "vaWjscsLrL8w", 273 | "outputId": "9810e826-ceb3-4116-f397-f082ae74ccc0" 274 | }, 275 | "execution_count": 18, 276 | "outputs": [ 277 | { 278 | "output_type": "stream", 279 | "name": "stdout", 280 | "text": [ 281 | "EDA Stuff\n" 282 | ] 283 | } 284 | ] 285 | }, 286 | { 287 | "cell_type": "code", 288 | "source": [], 289 | "metadata": { 290 | "id": "YQDCe1c8sKgA" 291 | }, 292 | "execution_count": null, 293 | "outputs": [] 294 | } 295 | ] 296 | } -------------------------------------------------------------------------------- /Mastering Variables in Python/Mastering Variables in Python - LIVE!.ipynb: -------------------------------------------------------------------------------- 1 | {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"authorship_tag":"ABX9TyO2DxbNWtogJDDzFVAZU1Bb"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"code","execution_count":1,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"uH2bh6uTxQJt","executionInfo":{"status":"ok","timestamp":1695825501874,"user_tz":-330,"elapsed":1190,"user":{"displayName":"priya bhatia","userId":"00515267356904697155"}},"outputId":"5bca1e66-1863-4eff-8d95-75864ed4637d"},"outputs":[{"output_type":"execute_result","data":{"text/plain":["5"]},"metadata":{},"execution_count":1}],"source":["2 + 3"]},{"cell_type":"code","source":["x = 2\n","y = 3\n","z = x + y"],"metadata":{"id":"AS3eXnUNE5ch","executionInfo":{"status":"ok","timestamp":1695826053977,"user_tz":-330,"elapsed":9,"user":{"displayName":"priya bhatia","userId":"00515267356904697155"}}},"execution_count":2,"outputs":[]},{"cell_type":"code","source":["z"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"m-ievOGkHAY_","executionInfo":{"status":"ok","timestamp":1695826062695,"user_tz":-330,"elapsed":7,"user":{"displayName":"priya bhatia","userId":"00515267356904697155"}},"outputId":"06b21e6c-63d8-436c-95e9-2142ed70e5ad"},"execution_count":3,"outputs":[{"output_type":"execute_result","data":{"text/plain":["5"]},"metadata":{},"execution_count":3}]},{"cell_type":"code","source":["type(x)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"DrnKbDMeHCOv","executionInfo":{"status":"ok","timestamp":1695826180701,"user_tz":-330,"elapsed":501,"user":{"displayName":"priya bhatia","userId":"00515267356904697155"}},"outputId":"c87091b4-ca23-4274-cf38-cd3a6f786389"},"execution_count":4,"outputs":[{"output_type":"execute_result","data":{"text/plain":["int"]},"metadata":{},"execution_count":4}]},{"cell_type":"code","source":["type(y)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"iWTI2WWpHfVW","executionInfo":{"status":"ok","timestamp":1695826196597,"user_tz":-330,"elapsed":6,"user":{"displayName":"priya bhatia","userId":"00515267356904697155"}},"outputId":"ff8036da-267a-41a5-87d2-4b5a45bcc9b9"},"execution_count":5,"outputs":[{"output_type":"execute_result","data":{"text/plain":["int"]},"metadata":{},"execution_count":5}]},{"cell_type":"code","source":["type(z)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"qifbm3yOHi-m","executionInfo":{"status":"ok","timestamp":1695826201917,"user_tz":-330,"elapsed":789,"user":{"displayName":"priya bhatia","userId":"00515267356904697155"}},"outputId":"dcf53a02-7f36-4163-d153-bd74b791e564"},"execution_count":6,"outputs":[{"output_type":"execute_result","data":{"text/plain":["int"]},"metadata":{},"execution_count":6}]},{"cell_type":"code","source":["x = 3.568912\n","z = x + y"],"metadata":{"id":"6p-3ezMQHkb2","executionInfo":{"status":"ok","timestamp":1695826344525,"user_tz":-330,"elapsed":886,"user":{"displayName":"priya bhatia","userId":"00515267356904697155"}}},"execution_count":7,"outputs":[]},{"cell_type":"code","source":["z"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"wgerj63MIHOm","executionInfo":{"status":"ok","timestamp":1695826349135,"user_tz":-330,"elapsed":7,"user":{"displayName":"priya bhatia","userId":"00515267356904697155"}},"outputId":"7a2d47ee-b631-47fa-e854-477b6c551555"},"execution_count":8,"outputs":[{"output_type":"execute_result","data":{"text/plain":["6.568912"]},"metadata":{},"execution_count":8}]},{"cell_type":"code","source":["type(x)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"EPpdc7sEIIXO","executionInfo":{"status":"ok","timestamp":1695826458121,"user_tz":-330,"elapsed":788,"user":{"displayName":"priya bhatia","userId":"00515267356904697155"}},"outputId":"4e397ceb-4e3b-4384-cac7-0ab638f27cc3"},"execution_count":9,"outputs":[{"output_type":"execute_result","data":{"text/plain":["float"]},"metadata":{},"execution_count":9}]},{"cell_type":"code","source":["name = \"Priya\"\n","name"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":36},"id":"IzFD3RnaIi_G","executionInfo":{"status":"ok","timestamp":1695826502558,"user_tz":-330,"elapsed":940,"user":{"displayName":"priya bhatia","userId":"00515267356904697155"}},"outputId":"0e8de560-f9e6-4a46-db95-4d7a0e31ab82"},"execution_count":10,"outputs":[{"output_type":"execute_result","data":{"text/plain":["'Priya'"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"string"}},"metadata":{},"execution_count":10}]},{"cell_type":"code","source":["type(name)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"dhuTrwYCItv-","executionInfo":{"status":"ok","timestamp":1695826572247,"user_tz":-330,"elapsed":1091,"user":{"displayName":"priya bhatia","userId":"00515267356904697155"}},"outputId":"422982c3-e52f-41c6-b07a-2542754001ca"},"execution_count":11,"outputs":[{"output_type":"execute_result","data":{"text/plain":["str"]},"metadata":{},"execution_count":11}]},{"cell_type":"code","source":["fullName = name + \" Bhatia\""],"metadata":{"id":"DZW-k4AxI-jN","executionInfo":{"status":"ok","timestamp":1695826634011,"user_tz":-330,"elapsed":843,"user":{"displayName":"priya bhatia","userId":"00515267356904697155"}}},"execution_count":14,"outputs":[]},{"cell_type":"code","source":["fullName"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":36},"id":"Zi0AEA5mJJ9k","executionInfo":{"status":"ok","timestamp":1695826639422,"user_tz":-330,"elapsed":9,"user":{"displayName":"priya bhatia","userId":"00515267356904697155"}},"outputId":"aa2486c4-3008-43bd-cdce-9e27c86f391b"},"execution_count":15,"outputs":[{"output_type":"execute_result","data":{"text/plain":["'Priya Bhatia'"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"string"}},"metadata":{},"execution_count":15}]},{"cell_type":"code","source":["name + \"123\""],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":36},"id":"UWDDWrcYJPC0","executionInfo":{"status":"ok","timestamp":1695826790513,"user_tz":-330,"elapsed":533,"user":{"displayName":"priya bhatia","userId":"00515267356904697155"}},"outputId":"19a5a7f8-13a8-4000-ccb2-903dafc91776"},"execution_count":17,"outputs":[{"output_type":"execute_result","data":{"text/plain":["'Priya123'"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"string"}},"metadata":{},"execution_count":17}]},{"cell_type":"code","source":["val = True\n","type(val)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"G9_nPgP6JvA0","executionInfo":{"status":"ok","timestamp":1695826852718,"user_tz":-330,"elapsed":1192,"user":{"displayName":"priya bhatia","userId":"00515267356904697155"}},"outputId":"f0c3cd21-d94d-4421-ed0f-657ebc169c4c"},"execution_count":18,"outputs":[{"output_type":"execute_result","data":{"text/plain":["bool"]},"metadata":{},"execution_count":18}]},{"cell_type":"code","source":["complexNum = 7 + 2j\n","type(complexNum)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"8cYAjjufKDLf","executionInfo":{"status":"ok","timestamp":1695827040727,"user_tz":-330,"elapsed":527,"user":{"displayName":"priya bhatia","userId":"00515267356904697155"}},"outputId":"204a99a0-0399-489c-8053-52f8fa21c369"},"execution_count":19,"outputs":[{"output_type":"execute_result","data":{"text/plain":["complex"]},"metadata":{},"execution_count":19}]},{"cell_type":"code","source":["complexNum.real"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"1lsc6NUyKxC-","executionInfo":{"status":"ok","timestamp":1695827126634,"user_tz":-330,"elapsed":14,"user":{"displayName":"priya bhatia","userId":"00515267356904697155"}},"outputId":"32e5325c-3802-4f07-ba67-1dd88066fb2f"},"execution_count":20,"outputs":[{"output_type":"execute_result","data":{"text/plain":["7.0"]},"metadata":{},"execution_count":20}]},{"cell_type":"code","source":["complexNum.imag"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"HY_giX12LGRM","executionInfo":{"status":"ok","timestamp":1695827176620,"user_tz":-330,"elapsed":9,"user":{"displayName":"priya bhatia","userId":"00515267356904697155"}},"outputId":"6dddf927-fa33-4e2e-993e-c691170c6d10"},"execution_count":21,"outputs":[{"output_type":"execute_result","data":{"text/plain":["2.0"]},"metadata":{},"execution_count":21}]},{"cell_type":"code","source":["complexNum"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"x4aJk94fLSOj","executionInfo":{"status":"ok","timestamp":1695827324460,"user_tz":-330,"elapsed":530,"user":{"displayName":"priya bhatia","userId":"00515267356904697155"}},"outputId":"bbe73a1f-043b-4a8f-cdd0-5e3b84165a19"},"execution_count":23,"outputs":[{"output_type":"execute_result","data":{"text/plain":["(7+2j)"]},"metadata":{},"execution_count":23}]},{"cell_type":"code","source":["val1 = True ##1\n","val2 = False ##0\n","\n","val1 - val2"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"L83b3iN5LqH6","executionInfo":{"status":"ok","timestamp":1695827425414,"user_tz":-330,"elapsed":5,"user":{"displayName":"priya bhatia","userId":"00515267356904697155"}},"outputId":"238a7273-76a3-431a-830e-ac60d2e56a7c"},"execution_count":24,"outputs":[{"output_type":"execute_result","data":{"text/plain":["1"]},"metadata":{},"execution_count":24}]},{"cell_type":"code","source":["val1 * val2"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"QcxTiFnOMPS6","executionInfo":{"status":"ok","timestamp":1695827527889,"user_tz":-330,"elapsed":693,"user":{"displayName":"priya bhatia","userId":"00515267356904697155"}},"outputId":"b5fc539e-97cc-453f-ba63-da018ae0dc46"},"execution_count":25,"outputs":[{"output_type":"execute_result","data":{"text/plain":["0"]},"metadata":{},"execution_count":25}]},{"cell_type":"code","source":[],"metadata":{"id":"NCoXk6qTMoLc"},"execution_count":null,"outputs":[]}]} -------------------------------------------------------------------------------- /Python Interview Questions Explained - LIVE!/Python's_Interview_Questions_Explained.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [] 7 | }, 8 | "kernelspec": { 9 | "name": "python3", 10 | "display_name": "Python 3" 11 | }, 12 | "language_info": { 13 | "name": "python" 14 | } 15 | }, 16 | "cells": [ 17 | { 18 | "cell_type": "markdown", 19 | "source": [ 20 | "1. What is the difference between tuple and list." 21 | ], 22 | "metadata": { 23 | "id": "MTD9_iCcz5bp" 24 | } 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "source": [ 29 | "\n", 30 | "\n", 31 | "1. Tuple is immutable(cannot change) whereas list is mutable(change)\n", 32 | "2. Tuple is much faster as comprable to list\n", 33 | "3. Tuple () whereas list []\n", 34 | "\n" 35 | ], 36 | "metadata": { 37 | "id": "pc3xVbLI0tQ9" 38 | } 39 | }, 40 | { 41 | "cell_type": "code", 42 | "source": [ 43 | "tuple1 = (1, 2, 5, 6)\n", 44 | "list1 = [2, 5, 7, 12]" 45 | ], 46 | "metadata": { 47 | "id": "WoML4ly0oZ6K" 48 | }, 49 | "execution_count": 12, 50 | "outputs": [] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "source": [ 55 | "type(tuple1)" 56 | ], 57 | "metadata": { 58 | "colab": { 59 | "base_uri": "https://localhost:8080/" 60 | }, 61 | "id": "ZoWEnJl51yht", 62 | "outputId": "3cb6775a-057c-4f5e-b34a-3c86a4877823" 63 | }, 64 | "execution_count": 13, 65 | "outputs": [ 66 | { 67 | "output_type": "execute_result", 68 | "data": { 69 | "text/plain": [ 70 | "tuple" 71 | ] 72 | }, 73 | "metadata": {}, 74 | "execution_count": 13 75 | } 76 | ] 77 | }, 78 | { 79 | "cell_type": "code", 80 | "source": [ 81 | "type(list1)" 82 | ], 83 | "metadata": { 84 | "colab": { 85 | "base_uri": "https://localhost:8080/" 86 | }, 87 | "id": "PTc6D7ZZ10Te", 88 | "outputId": "22e3c410-dfd5-440d-f455-5eebb726bbda" 89 | }, 90 | "execution_count": 14, 91 | "outputs": [ 92 | { 93 | "output_type": "execute_result", 94 | "data": { 95 | "text/plain": [ 96 | "list" 97 | ] 98 | }, 99 | "metadata": {}, 100 | "execution_count": 14 101 | } 102 | ] 103 | }, 104 | { 105 | "cell_type": "markdown", 106 | "source": [ 107 | "2. Given a list of numbers containing the duplicates, remove the duplicate elements from the list." 108 | ], 109 | "metadata": { 110 | "id": "JS2Fov2G143b" 111 | } 112 | }, 113 | { 114 | "cell_type": "code", 115 | "source": [ 116 | "list2 = [1, 2, 4, 2, 5, 7, 5, 8, 12, 7]\n", 117 | "## expected output = [1, 2, 4, 5, 7, 8, 12]\n", 118 | "\n", 119 | "def remove_duplicates(list2):\n", 120 | " return list(set(list2))\n", 121 | "\n", 122 | "print(remove_duplicates(list2))" 123 | ], 124 | "metadata": { 125 | "colab": { 126 | "base_uri": "https://localhost:8080/" 127 | }, 128 | "id": "ygYMsFK011pN", 129 | "outputId": "653b358e-3a4a-4f33-ceb9-e3ec07adeb93" 130 | }, 131 | "execution_count": 15, 132 | "outputs": [ 133 | { 134 | "output_type": "stream", 135 | "name": "stdout", 136 | "text": [ 137 | "[1, 2, 4, 5, 7, 8, 12]\n" 138 | ] 139 | } 140 | ] 141 | }, 142 | { 143 | "cell_type": "markdown", 144 | "source": [ 145 | "3. Given a string, reverse it." 146 | ], 147 | "metadata": { 148 | "id": "l2Ce0YeE3TzL" 149 | } 150 | }, 151 | { 152 | "cell_type": "code", 153 | "source": [ 154 | "s1 = \"Priya\"\n", 155 | "## expected output = \"ayirP\"\n", 156 | "\n", 157 | "def reverse_string(s1):\n", 158 | " return s1[::-1]\n", 159 | "\n", 160 | "print(reverse_string(s1))" 161 | ], 162 | "metadata": { 163 | "colab": { 164 | "base_uri": "https://localhost:8080/" 165 | }, 166 | "id": "nD_VhEjZ2Zq7", 167 | "outputId": "2741216a-416c-4046-ce19-363c00b5ac04" 168 | }, 169 | "execution_count": 16, 170 | "outputs": [ 171 | { 172 | "output_type": "stream", 173 | "name": "stdout", 174 | "text": [ 175 | "ayirP\n" 176 | ] 177 | } 178 | ] 179 | }, 180 | { 181 | "cell_type": "markdown", 182 | "source": [ 183 | "4. Given a string, check whether the string is palindromic or not." 184 | ], 185 | "metadata": { 186 | "id": "vH0G5EKI3-5a" 187 | } 188 | }, 189 | { 190 | "cell_type": "code", 191 | "source": [ 192 | "s1 = \"mommy\"\n", 193 | "\n", 194 | "def palidromic_string(s1):\n", 195 | " return s1 == s1[::-1]\n", 196 | "\n", 197 | "print(palidromic_string(s1))" 198 | ], 199 | "metadata": { 200 | "colab": { 201 | "base_uri": "https://localhost:8080/" 202 | }, 203 | "id": "jss6Ohea38K-", 204 | "outputId": "fc42368c-5fa6-4200-d257-e59a66a766af" 205 | }, 206 | "execution_count": 18, 207 | "outputs": [ 208 | { 209 | "output_type": "stream", 210 | "name": "stdout", 211 | "text": [ 212 | "False\n" 213 | ] 214 | } 215 | ] 216 | }, 217 | { 218 | "cell_type": "markdown", 219 | "source": [ 220 | "5. Difference between shallow copy and deep copy" 221 | ], 222 | "metadata": { 223 | "id": "usFzFxYC4zdD" 224 | } 225 | }, 226 | { 227 | "cell_type": "code", 228 | "source": [ 229 | "## shallow copy\n", 230 | "import copy\n", 231 | "list1 = [[1, 2, 3], [4, 5, 6]]\n", 232 | "list2 = copy.copy(list1)\n", 233 | "list2[0][2] = 10\n", 234 | "print(list1)" 235 | ], 236 | "metadata": { 237 | "colab": { 238 | "base_uri": "https://localhost:8080/" 239 | }, 240 | "id": "1bnbdQTd4pQ8", 241 | "outputId": "8957b97e-6e4f-4cf8-a38d-13e432b4a5ce" 242 | }, 243 | "execution_count": 19, 244 | "outputs": [ 245 | { 246 | "output_type": "stream", 247 | "name": "stdout", 248 | "text": [ 249 | "[[1, 2, 10], [4, 5, 6]]\n" 250 | ] 251 | } 252 | ] 253 | }, 254 | { 255 | "cell_type": "code", 256 | "source": [ 257 | "## deep copy\n", 258 | "list3 = copy.deepcopy(list1)\n", 259 | "list3[0][1] = 20\n", 260 | "print(list1)" 261 | ], 262 | "metadata": { 263 | "colab": { 264 | "base_uri": "https://localhost:8080/" 265 | }, 266 | "id": "1-fcpx3W5oIk", 267 | "outputId": "fc7274c3-a771-4aaf-dec9-3d249d0fb76e" 268 | }, 269 | "execution_count": 20, 270 | "outputs": [ 271 | { 272 | "output_type": "stream", 273 | "name": "stdout", 274 | "text": [ 275 | "[[1, 2, 10], [4, 5, 6]]\n" 276 | ] 277 | } 278 | ] 279 | }, 280 | { 281 | "cell_type": "markdown", 282 | "source": [ 283 | "6. How do you handle exceptions in Python?" 284 | ], 285 | "metadata": { 286 | "id": "3MBJ-DDK6Wld" 287 | } 288 | }, 289 | { 290 | "cell_type": "code", 291 | "source": [ 292 | "try:\n", 293 | " x = 1/0\n", 294 | "except ZeroDivisionError:\n", 295 | " print(\"U can't divide by Zero\")" 296 | ], 297 | "metadata": { 298 | "colab": { 299 | "base_uri": "https://localhost:8080/" 300 | }, 301 | "id": "TABfkXd06LDN", 302 | "outputId": "36676ea8-8053-46b0-e865-6183869b8332" 303 | }, 304 | "execution_count": 21, 305 | "outputs": [ 306 | { 307 | "output_type": "stream", 308 | "name": "stdout", 309 | "text": [ 310 | "U can't divide by Zero\n" 311 | ] 312 | } 313 | ] 314 | }, 315 | { 316 | "cell_type": "markdown", 317 | "source": [ 318 | "7. What is lambda functions in Python" 319 | ], 320 | "metadata": { 321 | "id": "-5wdqqgI7CBp" 322 | } 323 | }, 324 | { 325 | "cell_type": "code", 326 | "source": [ 327 | "add = lambda a, b:a+b\n", 328 | "print(add(2,3))" 329 | ], 330 | "metadata": { 331 | "colab": { 332 | "base_uri": "https://localhost:8080/" 333 | }, 334 | "id": "6maeC_1a6uKi", 335 | "outputId": "8601aa03-361f-4bfa-8f48-41bee4040e5f" 336 | }, 337 | "execution_count": 23, 338 | "outputs": [ 339 | { 340 | "output_type": "stream", 341 | "name": "stdout", 342 | "text": [ 343 | "5\n" 344 | ] 345 | } 346 | ] 347 | }, 348 | { 349 | "cell_type": "markdown", 350 | "source": [ 351 | "8. What is list comprehension in Python" 352 | ], 353 | "metadata": { 354 | "id": "s5C8_9hA7hTN" 355 | } 356 | }, 357 | { 358 | "cell_type": "code", 359 | "source": [ 360 | "## Given a list, give me the squares of every element available in the list\n", 361 | "squares = [x**2 for x in range(10)]\n", 362 | "print(squares)" 363 | ], 364 | "metadata": { 365 | "colab": { 366 | "base_uri": "https://localhost:8080/" 367 | }, 368 | "id": "3RtdIkKT7dL8", 369 | "outputId": "1d18f662-7063-4236-b42b-a52f24cbf2d2" 370 | }, 371 | "execution_count": 24, 372 | "outputs": [ 373 | { 374 | "output_type": "stream", 375 | "name": "stdout", 376 | "text": [ 377 | "[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]\n" 378 | ] 379 | } 380 | ] 381 | }, 382 | { 383 | "cell_type": "code", 384 | "source": [ 385 | "range(10)" 386 | ], 387 | "metadata": { 388 | "colab": { 389 | "base_uri": "https://localhost:8080/" 390 | }, 391 | "id": "TGNGqNKF8Kq8", 392 | "outputId": "1abe07ad-e58b-4413-9a6e-adaa7673b64d" 393 | }, 394 | "execution_count": 25, 395 | "outputs": [ 396 | { 397 | "output_type": "execute_result", 398 | "data": { 399 | "text/plain": [ 400 | "range(0, 10)" 401 | ] 402 | }, 403 | "metadata": {}, 404 | "execution_count": 25 405 | } 406 | ] 407 | }, 408 | { 409 | "cell_type": "markdown", 410 | "source": [ 411 | "9. Count the number of times a particular character appears in a string" 412 | ], 413 | "metadata": { 414 | "id": "IpdsPnCc8Wyf" 415 | } 416 | }, 417 | { 418 | "cell_type": "code", 419 | "source": [ 420 | "str1 = \"priyabhatia\"\n", 421 | "## Given a string, count how many times a character appears in a given string\n", 422 | "def count_char(str1, char):\n", 423 | " return str1.count(char)\n", 424 | "\n", 425 | "print(count_char(str1, \"a\"))" 426 | ], 427 | "metadata": { 428 | "colab": { 429 | "base_uri": "https://localhost:8080/" 430 | }, 431 | "id": "WwfNQUcQ8Opz", 432 | "outputId": "711d26bb-ae49-423e-fbc5-1c73d8ca5399" 433 | }, 434 | "execution_count": 26, 435 | "outputs": [ 436 | { 437 | "output_type": "stream", 438 | "name": "stdout", 439 | "text": [ 440 | "3\n" 441 | ] 442 | } 443 | ] 444 | }, 445 | { 446 | "cell_type": "markdown", 447 | "source": [ 448 | "10. Given two sorted list, merge both of them and create another sorted list." 449 | ], 450 | "metadata": { 451 | "id": "0G35ZQxK89PF" 452 | } 453 | }, 454 | { 455 | "cell_type": "code", 456 | "source": [ 457 | "## list1 = [1, 3, 7]\n", 458 | "## list2 = [2, 5, 6]\n", 459 | "## expected output = [1, 2, 3, 5, 6, 7]\n", 460 | "## write your own code\n", 461 | "## approach 1: sorted(list1 + list2)\n", 462 | "## approch 2: mergeProcedure - mergeSort{DSA using Python}" 463 | ], 464 | "metadata": { 465 | "id": "O_UxMmjI83xr" 466 | }, 467 | "execution_count": null, 468 | "outputs": [] 469 | } 470 | ] 471 | } -------------------------------------------------------------------------------- /Mastering Python's Functional Tools/Mastering_Python's_Functional_Tools.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [] 7 | }, 8 | "kernelspec": { 9 | "name": "python3", 10 | "display_name": "Python 3" 11 | }, 12 | "language_info": { 13 | "name": "python" 14 | } 15 | }, 16 | "cells": [ 17 | { 18 | "cell_type": "markdown", 19 | "source": [ 20 | "Implement a function where the result is the cube of a given number" 21 | ], 22 | "metadata": { 23 | "id": "Maz_zU15KfmM" 24 | } 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": 1, 29 | "metadata": { 30 | "colab": { 31 | "base_uri": "https://localhost:8080/" 32 | }, 33 | "id": "wGhasdRUB9Lb", 34 | "outputId": "d8ad8cbb-e294-4a7e-9e01-373d2f3cb298" 35 | }, 36 | "outputs": [ 37 | { 38 | "output_type": "stream", 39 | "name": "stdout", 40 | "text": [ 41 | "27\n" 42 | ] 43 | } 44 | ], 45 | "source": [ 46 | "def cube(x):\n", 47 | " return x*x*x\n", 48 | "\n", 49 | "print(cube(3))" 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "source": [ 55 | "Lambda Functions - Anonymous Functions that can be used to define a single line of code." 56 | ], 57 | "metadata": { 58 | "id": "numL_Yf-K4hF" 59 | } 60 | }, 61 | { 62 | "cell_type": "code", 63 | "source": [ 64 | "lambda_cube = lambda x:x*x*x\n", 65 | "\n", 66 | "lambda_cube(3)" 67 | ], 68 | "metadata": { 69 | "colab": { 70 | "base_uri": "https://localhost:8080/" 71 | }, 72 | "id": "Yy9fadRzKrny", 73 | "outputId": "d5580667-2463-459d-be4f-3e4523172317" 74 | }, 75 | "execution_count": 2, 76 | "outputs": [ 77 | { 78 | "output_type": "execute_result", 79 | "data": { 80 | "text/plain": [ 81 | "27" 82 | ] 83 | }, 84 | "metadata": {}, 85 | "execution_count": 2 86 | } 87 | ] 88 | }, 89 | { 90 | "cell_type": "markdown", 91 | "source": [ 92 | "**Implement a code that adds two numbers**" 93 | ], 94 | "metadata": { 95 | "id": "mnBePDeLLddN" 96 | } 97 | }, 98 | { 99 | "cell_type": "code", 100 | "source": [ 101 | "lambda_sum = lambda x,y:x+y\n", 102 | "\n", 103 | "lambda_sum(2,3)" 104 | ], 105 | "metadata": { 106 | "colab": { 107 | "base_uri": "https://localhost:8080/" 108 | }, 109 | "id": "pkuIc-_jLKdh", 110 | "outputId": "212f8dbe-f157-42d1-b1a8-984a2492439d" 111 | }, 112 | "execution_count": 3, 113 | "outputs": [ 114 | { 115 | "output_type": "execute_result", 116 | "data": { 117 | "text/plain": [ 118 | "5" 119 | ] 120 | }, 121 | "metadata": {}, 122 | "execution_count": 3 123 | } 124 | ] 125 | }, 126 | { 127 | "cell_type": "markdown", 128 | "source": [ 129 | "**Sort a list of dictionaries on the basis of a specific key**" 130 | ], 131 | "metadata": { 132 | "id": "XVVUeeYhMCF9" 133 | } 134 | }, 135 | { 136 | "cell_type": "code", 137 | "source": [ 138 | "employee_records = [{'name':'John', 'age':29, 'occupation':'engineer'},\n", 139 | " {'name':'Vikash', 'age':25, 'occupation':'doctor'},\n", 140 | " {'name':'Nikhil', 'age':25, 'occupation':'engineer'},\n", 141 | " {'name':'Teja', 'age':23, 'occupation':'data scientist'},\n", 142 | " {'name':'Priya', 'age':25, 'occupation':'engineer'},]" 143 | ], 144 | "metadata": { 145 | "id": "wBH4snr0LvqK" 146 | }, 147 | "execution_count": 6, 148 | "outputs": [] 149 | }, 150 | { 151 | "cell_type": "markdown", 152 | "source": [ 153 | "**Sort the data on the basis of the key value as age**" 154 | ], 155 | "metadata": { 156 | "id": "awZCP2OTNc7T" 157 | } 158 | }, 159 | { 160 | "cell_type": "code", 161 | "source": [ 162 | "sorted(employee_records, key=lambda x:x['age'])" 163 | ], 164 | "metadata": { 165 | "colab": { 166 | "base_uri": "https://localhost:8080/" 167 | }, 168 | "id": "RG8-5Qp9Mr6e", 169 | "outputId": "1c0302f1-397a-4a25-e481-998d73f7200b" 170 | }, 171 | "execution_count": 7, 172 | "outputs": [ 173 | { 174 | "output_type": "execute_result", 175 | "data": { 176 | "text/plain": [ 177 | "[{'name': 'Teja', 'age': 23, 'occupation': 'data scientist'},\n", 178 | " {'name': 'Vikash', 'age': 25, 'occupation': 'doctor'},\n", 179 | " {'name': 'Nikhil', 'age': 25, 'occupation': 'engineer'},\n", 180 | " {'name': 'Priya', 'age': 25, 'occupation': 'engineer'},\n", 181 | " {'name': 'John', 'age': 29, 'occupation': 'engineer'}]" 182 | ] 183 | }, 184 | "metadata": {}, 185 | "execution_count": 7 186 | } 187 | ] 188 | }, 189 | { 190 | "cell_type": "markdown", 191 | "source": [ 192 | "**Sort the data on the basis of key value as age, name**" 193 | ], 194 | "metadata": { 195 | "id": "gbTqbnmSNhWL" 196 | } 197 | }, 198 | { 199 | "cell_type": "code", 200 | "source": [ 201 | "sorted(employee_records, key=lambda x:(x['age'], x['name']))" 202 | ], 203 | "metadata": { 204 | "colab": { 205 | "base_uri": "https://localhost:8080/" 206 | }, 207 | "id": "dLdIz88MM7-W", 208 | "outputId": "85455f45-d9da-4c6a-f766-324425bbf7a6" 209 | }, 210 | "execution_count": 8, 211 | "outputs": [ 212 | { 213 | "output_type": "execute_result", 214 | "data": { 215 | "text/plain": [ 216 | "[{'name': 'Teja', 'age': 23, 'occupation': 'data scientist'},\n", 217 | " {'name': 'Nikhil', 'age': 25, 'occupation': 'engineer'},\n", 218 | " {'name': 'Priya', 'age': 25, 'occupation': 'engineer'},\n", 219 | " {'name': 'Vikash', 'age': 25, 'occupation': 'doctor'},\n", 220 | " {'name': 'John', 'age': 29, 'occupation': 'engineer'}]" 221 | ] 222 | }, 223 | "metadata": {}, 224 | "execution_count": 8 225 | } 226 | ] 227 | }, 228 | { 229 | "cell_type": "markdown", 230 | "source": [ 231 | "**Implement a function which results the square of every number available in the list**" 232 | ], 233 | "metadata": { 234 | "id": "pG4KSGoxO6Ws" 235 | } 236 | }, 237 | { 238 | "cell_type": "code", 239 | "source": [ 240 | "l1 = [2, 4, 5, 7, 9]\n", 241 | "newl1 = []\n", 242 | "\n", 243 | "for ele in l1:\n", 244 | " newl1.append(ele**2)\n", 245 | "print(newl1)" 246 | ], 247 | "metadata": { 248 | "colab": { 249 | "base_uri": "https://localhost:8080/" 250 | }, 251 | "id": "FY4LoDWfNxR3", 252 | "outputId": "8ac70028-41f4-4c14-fb65-18eda4a62e4b" 253 | }, 254 | "execution_count": 9, 255 | "outputs": [ 256 | { 257 | "output_type": "stream", 258 | "name": "stdout", 259 | "text": [ 260 | "[4, 16, 25, 49, 81]\n" 261 | ] 262 | } 263 | ] 264 | }, 265 | { 266 | "cell_type": "markdown", 267 | "source": [ 268 | "Map Function - Scan the entire list and corresponding to every element available in the list, you are looking for some kind of output." 269 | ], 270 | "metadata": { 271 | "id": "I5XL2DdAQ_SE" 272 | } 273 | }, 274 | { 275 | "cell_type": "code", 276 | "source": [ 277 | "l2 = list(map(lambda l1:l1**2, l1))\n", 278 | "print(l2)" 279 | ], 280 | "metadata": { 281 | "colab": { 282 | "base_uri": "https://localhost:8080/" 283 | }, 284 | "id": "ceHwSVxrPP-E", 285 | "outputId": "caa7be82-c436-4b77-ae53-d88fcb475ad5" 286 | }, 287 | "execution_count": 10, 288 | "outputs": [ 289 | { 290 | "output_type": "stream", 291 | "name": "stdout", 292 | "text": [ 293 | "[4, 16, 25, 49, 81]\n" 294 | ] 295 | } 296 | ] 297 | }, 298 | { 299 | "cell_type": "code", 300 | "source": [ 301 | "map(lambda l1:l1**2, l1)" 302 | ], 303 | "metadata": { 304 | "colab": { 305 | "base_uri": "https://localhost:8080/" 306 | }, 307 | "id": "BV35TP8rPygV", 308 | "outputId": "a323bf7b-faee-4023-b911-9a01f9796268" 309 | }, 310 | "execution_count": 11, 311 | "outputs": [ 312 | { 313 | "output_type": "execute_result", 314 | "data": { 315 | "text/plain": [ 316 | "" 317 | ] 318 | }, 319 | "metadata": {}, 320 | "execution_count": 11 321 | } 322 | ] 323 | }, 324 | { 325 | "cell_type": "code", 326 | "source": [ 327 | "x1 = lambda l1:l1**2\n", 328 | "x1(2)" 329 | ], 330 | "metadata": { 331 | "colab": { 332 | "base_uri": "https://localhost:8080/" 333 | }, 334 | "id": "b4Je7fZgQLX1", 335 | "outputId": "9a002361-938b-4d64-be41-7ef8e48e3787" 336 | }, 337 | "execution_count": 14, 338 | "outputs": [ 339 | { 340 | "output_type": "execute_result", 341 | "data": { 342 | "text/plain": [ 343 | "4" 344 | ] 345 | }, 346 | "metadata": {}, 347 | "execution_count": 14 348 | } 349 | ] 350 | }, 351 | { 352 | "cell_type": "code", 353 | "source": [ 354 | "## l1 = [2, 5, 7, 9]\n", 355 | "## l2 = [2, 7]\n", 356 | "\n", 357 | "## common/intersection values of both l1 and l2\n", 358 | "## output = [2, 7]" 359 | ], 360 | "metadata": { 361 | "id": "BWSwhgGXQVeW" 362 | }, 363 | "execution_count": null, 364 | "outputs": [] 365 | }, 366 | { 367 | "cell_type": "markdown", 368 | "source": [ 369 | "**Filter: Given a list, return the even elements available in the list.**\n", 370 | "\n", 371 | "Subset of the given list by having some sort of constraints." 372 | ], 373 | "metadata": { 374 | "id": "pdubx9VMRfaU" 375 | } 376 | }, 377 | { 378 | "cell_type": "code", 379 | "source": [ 380 | "l3 = [2, 3, 5, 7, 9, 11, 12, 16]\n", 381 | "l4 = list(filter(lambda x:x%2 == 0, l3))\n", 382 | "print(l4)" 383 | ], 384 | "metadata": { 385 | "colab": { 386 | "base_uri": "https://localhost:8080/" 387 | }, 388 | "id": "AnBp6i_ZRfJ6", 389 | "outputId": "388510ab-8d34-43a6-ea15-1d536c6b2625" 390 | }, 391 | "execution_count": 15, 392 | "outputs": [ 393 | { 394 | "output_type": "stream", 395 | "name": "stdout", 396 | "text": [ 397 | "[2, 12, 16]\n" 398 | ] 399 | } 400 | ] 401 | }, 402 | { 403 | "cell_type": "code", 404 | "source": [ 405 | "filter(lambda x:x%2 == 0, l3)" 406 | ], 407 | "metadata": { 408 | "colab": { 409 | "base_uri": "https://localhost:8080/" 410 | }, 411 | "id": "6zwuBXvWVXY4", 412 | "outputId": "e104561c-d044-4258-a5f1-df775d132fde" 413 | }, 414 | "execution_count": 17, 415 | "outputs": [ 416 | { 417 | "output_type": "execute_result", 418 | "data": { 419 | "text/plain": [ 420 | "" 421 | ] 422 | }, 423 | "metadata": {}, 424 | "execution_count": 17 425 | } 426 | ] 427 | }, 428 | { 429 | "cell_type": "markdown", 430 | "source": [ 431 | "Reduce: Given a list, return the sum of the entire list.\n", 432 | "\n", 433 | "Single output - reduce function" 434 | ], 435 | "metadata": { 436 | "id": "-6GJvCF9S2w2" 437 | } 438 | }, 439 | { 440 | "cell_type": "code", 441 | "source": [ 442 | "from functools import reduce\n", 443 | "sum_list = reduce(lambda x,y:x+y, l3)\n", 444 | "print(sum_list)" 445 | ], 446 | "metadata": { 447 | "colab": { 448 | "base_uri": "https://localhost:8080/" 449 | }, 450 | "id": "NRE0-RlwSYAS", 451 | "outputId": "fa0985fb-ea55-41b3-e114-281bf724b206" 452 | }, 453 | "execution_count": 16, 454 | "outputs": [ 455 | { 456 | "output_type": "stream", 457 | "name": "stdout", 458 | "text": [ 459 | "65\n" 460 | ] 461 | } 462 | ] 463 | }, 464 | { 465 | "cell_type": "code", 466 | "source": [], 467 | "metadata": { 468 | "id": "xlk6unUwTakR" 469 | }, 470 | "execution_count": null, 471 | "outputs": [] 472 | } 473 | ] 474 | } -------------------------------------------------------------------------------- /Mastering Python Strings/Mastering_Python_Strings_LIVE.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [] 7 | }, 8 | "kernelspec": { 9 | "name": "python3", 10 | "display_name": "Python 3" 11 | }, 12 | "language_info": { 13 | "name": "python" 14 | } 15 | }, 16 | "cells": [ 17 | { 18 | "cell_type": "code", 19 | "execution_count": 1, 20 | "metadata": { 21 | "id": "W1GOxw13R4xl" 22 | }, 23 | "outputs": [], 24 | "source": [ 25 | "## intialization of a string in python\n", 26 | "str1 = \"Priya\"" 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "source": [ 32 | "type(str1)" 33 | ], 34 | "metadata": { 35 | "colab": { 36 | "base_uri": "https://localhost:8080/" 37 | }, 38 | "id": "HRJ4TJ4cUN9b", 39 | "outputId": "e1689b28-0bf7-49fd-c0fa-62e728e5aba8" 40 | }, 41 | "execution_count": 2, 42 | "outputs": [ 43 | { 44 | "output_type": "execute_result", 45 | "data": { 46 | "text/plain": [ 47 | "str" 48 | ] 49 | }, 50 | "metadata": {}, 51 | "execution_count": 2 52 | } 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "source": [ 58 | "## indexing of the characters in the string\n", 59 | "str1[3]" 60 | ], 61 | "metadata": { 62 | "colab": { 63 | "base_uri": "https://localhost:8080/", 64 | "height": 36 65 | }, 66 | "id": "RKkhBleEUam_", 67 | "outputId": "7a8441ed-fb3d-48ba-d33e-34151f55f898" 68 | }, 69 | "execution_count": 3, 70 | "outputs": [ 71 | { 72 | "output_type": "execute_result", 73 | "data": { 74 | "text/plain": [ 75 | "'y'" 76 | ], 77 | "application/vnd.google.colaboratory.intrinsic+json": { 78 | "type": "string" 79 | } 80 | }, 81 | "metadata": {}, 82 | "execution_count": 3 83 | } 84 | ] 85 | }, 86 | { 87 | "cell_type": "code", 88 | "source": [ 89 | "str1[-1]" 90 | ], 91 | "metadata": { 92 | "colab": { 93 | "base_uri": "https://localhost:8080/", 94 | "height": 36 95 | }, 96 | "id": "Ae-mVyObU_pG", 97 | "outputId": "1427b3fd-3d16-431d-b82b-9d4a5472f14b" 98 | }, 99 | "execution_count": 4, 100 | "outputs": [ 101 | { 102 | "output_type": "execute_result", 103 | "data": { 104 | "text/plain": [ 105 | "'a'" 106 | ], 107 | "application/vnd.google.colaboratory.intrinsic+json": { 108 | "type": "string" 109 | } 110 | }, 111 | "metadata": {}, 112 | "execution_count": 4 113 | } 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "source": [ 119 | "str1[-5]" 120 | ], 121 | "metadata": { 122 | "colab": { 123 | "base_uri": "https://localhost:8080/", 124 | "height": 36 125 | }, 126 | "id": "s3hfCzyEVbL9", 127 | "outputId": "06fae567-355b-4c16-fbd2-0a890b5129dc" 128 | }, 129 | "execution_count": 5, 130 | "outputs": [ 131 | { 132 | "output_type": "execute_result", 133 | "data": { 134 | "text/plain": [ 135 | "'P'" 136 | ], 137 | "application/vnd.google.colaboratory.intrinsic+json": { 138 | "type": "string" 139 | } 140 | }, 141 | "metadata": {}, 142 | "execution_count": 5 143 | } 144 | ] 145 | }, 146 | { 147 | "cell_type": "code", 148 | "source": [ 149 | "## length of the string\n", 150 | "len(str1)" 151 | ], 152 | "metadata": { 153 | "colab": { 154 | "base_uri": "https://localhost:8080/" 155 | }, 156 | "id": "ta3F-S2vVdZV", 157 | "outputId": "ff81bbe3-18ba-41d3-ad84-9ed216263569" 158 | }, 159 | "execution_count": 6, 160 | "outputs": [ 161 | { 162 | "output_type": "execute_result", 163 | "data": { 164 | "text/plain": [ 165 | "5" 166 | ] 167 | }, 168 | "metadata": {}, 169 | "execution_count": 6 170 | } 171 | ] 172 | }, 173 | { 174 | "cell_type": "code", 175 | "source": [ 176 | "## inbuilt function of the string\n", 177 | "## find - search a character in a string\n", 178 | "## if the character in a string - return the index\n", 179 | "## if the character is not in a string - return -1\n", 180 | "str1.find('a')" 181 | ], 182 | "metadata": { 183 | "colab": { 184 | "base_uri": "https://localhost:8080/" 185 | }, 186 | "id": "Uu82RfvoV2fO", 187 | "outputId": "f8a0ed1f-35de-4f46-db9f-3d71c5c78117" 188 | }, 189 | "execution_count": 7, 190 | "outputs": [ 191 | { 192 | "output_type": "execute_result", 193 | "data": { 194 | "text/plain": [ 195 | "4" 196 | ] 197 | }, 198 | "metadata": {}, 199 | "execution_count": 7 200 | } 201 | ] 202 | }, 203 | { 204 | "cell_type": "code", 205 | "source": [ 206 | "str1.find('z')" 207 | ], 208 | "metadata": { 209 | "colab": { 210 | "base_uri": "https://localhost:8080/" 211 | }, 212 | "id": "cwiWthgAWQ49", 213 | "outputId": "8f829429-3392-47d1-c8e4-a5ab06034ceb" 214 | }, 215 | "execution_count": 8, 216 | "outputs": [ 217 | { 218 | "output_type": "execute_result", 219 | "data": { 220 | "text/plain": [ 221 | "-1" 222 | ] 223 | }, 224 | "metadata": {}, 225 | "execution_count": 8 226 | } 227 | ] 228 | }, 229 | { 230 | "cell_type": "code", 231 | "source": [ 232 | "## split function\n", 233 | "## realtime application: Natural Language Processing(Textual Data)\n", 234 | "## Sentiment Analysis\n", 235 | "text = \"Hello Priya\"\n", 236 | "text.split()" 237 | ], 238 | "metadata": { 239 | "colab": { 240 | "base_uri": "https://localhost:8080/" 241 | }, 242 | "id": "Hj2QxYSkWmms", 243 | "outputId": "6fd7b29a-c7bc-48ac-969e-cd851ecc85cd" 244 | }, 245 | "execution_count": 15, 246 | "outputs": [ 247 | { 248 | "output_type": "execute_result", 249 | "data": { 250 | "text/plain": [ 251 | "['Hello', 'Priya']" 252 | ] 253 | }, 254 | "metadata": {}, 255 | "execution_count": 15 256 | } 257 | ] 258 | }, 259 | { 260 | "cell_type": "code", 261 | "source": [ 262 | "## replace the word 'Priya' to 'Python'\n", 263 | "## reassignment\n", 264 | "text = text.replace('Priya', 'Python')" 265 | ], 266 | "metadata": { 267 | "id": "aik2ef_NYDis" 268 | }, 269 | "execution_count": 12, 270 | "outputs": [] 271 | }, 272 | { 273 | "cell_type": "code", 274 | "source": [ 275 | "text" 276 | ], 277 | "metadata": { 278 | "colab": { 279 | "base_uri": "https://localhost:8080/", 280 | "height": 36 281 | }, 282 | "id": "FKHXn1bOYkvz", 283 | "outputId": "506ce636-29d1-42e5-9559-9f03ac958466" 284 | }, 285 | "execution_count": 13, 286 | "outputs": [ 287 | { 288 | "output_type": "execute_result", 289 | "data": { 290 | "text/plain": [ 291 | "'Hello Python'" 292 | ], 293 | "application/vnd.google.colaboratory.intrinsic+json": { 294 | "type": "string" 295 | } 296 | }, 297 | "metadata": {}, 298 | "execution_count": 13 299 | } 300 | ] 301 | }, 302 | { 303 | "cell_type": "code", 304 | "source": [ 305 | "## count function - count the given characters\n", 306 | "str2 = \"Priya Bhatia\"\n", 307 | "## how many time 'a' appear in the str2\n", 308 | "str2.count('a')" 309 | ], 310 | "metadata": { 311 | "colab": { 312 | "base_uri": "https://localhost:8080/" 313 | }, 314 | "id": "I15mqK8MYz-V", 315 | "outputId": "4f0bbca7-e1e4-4de1-ea2f-9e8b7f868cde" 316 | }, 317 | "execution_count": 18, 318 | "outputs": [ 319 | { 320 | "output_type": "execute_result", 321 | "data": { 322 | "text/plain": [ 323 | "3" 324 | ] 325 | }, 326 | "metadata": {}, 327 | "execution_count": 18 328 | } 329 | ] 330 | }, 331 | { 332 | "cell_type": "code", 333 | "source": [ 334 | "str2.count('b')" 335 | ], 336 | "metadata": { 337 | "colab": { 338 | "base_uri": "https://localhost:8080/" 339 | }, 340 | "id": "NvQbqMphZuw7", 341 | "outputId": "5f20fc97-105e-432e-d25f-05be6b2e65a8" 342 | }, 343 | "execution_count": 19, 344 | "outputs": [ 345 | { 346 | "output_type": "execute_result", 347 | "data": { 348 | "text/plain": [ 349 | "0" 350 | ] 351 | }, 352 | "metadata": {}, 353 | "execution_count": 19 354 | } 355 | ] 356 | }, 357 | { 358 | "cell_type": "code", 359 | "source": [ 360 | "str2.count('B')" 361 | ], 362 | "metadata": { 363 | "colab": { 364 | "base_uri": "https://localhost:8080/" 365 | }, 366 | "id": "ogbJrJVjaSjZ", 367 | "outputId": "5305af89-f24b-4eb8-ed83-ae8c0f370557" 368 | }, 369 | "execution_count": 20, 370 | "outputs": [ 371 | { 372 | "output_type": "execute_result", 373 | "data": { 374 | "text/plain": [ 375 | "1" 376 | ] 377 | }, 378 | "metadata": {}, 379 | "execution_count": 20 380 | } 381 | ] 382 | }, 383 | { 384 | "cell_type": "code", 385 | "source": [ 386 | "## conversion to lowercase characters\n", 387 | "str2.lower()" 388 | ], 389 | "metadata": { 390 | "colab": { 391 | "base_uri": "https://localhost:8080/", 392 | "height": 36 393 | }, 394 | "id": "feZ3rpCQaU0J", 395 | "outputId": "19652597-34c2-4634-f8a3-7d443ca0e562" 396 | }, 397 | "execution_count": 21, 398 | "outputs": [ 399 | { 400 | "output_type": "execute_result", 401 | "data": { 402 | "text/plain": [ 403 | "'priya bhatia'" 404 | ], 405 | "application/vnd.google.colaboratory.intrinsic+json": { 406 | "type": "string" 407 | } 408 | }, 409 | "metadata": {}, 410 | "execution_count": 21 411 | } 412 | ] 413 | }, 414 | { 415 | "cell_type": "code", 416 | "source": [ 417 | "## conversion to uppercase characters\n", 418 | "str2.upper()" 419 | ], 420 | "metadata": { 421 | "colab": { 422 | "base_uri": "https://localhost:8080/", 423 | "height": 36 424 | }, 425 | "id": "m-EvDEpwafIo", 426 | "outputId": "c4bb8709-95dc-4ce8-c4aa-a733bbdef891" 427 | }, 428 | "execution_count": 22, 429 | "outputs": [ 430 | { 431 | "output_type": "execute_result", 432 | "data": { 433 | "text/plain": [ 434 | "'PRIYA BHATIA'" 435 | ], 436 | "application/vnd.google.colaboratory.intrinsic+json": { 437 | "type": "string" 438 | } 439 | }, 440 | "metadata": {}, 441 | "execution_count": 22 442 | } 443 | ] 444 | }, 445 | { 446 | "cell_type": "code", 447 | "source": [ 448 | "## swapcase - lower case converted to upper and vice-versa\n", 449 | "str2.swapcase()" 450 | ], 451 | "metadata": { 452 | "colab": { 453 | "base_uri": "https://localhost:8080/", 454 | "height": 36 455 | }, 456 | "id": "CJLNi42uaknx", 457 | "outputId": "cef34765-2243-450e-dd88-70b6efa43cf4" 458 | }, 459 | "execution_count": 23, 460 | "outputs": [ 461 | { 462 | "output_type": "execute_result", 463 | "data": { 464 | "text/plain": [ 465 | "'pRIYA bHATIA'" 466 | ], 467 | "application/vnd.google.colaboratory.intrinsic+json": { 468 | "type": "string" 469 | } 470 | }, 471 | "metadata": {}, 472 | "execution_count": 23 473 | } 474 | ] 475 | }, 476 | { 477 | "cell_type": "code", 478 | "source": [ 479 | "## title() and capitalize()\n", 480 | "str3 = \"this is the mastering python strings masterclass hosted by priya bhatia\"\n", 481 | "str3.title()" 482 | ], 483 | "metadata": { 484 | "colab": { 485 | "base_uri": "https://localhost:8080/", 486 | "height": 36 487 | }, 488 | "id": "iURcE9lqaxXy", 489 | "outputId": "2fe8d83d-89ec-4b13-a7d6-18bd2a5dabeb" 490 | }, 491 | "execution_count": 24, 492 | "outputs": [ 493 | { 494 | "output_type": "execute_result", 495 | "data": { 496 | "text/plain": [ 497 | "'This Is The Mastering Python Strings Masterclass Hosted By Priya Bhatia'" 498 | ], 499 | "application/vnd.google.colaboratory.intrinsic+json": { 500 | "type": "string" 501 | } 502 | }, 503 | "metadata": {}, 504 | "execution_count": 24 505 | } 506 | ] 507 | }, 508 | { 509 | "cell_type": "code", 510 | "source": [ 511 | "str3.capitalize()" 512 | ], 513 | "metadata": { 514 | "colab": { 515 | "base_uri": "https://localhost:8080/", 516 | "height": 36 517 | }, 518 | "id": "AoHiH7_ubWoJ", 519 | "outputId": "7873d3ab-ef35-44af-a0ee-166fe120be4e" 520 | }, 521 | "execution_count": 25, 522 | "outputs": [ 523 | { 524 | "output_type": "execute_result", 525 | "data": { 526 | "text/plain": [ 527 | "'This is the mastering python strings masterclass hosted by priya bhatia'" 528 | ], 529 | "application/vnd.google.colaboratory.intrinsic+json": { 530 | "type": "string" 531 | } 532 | }, 533 | "metadata": {}, 534 | "execution_count": 25 535 | } 536 | ] 537 | }, 538 | { 539 | "cell_type": "code", 540 | "source": [ 541 | "## slicing\n", 542 | "str1[0:3]" 543 | ], 544 | "metadata": { 545 | "colab": { 546 | "base_uri": "https://localhost:8080/", 547 | "height": 36 548 | }, 549 | "id": "kQkVEE7NbgY4", 550 | "outputId": "a5981fba-5b63-49d4-e6f2-21b879485bf8" 551 | }, 552 | "execution_count": 26, 553 | "outputs": [ 554 | { 555 | "output_type": "execute_result", 556 | "data": { 557 | "text/plain": [ 558 | "'Pri'" 559 | ], 560 | "application/vnd.google.colaboratory.intrinsic+json": { 561 | "type": "string" 562 | } 563 | }, 564 | "metadata": {}, 565 | "execution_count": 26 566 | } 567 | ] 568 | }, 569 | { 570 | "cell_type": "code", 571 | "source": [ 572 | "str1[0:5:2]" 573 | ], 574 | "metadata": { 575 | "colab": { 576 | "base_uri": "https://localhost:8080/", 577 | "height": 36 578 | }, 579 | "id": "m9EeyVq3cTd_", 580 | "outputId": "57a99057-89b6-4f1f-b671-34c7e6c60b57" 581 | }, 582 | "execution_count": 27, 583 | "outputs": [ 584 | { 585 | "output_type": "execute_result", 586 | "data": { 587 | "text/plain": [ 588 | "'Pia'" 589 | ], 590 | "application/vnd.google.colaboratory.intrinsic+json": { 591 | "type": "string" 592 | } 593 | }, 594 | "metadata": {}, 595 | "execution_count": 27 596 | } 597 | ] 598 | }, 599 | { 600 | "cell_type": "code", 601 | "source": [ 602 | "str1[::2]" 603 | ], 604 | "metadata": { 605 | "colab": { 606 | "base_uri": "https://localhost:8080/", 607 | "height": 36 608 | }, 609 | "id": "EmXIhBMpcxzI", 610 | "outputId": "9f5926bf-8ce8-4103-95e1-f2135d42a83f" 611 | }, 612 | "execution_count": 28, 613 | "outputs": [ 614 | { 615 | "output_type": "execute_result", 616 | "data": { 617 | "text/plain": [ 618 | "'Pia'" 619 | ], 620 | "application/vnd.google.colaboratory.intrinsic+json": { 621 | "type": "string" 622 | } 623 | }, 624 | "metadata": {}, 625 | "execution_count": 28 626 | } 627 | ] 628 | }, 629 | { 630 | "cell_type": "code", 631 | "source": [ 632 | "## reversal of a complete string\n", 633 | "str1[4::-1]" 634 | ], 635 | "metadata": { 636 | "colab": { 637 | "base_uri": "https://localhost:8080/", 638 | "height": 36 639 | }, 640 | "id": "c9S0zXxoc4uP", 641 | "outputId": "59cb47b9-c2cc-4939-afe0-30d1571bcfb4" 642 | }, 643 | "execution_count": 29, 644 | "outputs": [ 645 | { 646 | "output_type": "execute_result", 647 | "data": { 648 | "text/plain": [ 649 | "'ayirP'" 650 | ], 651 | "application/vnd.google.colaboratory.intrinsic+json": { 652 | "type": "string" 653 | } 654 | }, 655 | "metadata": {}, 656 | "execution_count": 29 657 | } 658 | ] 659 | }, 660 | { 661 | "cell_type": "code", 662 | "source": [ 663 | "str1[::-1]" 664 | ], 665 | "metadata": { 666 | "colab": { 667 | "base_uri": "https://localhost:8080/", 668 | "height": 36 669 | }, 670 | "id": "c5bCNmEMdi0_", 671 | "outputId": "8c6e2af0-740d-484a-d696-4ca0476f7967" 672 | }, 673 | "execution_count": 30, 674 | "outputs": [ 675 | { 676 | "output_type": "execute_result", 677 | "data": { 678 | "text/plain": [ 679 | "'ayirP'" 680 | ], 681 | "application/vnd.google.colaboratory.intrinsic+json": { 682 | "type": "string" 683 | } 684 | }, 685 | "metadata": {}, 686 | "execution_count": 30 687 | } 688 | ] 689 | }, 690 | { 691 | "cell_type": "code", 692 | "source": [ 693 | "## return - 'ayi'\n", 694 | "str1[:1:-1]" 695 | ], 696 | "metadata": { 697 | "colab": { 698 | "base_uri": "https://localhost:8080/", 699 | "height": 36 700 | }, 701 | "id": "_IAyEU2tdrau", 702 | "outputId": "2b50d101-be5b-4461-9e26-1fcbb51e5ce6" 703 | }, 704 | "execution_count": 33, 705 | "outputs": [ 706 | { 707 | "output_type": "execute_result", 708 | "data": { 709 | "text/plain": [ 710 | "'ayi'" 711 | ], 712 | "application/vnd.google.colaboratory.intrinsic+json": { 713 | "type": "string" 714 | } 715 | }, 716 | "metadata": {}, 717 | "execution_count": 33 718 | } 719 | ] 720 | }, 721 | { 722 | "cell_type": "code", 723 | "source": [], 724 | "metadata": { 725 | "id": "ZpB4fd46eaG_" 726 | }, 727 | "execution_count": null, 728 | "outputs": [] 729 | } 730 | ] 731 | } -------------------------------------------------------------------------------- /Mastering the Power Of NumPy in Python - LIVE!/Mastering_the_Power_Of_NumPy.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [] 7 | }, 8 | "kernelspec": { 9 | "name": "python3", 10 | "display_name": "Python 3" 11 | }, 12 | "language_info": { 13 | "name": "python" 14 | } 15 | }, 16 | "cells": [ 17 | { 18 | "cell_type": "code", 19 | "execution_count": 1, 20 | "metadata": { 21 | "id": "CxVa1VX7z_Vc" 22 | }, 23 | "outputs": [], 24 | "source": [ 25 | "import numpy as np" 26 | ] 27 | }, 28 | { 29 | "cell_type": "markdown", 30 | "source": [ 31 | "Understanding of 1D, 2D and 3D array in numpy" 32 | ], 33 | "metadata": { 34 | "id": "2BLy2mfKIixz" 35 | } 36 | }, 37 | { 38 | "cell_type": "code", 39 | "source": [ 40 | "arr = np.array([1, 3, 4, 7, 9])" 41 | ], 42 | "metadata": { 43 | "id": "IG5lGRWaEk6I" 44 | }, 45 | "execution_count": 2, 46 | "outputs": [] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "source": [ 51 | "arr" 52 | ], 53 | "metadata": { 54 | "colab": { 55 | "base_uri": "https://localhost:8080/" 56 | }, 57 | "id": "RrOeVosQEwu5", 58 | "outputId": "98888485-2474-4a59-e470-26ab3932c4a1" 59 | }, 60 | "execution_count": 3, 61 | "outputs": [ 62 | { 63 | "output_type": "execute_result", 64 | "data": { 65 | "text/plain": [ 66 | "array([1, 3, 4, 7, 9])" 67 | ] 68 | }, 69 | "metadata": {}, 70 | "execution_count": 3 71 | } 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "source": [ 77 | "type(arr)" 78 | ], 79 | "metadata": { 80 | "colab": { 81 | "base_uri": "https://localhost:8080/" 82 | }, 83 | "id": "WTUaBhHYExPP", 84 | "outputId": "4adcf59b-724c-4869-9569-a65dc8194abc" 85 | }, 86 | "execution_count": 4, 87 | "outputs": [ 88 | { 89 | "output_type": "execute_result", 90 | "data": { 91 | "text/plain": [ 92 | "numpy.ndarray" 93 | ] 94 | }, 95 | "metadata": {}, 96 | "execution_count": 4 97 | } 98 | ] 99 | }, 100 | { 101 | "cell_type": "code", 102 | "source": [ 103 | "arr.ndim" 104 | ], 105 | "metadata": { 106 | "colab": { 107 | "base_uri": "https://localhost:8080/" 108 | }, 109 | "id": "qcdVLB5LF95n", 110 | "outputId": "605d8b9c-6a05-4dad-a2e2-de333a6594cf" 111 | }, 112 | "execution_count": 13, 113 | "outputs": [ 114 | { 115 | "output_type": "execute_result", 116 | "data": { 117 | "text/plain": [ 118 | "1" 119 | ] 120 | }, 121 | "metadata": {}, 122 | "execution_count": 13 123 | } 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "source": [ 129 | "arr.shape" 130 | ], 131 | "metadata": { 132 | "colab": { 133 | "base_uri": "https://localhost:8080/" 134 | }, 135 | "id": "0HUvJ72tGIOK", 136 | "outputId": "4720ac3f-b85b-44ae-b90e-7994e0f14fcf" 137 | }, 138 | "execution_count": 15, 139 | "outputs": [ 140 | { 141 | "output_type": "execute_result", 142 | "data": { 143 | "text/plain": [ 144 | "(5,)" 145 | ] 146 | }, 147 | "metadata": {}, 148 | "execution_count": 15 149 | } 150 | ] 151 | }, 152 | { 153 | "cell_type": "code", 154 | "source": [ 155 | "arr2 = np.array([[1, 3], [4, 7]])" 156 | ], 157 | "metadata": { 158 | "id": "q8aN4bwqE18O" 159 | }, 160 | "execution_count": 5, 161 | "outputs": [] 162 | }, 163 | { 164 | "cell_type": "code", 165 | "source": [ 166 | "arr2" 167 | ], 168 | "metadata": { 169 | "colab": { 170 | "base_uri": "https://localhost:8080/" 171 | }, 172 | "id": "SjWVkvn9FERn", 173 | "outputId": "5b97c6d5-670e-4de0-f631-6a2f969e61a4" 174 | }, 175 | "execution_count": 6, 176 | "outputs": [ 177 | { 178 | "output_type": "execute_result", 179 | "data": { 180 | "text/plain": [ 181 | "array([[1, 3],\n", 182 | " [4, 7]])" 183 | ] 184 | }, 185 | "metadata": {}, 186 | "execution_count": 6 187 | } 188 | ] 189 | }, 190 | { 191 | "cell_type": "code", 192 | "source": [ 193 | "type(arr2)" 194 | ], 195 | "metadata": { 196 | "colab": { 197 | "base_uri": "https://localhost:8080/" 198 | }, 199 | "id": "noqN2kzBFE9A", 200 | "outputId": "533ff314-1f7c-414f-eb1c-d78848f07b8f" 201 | }, 202 | "execution_count": 7, 203 | "outputs": [ 204 | { 205 | "output_type": "execute_result", 206 | "data": { 207 | "text/plain": [ 208 | "numpy.ndarray" 209 | ] 210 | }, 211 | "metadata": {}, 212 | "execution_count": 7 213 | } 214 | ] 215 | }, 216 | { 217 | "cell_type": "code", 218 | "source": [ 219 | "arr2.shape" 220 | ], 221 | "metadata": { 222 | "colab": { 223 | "base_uri": "https://localhost:8080/" 224 | }, 225 | "id": "LjxsZLSxGMCu", 226 | "outputId": "a1470ada-d85b-477a-902e-d5087fdf6ca7" 227 | }, 228 | "execution_count": 16, 229 | "outputs": [ 230 | { 231 | "output_type": "execute_result", 232 | "data": { 233 | "text/plain": [ 234 | "(2, 2)" 235 | ] 236 | }, 237 | "metadata": {}, 238 | "execution_count": 16 239 | } 240 | ] 241 | }, 242 | { 243 | "cell_type": "code", 244 | "source": [ 245 | "arr2.ndim" 246 | ], 247 | "metadata": { 248 | "colab": { 249 | "base_uri": "https://localhost:8080/" 250 | }, 251 | "id": "bpDefdvxF7GK", 252 | "outputId": "66c4aff2-bf3c-4df7-9d6c-e6cdac364823" 253 | }, 254 | "execution_count": 12, 255 | "outputs": [ 256 | { 257 | "output_type": "execute_result", 258 | "data": { 259 | "text/plain": [ 260 | "2" 261 | ] 262 | }, 263 | "metadata": {}, 264 | "execution_count": 12 265 | } 266 | ] 267 | }, 268 | { 269 | "cell_type": "code", 270 | "source": [ 271 | "arr3 = np.array([[[1, 3], [4, 7]], [[2,4],[5,7]]])\n", 272 | "arr3" 273 | ], 274 | "metadata": { 275 | "colab": { 276 | "base_uri": "https://localhost:8080/" 277 | }, 278 | "id": "n7CNFx9XFGg_", 279 | "outputId": "3878a579-7181-408b-934b-368f540b83fd" 280 | }, 281 | "execution_count": 8, 282 | "outputs": [ 283 | { 284 | "output_type": "execute_result", 285 | "data": { 286 | "text/plain": [ 287 | "array([[[1, 3],\n", 288 | " [4, 7]],\n", 289 | "\n", 290 | " [[2, 4],\n", 291 | " [5, 7]]])" 292 | ] 293 | }, 294 | "metadata": {}, 295 | "execution_count": 8 296 | } 297 | ] 298 | }, 299 | { 300 | "cell_type": "code", 301 | "source": [ 302 | "type(arr3)" 303 | ], 304 | "metadata": { 305 | "colab": { 306 | "base_uri": "https://localhost:8080/" 307 | }, 308 | "id": "EheGQF48Fi3Q", 309 | "outputId": "f569cfa4-ad3f-4027-c1c9-c569792660af" 310 | }, 311 | "execution_count": 9, 312 | "outputs": [ 313 | { 314 | "output_type": "execute_result", 315 | "data": { 316 | "text/plain": [ 317 | "numpy.ndarray" 318 | ] 319 | }, 320 | "metadata": {}, 321 | "execution_count": 9 322 | } 323 | ] 324 | }, 325 | { 326 | "cell_type": "code", 327 | "source": [ 328 | "arr3.ndim" 329 | ], 330 | "metadata": { 331 | "colab": { 332 | "base_uri": "https://localhost:8080/" 333 | }, 334 | "id": "1ygBDNRkFk6u", 335 | "outputId": "a12ed79c-f878-4dcd-9773-d5f999607875" 336 | }, 337 | "execution_count": 11, 338 | "outputs": [ 339 | { 340 | "output_type": "execute_result", 341 | "data": { 342 | "text/plain": [ 343 | "3" 344 | ] 345 | }, 346 | "metadata": {}, 347 | "execution_count": 11 348 | } 349 | ] 350 | }, 351 | { 352 | "cell_type": "code", 353 | "source": [ 354 | "arr3.shape" 355 | ], 356 | "metadata": { 357 | "colab": { 358 | "base_uri": "https://localhost:8080/" 359 | }, 360 | "id": "uy0HE3puFvXU", 361 | "outputId": "e9b0ddd7-4ead-4605-b441-4cf4e4c47cc8" 362 | }, 363 | "execution_count": 14, 364 | "outputs": [ 365 | { 366 | "output_type": "execute_result", 367 | "data": { 368 | "text/plain": [ 369 | "(2, 2, 2)" 370 | ] 371 | }, 372 | "metadata": {}, 373 | "execution_count": 14 374 | } 375 | ] 376 | }, 377 | { 378 | "cell_type": "code", 379 | "source": [ 380 | "arr4 = np.array([[[1, 3], [4, 7]], [[2,4],[5,7]], [[2,6],[4,7]]])\n", 381 | "arr4" 382 | ], 383 | "metadata": { 384 | "colab": { 385 | "base_uri": "https://localhost:8080/" 386 | }, 387 | "id": "sDXj2gWjGGK3", 388 | "outputId": "591aeb32-a6f9-4e72-9f1c-f6aeec2d1d08" 389 | }, 390 | "execution_count": 18, 391 | "outputs": [ 392 | { 393 | "output_type": "execute_result", 394 | "data": { 395 | "text/plain": [ 396 | "array([[[1, 3],\n", 397 | " [4, 7]],\n", 398 | "\n", 399 | " [[2, 4],\n", 400 | " [5, 7]],\n", 401 | "\n", 402 | " [[2, 6],\n", 403 | " [4, 7]]])" 404 | ] 405 | }, 406 | "metadata": {}, 407 | "execution_count": 18 408 | } 409 | ] 410 | }, 411 | { 412 | "cell_type": "code", 413 | "source": [ 414 | "arr4.shape" 415 | ], 416 | "metadata": { 417 | "colab": { 418 | "base_uri": "https://localhost:8080/" 419 | }, 420 | "id": "ExZbkDyKGw7v", 421 | "outputId": "dfee5c78-1792-4e38-fed6-f66c2749db7d" 422 | }, 423 | "execution_count": 19, 424 | "outputs": [ 425 | { 426 | "output_type": "execute_result", 427 | "data": { 428 | "text/plain": [ 429 | "(3, 2, 2)" 430 | ] 431 | }, 432 | "metadata": {}, 433 | "execution_count": 19 434 | } 435 | ] 436 | }, 437 | { 438 | "cell_type": "markdown", 439 | "source": [ 440 | "Difference between the functionalities of arange and linspace function in numpy" 441 | ], 442 | "metadata": { 443 | "id": "StX1W_f2Ib_C" 444 | } 445 | }, 446 | { 447 | "cell_type": "code", 448 | "source": [ 449 | "np.arange(1,9)" 450 | ], 451 | "metadata": { 452 | "colab": { 453 | "base_uri": "https://localhost:8080/" 454 | }, 455 | "id": "eT9DDOcnHCEh", 456 | "outputId": "513e2210-f153-407a-df09-9d855ce7f6d8" 457 | }, 458 | "execution_count": 20, 459 | "outputs": [ 460 | { 461 | "output_type": "execute_result", 462 | "data": { 463 | "text/plain": [ 464 | "array([1, 2, 3, 4, 5, 6, 7, 8])" 465 | ] 466 | }, 467 | "metadata": {}, 468 | "execution_count": 20 469 | } 470 | ] 471 | }, 472 | { 473 | "cell_type": "code", 474 | "source": [ 475 | "np.arange(1,9,2)" 476 | ], 477 | "metadata": { 478 | "colab": { 479 | "base_uri": "https://localhost:8080/" 480 | }, 481 | "id": "R6VwwXynHq42", 482 | "outputId": "2382d3c7-119c-4fc8-b504-69f91ccd2bc2" 483 | }, 484 | "execution_count": 21, 485 | "outputs": [ 486 | { 487 | "output_type": "execute_result", 488 | "data": { 489 | "text/plain": [ 490 | "array([1, 3, 5, 7])" 491 | ] 492 | }, 493 | "metadata": {}, 494 | "execution_count": 21 495 | } 496 | ] 497 | }, 498 | { 499 | "cell_type": "code", 500 | "source": [ 501 | "np.linspace(1,9,5)" 502 | ], 503 | "metadata": { 504 | "colab": { 505 | "base_uri": "https://localhost:8080/" 506 | }, 507 | "id": "iALKPWw_H3oU", 508 | "outputId": "3b07f17a-7537-40a3-f29c-22580b5eae74" 509 | }, 510 | "execution_count": 23, 511 | "outputs": [ 512 | { 513 | "output_type": "execute_result", 514 | "data": { 515 | "text/plain": [ 516 | "array([1., 3., 5., 7., 9.])" 517 | ] 518 | }, 519 | "metadata": {}, 520 | "execution_count": 23 521 | } 522 | ] 523 | }, 524 | { 525 | "cell_type": "markdown", 526 | "source": [ 527 | "Difference between the shallow copy and deep copy in numpy" 528 | ], 529 | "metadata": { 530 | "id": "5QhaUc0KIoSd" 531 | } 532 | }, 533 | { 534 | "cell_type": "code", 535 | "source": [ 536 | "arr2" 537 | ], 538 | "metadata": { 539 | "colab": { 540 | "base_uri": "https://localhost:8080/" 541 | }, 542 | "id": "f-FqfN-pIFCV", 543 | "outputId": "c27ad20b-ca42-40f6-8298-9764775ee3f2" 544 | }, 545 | "execution_count": 24, 546 | "outputs": [ 547 | { 548 | "output_type": "execute_result", 549 | "data": { 550 | "text/plain": [ 551 | "array([[1, 3],\n", 552 | " [4, 7]])" 553 | ] 554 | }, 555 | "metadata": {}, 556 | "execution_count": 24 557 | } 558 | ] 559 | }, 560 | { 561 | "cell_type": "code", 562 | "source": [ 563 | "shallowArr = arr2" 564 | ], 565 | "metadata": { 566 | "id": "SE4jgwFBIz3K" 567 | }, 568 | "execution_count": 25, 569 | "outputs": [] 570 | }, 571 | { 572 | "cell_type": "code", 573 | "source": [ 574 | "deepArr = np.copy(arr2)" 575 | ], 576 | "metadata": { 577 | "id": "nESf9HlgI6y4" 578 | }, 579 | "execution_count": 26, 580 | "outputs": [] 581 | }, 582 | { 583 | "cell_type": "code", 584 | "source": [ 585 | "arr2[0][0] = 5\n", 586 | "arr2" 587 | ], 588 | "metadata": { 589 | "colab": { 590 | "base_uri": "https://localhost:8080/" 591 | }, 592 | "id": "D4u3HdwUJEdZ", 593 | "outputId": "440b6901-0f14-4f1c-d85f-fbf0f2c4630c" 594 | }, 595 | "execution_count": 27, 596 | "outputs": [ 597 | { 598 | "output_type": "execute_result", 599 | "data": { 600 | "text/plain": [ 601 | "array([[5, 3],\n", 602 | " [4, 7]])" 603 | ] 604 | }, 605 | "metadata": {}, 606 | "execution_count": 27 607 | } 608 | ] 609 | }, 610 | { 611 | "cell_type": "code", 612 | "source": [ 613 | "shallowArr" 614 | ], 615 | "metadata": { 616 | "colab": { 617 | "base_uri": "https://localhost:8080/" 618 | }, 619 | "id": "9iQNvV5YJJ6h", 620 | "outputId": "7540053b-0cce-4495-9014-192d60d01b3e" 621 | }, 622 | "execution_count": 28, 623 | "outputs": [ 624 | { 625 | "output_type": "execute_result", 626 | "data": { 627 | "text/plain": [ 628 | "array([[5, 3],\n", 629 | " [4, 7]])" 630 | ] 631 | }, 632 | "metadata": {}, 633 | "execution_count": 28 634 | } 635 | ] 636 | }, 637 | { 638 | "cell_type": "code", 639 | "source": [ 640 | "deepArr" 641 | ], 642 | "metadata": { 643 | "colab": { 644 | "base_uri": "https://localhost:8080/" 645 | }, 646 | "id": "F2uYABDAJTkO", 647 | "outputId": "2611f549-9e35-4bce-9389-8ea00e4f0899" 648 | }, 649 | "execution_count": 29, 650 | "outputs": [ 651 | { 652 | "output_type": "execute_result", 653 | "data": { 654 | "text/plain": [ 655 | "array([[1, 3],\n", 656 | " [4, 7]])" 657 | ] 658 | }, 659 | "metadata": {}, 660 | "execution_count": 29 661 | } 662 | ] 663 | }, 664 | { 665 | "cell_type": "markdown", 666 | "source": [ 667 | "fromfunction in numpy" 668 | ], 669 | "metadata": { 670 | "id": "1aCw6c0kJvoy" 671 | } 672 | }, 673 | { 674 | "cell_type": "code", 675 | "source": [ 676 | "np.fromfunction(lambda i,j:i*j, (4,4))" 677 | ], 678 | "metadata": { 679 | "colab": { 680 | "base_uri": "https://localhost:8080/" 681 | }, 682 | "id": "AW0Q5nkDJV_m", 683 | "outputId": "685a5565-d376-4e60-be6e-f88dd3ed06d0" 684 | }, 685 | "execution_count": 30, 686 | "outputs": [ 687 | { 688 | "output_type": "execute_result", 689 | "data": { 690 | "text/plain": [ 691 | "array([[0., 0., 0., 0.],\n", 692 | " [0., 1., 2., 3.],\n", 693 | " [0., 2., 4., 6.],\n", 694 | " [0., 3., 6., 9.]])" 695 | ] 696 | }, 697 | "metadata": {}, 698 | "execution_count": 30 699 | } 700 | ] 701 | }, 702 | { 703 | "cell_type": "code", 704 | "source": [ 705 | "np.fromfunction(lambda i,j:i+j, (4,4))" 706 | ], 707 | "metadata": { 708 | "colab": { 709 | "base_uri": "https://localhost:8080/" 710 | }, 711 | "id": "aFGyZQe3KLXK", 712 | "outputId": "a2db1068-73b1-4826-c400-fa6c95dd8a6f" 713 | }, 714 | "execution_count": 31, 715 | "outputs": [ 716 | { 717 | "output_type": "execute_result", 718 | "data": { 719 | "text/plain": [ 720 | "array([[0., 1., 2., 3.],\n", 721 | " [1., 2., 3., 4.],\n", 722 | " [2., 3., 4., 5.],\n", 723 | " [3., 4., 5., 6.]])" 724 | ] 725 | }, 726 | "metadata": {}, 727 | "execution_count": 31 728 | } 729 | ] 730 | }, 731 | { 732 | "cell_type": "code", 733 | "source": [ 734 | "np.fromfunction(lambda i,j:i==j, (4,4))" 735 | ], 736 | "metadata": { 737 | "colab": { 738 | "base_uri": "https://localhost:8080/" 739 | }, 740 | "id": "XrCRR4NvKhIC", 741 | "outputId": "1f949a5c-8068-40af-aadb-bb91d88ac625" 742 | }, 743 | "execution_count": 32, 744 | "outputs": [ 745 | { 746 | "output_type": "execute_result", 747 | "data": { 748 | "text/plain": [ 749 | "array([[ True, False, False, False],\n", 750 | " [False, True, False, False],\n", 751 | " [False, False, True, False],\n", 752 | " [False, False, False, True]])" 753 | ] 754 | }, 755 | "metadata": {}, 756 | "execution_count": 32 757 | } 758 | ] 759 | }, 760 | { 761 | "cell_type": "markdown", 762 | "source": [ 763 | "To create an identity matrix" 764 | ], 765 | "metadata": { 766 | "id": "unQ-RNsFLJ2q" 767 | } 768 | }, 769 | { 770 | "cell_type": "code", 771 | "source": [ 772 | "np.eye(4)" 773 | ], 774 | "metadata": { 775 | "colab": { 776 | "base_uri": "https://localhost:8080/" 777 | }, 778 | "id": "q8F8EM6MKm3h", 779 | "outputId": "7df1575f-6ffc-4406-b698-9e57e061e8d6" 780 | }, 781 | "execution_count": 33, 782 | "outputs": [ 783 | { 784 | "output_type": "execute_result", 785 | "data": { 786 | "text/plain": [ 787 | "array([[1., 0., 0., 0.],\n", 788 | " [0., 1., 0., 0.],\n", 789 | " [0., 0., 1., 0.],\n", 790 | " [0., 0., 0., 1.]])" 791 | ] 792 | }, 793 | "metadata": {}, 794 | "execution_count": 33 795 | } 796 | ] 797 | }, 798 | { 799 | "cell_type": "markdown", 800 | "source": [ 801 | "Reshape function in numpy" 802 | ], 803 | "metadata": { 804 | "id": "bJGtev1pLnWv" 805 | } 806 | }, 807 | { 808 | "cell_type": "code", 809 | "source": [ 810 | "dataset = np.linspace(2,9,50)" 811 | ], 812 | "metadata": { 813 | "id": "8cXPE_HnLZFp" 814 | }, 815 | "execution_count": 34, 816 | "outputs": [] 817 | }, 818 | { 819 | "cell_type": "code", 820 | "source": [ 821 | "dataset" 822 | ], 823 | "metadata": { 824 | "colab": { 825 | "base_uri": "https://localhost:8080/" 826 | }, 827 | "id": "NQ5mo-rqME7I", 828 | "outputId": "cd0f1587-020c-4df5-90e5-cd54603c7d10" 829 | }, 830 | "execution_count": 35, 831 | "outputs": [ 832 | { 833 | "output_type": "execute_result", 834 | "data": { 835 | "text/plain": [ 836 | "array([2. , 2.14285714, 2.28571429, 2.42857143, 2.57142857,\n", 837 | " 2.71428571, 2.85714286, 3. , 3.14285714, 3.28571429,\n", 838 | " 3.42857143, 3.57142857, 3.71428571, 3.85714286, 4. ,\n", 839 | " 4.14285714, 4.28571429, 4.42857143, 4.57142857, 4.71428571,\n", 840 | " 4.85714286, 5. , 5.14285714, 5.28571429, 5.42857143,\n", 841 | " 5.57142857, 5.71428571, 5.85714286, 6. , 6.14285714,\n", 842 | " 6.28571429, 6.42857143, 6.57142857, 6.71428571, 6.85714286,\n", 843 | " 7. , 7.14285714, 7.28571429, 7.42857143, 7.57142857,\n", 844 | " 7.71428571, 7.85714286, 8. , 8.14285714, 8.28571429,\n", 845 | " 8.42857143, 8.57142857, 8.71428571, 8.85714286, 9. ])" 846 | ] 847 | }, 848 | "metadata": {}, 849 | "execution_count": 35 850 | } 851 | ] 852 | }, 853 | { 854 | "cell_type": "code", 855 | "source": [ 856 | "dataset.shape" 857 | ], 858 | "metadata": { 859 | "colab": { 860 | "base_uri": "https://localhost:8080/" 861 | }, 862 | "id": "RxnZyMz3MFyH", 863 | "outputId": "21cae827-60f1-48c7-dbd3-afa47dc059f0" 864 | }, 865 | "execution_count": 37, 866 | "outputs": [ 867 | { 868 | "output_type": "execute_result", 869 | "data": { 870 | "text/plain": [ 871 | "(50,)" 872 | ] 873 | }, 874 | "metadata": {}, 875 | "execution_count": 37 876 | } 877 | ] 878 | }, 879 | { 880 | "cell_type": "code", 881 | "source": [ 882 | "dataset.reshape(2,1,25)" 883 | ], 884 | "metadata": { 885 | "colab": { 886 | "base_uri": "https://localhost:8080/" 887 | }, 888 | "id": "UyMRXZupMJS4", 889 | "outputId": "b742c53d-42df-4f07-9436-32c262ebe3e5" 890 | }, 891 | "execution_count": 38, 892 | "outputs": [ 893 | { 894 | "output_type": "execute_result", 895 | "data": { 896 | "text/plain": [ 897 | "array([[[2. , 2.14285714, 2.28571429, 2.42857143, 2.57142857,\n", 898 | " 2.71428571, 2.85714286, 3. , 3.14285714, 3.28571429,\n", 899 | " 3.42857143, 3.57142857, 3.71428571, 3.85714286, 4. ,\n", 900 | " 4.14285714, 4.28571429, 4.42857143, 4.57142857, 4.71428571,\n", 901 | " 4.85714286, 5. , 5.14285714, 5.28571429, 5.42857143]],\n", 902 | "\n", 903 | " [[5.57142857, 5.71428571, 5.85714286, 6. , 6.14285714,\n", 904 | " 6.28571429, 6.42857143, 6.57142857, 6.71428571, 6.85714286,\n", 905 | " 7. , 7.14285714, 7.28571429, 7.42857143, 7.57142857,\n", 906 | " 7.71428571, 7.85714286, 8. , 8.14285714, 8.28571429,\n", 907 | " 8.42857143, 8.57142857, 8.71428571, 8.85714286, 9. ]]])" 908 | ] 909 | }, 910 | "metadata": {}, 911 | "execution_count": 38 912 | } 913 | ] 914 | }, 915 | { 916 | "cell_type": "code", 917 | "source": [ 918 | "dataset.reshape(2,1,25)" 919 | ], 920 | "metadata": { 921 | "colab": { 922 | "base_uri": "https://localhost:8080/" 923 | }, 924 | "id": "MciNfQ9VMbFZ", 925 | "outputId": "0a2c02b1-ad67-43bc-b751-88ce5bd85b71" 926 | }, 927 | "execution_count": 40, 928 | "outputs": [ 929 | { 930 | "output_type": "execute_result", 931 | "data": { 932 | "text/plain": [ 933 | "array([[[2. , 2.14285714, 2.28571429, 2.42857143, 2.57142857,\n", 934 | " 2.71428571, 2.85714286, 3. , 3.14285714, 3.28571429,\n", 935 | " 3.42857143, 3.57142857, 3.71428571, 3.85714286, 4. ,\n", 936 | " 4.14285714, 4.28571429, 4.42857143, 4.57142857, 4.71428571,\n", 937 | " 4.85714286, 5. , 5.14285714, 5.28571429, 5.42857143]],\n", 938 | "\n", 939 | " [[5.57142857, 5.71428571, 5.85714286, 6. , 6.14285714,\n", 940 | " 6.28571429, 6.42857143, 6.57142857, 6.71428571, 6.85714286,\n", 941 | " 7. , 7.14285714, 7.28571429, 7.42857143, 7.57142857,\n", 942 | " 7.71428571, 7.85714286, 8. , 8.14285714, 8.28571429,\n", 943 | " 8.42857143, 8.57142857, 8.71428571, 8.85714286, 9. ]]])" 944 | ] 945 | }, 946 | "metadata": {}, 947 | "execution_count": 40 948 | } 949 | ] 950 | }, 951 | { 952 | "cell_type": "code", 953 | "source": [], 954 | "metadata": { 955 | "id": "_gb7CsCVM6-Y" 956 | }, 957 | "execution_count": null, 958 | "outputs": [] 959 | } 960 | ] 961 | } -------------------------------------------------------------------------------- /Mastering the Power Of Pandas: LIVE!/Mastering_the_Power_Of_Pandas_LIVE.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [] 7 | }, 8 | "kernelspec": { 9 | "name": "python3", 10 | "display_name": "Python 3" 11 | }, 12 | "language_info": { 13 | "name": "python" 14 | } 15 | }, 16 | "cells": [ 17 | { 18 | "cell_type": "markdown", 19 | "source": [ 20 | "Pandas: Open Source Data Analysis library written in Python. It leverages the power and speed of numpy to make data analysis and EDA really easy task for any data scientist." 21 | ], 22 | "metadata": { 23 | "id": "XBzqDA-ZHRNd" 24 | } 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "source": [ 29 | "Data Structure: Dataframe and Series\n", 30 | "\n", 31 | "Operation on Dataframe (Live Demonstration)" 32 | ], 33 | "metadata": { 34 | "id": "DqyXBFIhRH_g" 35 | } 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": 1, 40 | "metadata": { 41 | "id": "f1BHFGr23bY7" 42 | }, 43 | "outputs": [], 44 | "source": [ 45 | "import pandas as pd\n", 46 | "import numpy as np" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "source": [ 52 | "data = pd.read_csv(\"/content/train.csv\")" 53 | ], 54 | "metadata": { 55 | "id": "Q5dsvFcmIVTK" 56 | }, 57 | "execution_count": 2, 58 | "outputs": [] 59 | }, 60 | { 61 | "cell_type": "markdown", 62 | "source": [ 63 | "DataFrame" 64 | ], 65 | "metadata": { 66 | "id": "1j_NRnM7Ll_A" 67 | } 68 | }, 69 | { 70 | "cell_type": "code", 71 | "source": [ 72 | "type(data)" 73 | ], 74 | "metadata": { 75 | "colab": { 76 | "base_uri": "https://localhost:8080/" 77 | }, 78 | "id": "7J3OZeq-KdqK", 79 | "outputId": "8540ae7a-bc7e-4c1a-cc41-47a42ae05426" 80 | }, 81 | "execution_count": 3, 82 | "outputs": [ 83 | { 84 | "output_type": "execute_result", 85 | "data": { 86 | "text/plain": [ 87 | "pandas.core.frame.DataFrame" 88 | ] 89 | }, 90 | "metadata": {}, 91 | "execution_count": 3 92 | } 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "source": [ 98 | "data.head()" 99 | ], 100 | "metadata": { 101 | "colab": { 102 | "base_uri": "https://localhost:8080/", 103 | "height": 345 104 | }, 105 | "id": "fVxl0r0UKjZB", 106 | "outputId": "2b54e030-4229-486a-8e36-60401cff3775" 107 | }, 108 | "execution_count": 4, 109 | "outputs": [ 110 | { 111 | "output_type": "execute_result", 112 | "data": { 113 | "text/plain": [ 114 | " PassengerId Survived Pclass \\\n", 115 | "0 1 0 3 \n", 116 | "1 2 1 1 \n", 117 | "2 3 1 3 \n", 118 | "3 4 1 1 \n", 119 | "4 5 0 3 \n", 120 | "\n", 121 | " Name Sex Age SibSp \\\n", 122 | "0 Braund, Mr. Owen Harris male 22.0 1 \n", 123 | "1 Cumings, Mrs. John Bradley (Florence Briggs Th... female 38.0 1 \n", 124 | "2 Heikkinen, Miss. Laina female 26.0 0 \n", 125 | "3 Futrelle, Mrs. Jacques Heath (Lily May Peel) female 35.0 1 \n", 126 | "4 Allen, Mr. William Henry male 35.0 0 \n", 127 | "\n", 128 | " Parch Ticket Fare Cabin Embarked \n", 129 | "0 0 A/5 21171 7.2500 NaN S \n", 130 | "1 0 PC 17599 71.2833 C85 C \n", 131 | "2 0 STON/O2. 3101282 7.9250 NaN S \n", 132 | "3 0 113803 53.1000 C123 S \n", 133 | "4 0 373450 8.0500 NaN S " 134 | ], 135 | "text/html": [ 136 | "\n", 137 | "
\n", 138 | "
\n", 139 | "\n", 152 | "\n", 153 | " \n", 154 | " \n", 155 | " \n", 156 | " \n", 157 | " \n", 158 | " \n", 159 | " \n", 160 | " \n", 161 | " \n", 162 | " \n", 163 | " \n", 164 | " \n", 165 | " \n", 166 | " \n", 167 | " \n", 168 | " \n", 169 | " \n", 170 | " \n", 171 | " \n", 172 | " \n", 173 | " \n", 174 | " \n", 175 | " \n", 176 | " \n", 177 | " \n", 178 | " \n", 179 | " \n", 180 | " \n", 181 | " \n", 182 | " \n", 183 | " \n", 184 | " \n", 185 | " \n", 186 | " \n", 187 | " \n", 188 | " \n", 189 | " \n", 190 | " \n", 191 | " \n", 192 | " \n", 193 | " \n", 194 | " \n", 195 | " \n", 196 | " \n", 197 | " \n", 198 | " \n", 199 | " \n", 200 | " \n", 201 | " \n", 202 | " \n", 203 | " \n", 204 | " \n", 205 | " \n", 206 | " \n", 207 | " \n", 208 | " \n", 209 | " \n", 210 | " \n", 211 | " \n", 212 | " \n", 213 | " \n", 214 | " \n", 215 | " \n", 216 | " \n", 217 | " \n", 218 | " \n", 219 | " \n", 220 | " \n", 221 | " \n", 222 | " \n", 223 | " \n", 224 | " \n", 225 | " \n", 226 | " \n", 227 | " \n", 228 | " \n", 229 | " \n", 230 | " \n", 231 | " \n", 232 | " \n", 233 | " \n", 234 | " \n", 235 | " \n", 236 | " \n", 237 | " \n", 238 | " \n", 239 | " \n", 240 | " \n", 241 | " \n", 242 | " \n", 243 | " \n", 244 | " \n", 245 | " \n", 246 | " \n", 247 | "
PassengerIdSurvivedPclassNameSexAgeSibSpParchTicketFareCabinEmbarked
0103Braund, Mr. Owen Harrismale22.010A/5 211717.2500NaNS
1211Cumings, Mrs. John Bradley (Florence Briggs Th...female38.010PC 1759971.2833C85C
2313Heikkinen, Miss. Lainafemale26.000STON/O2. 31012827.9250NaNS
3411Futrelle, Mrs. Jacques Heath (Lily May Peel)female35.01011380353.1000C123S
4503Allen, Mr. William Henrymale35.0003734508.0500NaNS
\n", 248 | "
\n", 249 | "
\n", 250 | "\n", 251 | "
\n", 252 | " \n", 260 | "\n", 261 | " \n", 301 | "\n", 302 | " \n", 326 | "
\n", 327 | "\n", 328 | "\n", 329 | "
\n", 330 | " \n", 341 | "\n", 342 | "\n", 431 | "\n", 432 | " \n", 454 | "
\n", 455 | "
\n", 456 | "
\n" 457 | ] 458 | }, 459 | "metadata": {}, 460 | "execution_count": 4 461 | } 462 | ] 463 | }, 464 | { 465 | "cell_type": "code", 466 | "source": [ 467 | "dict1 = {\"name\":[\"priya\", \"nikhil\", \"sanjay\", \"ravindra\"],\n", 468 | " \"age\": [29, 25, 23, 32],\n", 469 | " \"city\": [\"delhi\", \"bengaluru\", \"rohtak\", \"delhi\"]}" 470 | ], 471 | "metadata": { 472 | "id": "YYusJJndKrfZ" 473 | }, 474 | "execution_count": 5, 475 | "outputs": [] 476 | }, 477 | { 478 | "cell_type": "code", 479 | "source": [ 480 | "dict1" 481 | ], 482 | "metadata": { 483 | "colab": { 484 | "base_uri": "https://localhost:8080/" 485 | }, 486 | "id": "wKmenjv3LZcb", 487 | "outputId": "45457179-58cd-485c-cfb0-b2626d569cf3" 488 | }, 489 | "execution_count": 6, 490 | "outputs": [ 491 | { 492 | "output_type": "execute_result", 493 | "data": { 494 | "text/plain": [ 495 | "{'name': ['priya', 'nikhil', 'sanjay', 'ravindra'],\n", 496 | " 'age': [29, 25, 23, 32],\n", 497 | " 'city': ['delhi', 'bengaluru', 'rohtak', 'delhi']}" 498 | ] 499 | }, 500 | "metadata": {}, 501 | "execution_count": 6 502 | } 503 | ] 504 | }, 505 | { 506 | "cell_type": "code", 507 | "source": [ 508 | "dataframe = pd.DataFrame(dict1)" 509 | ], 510 | "metadata": { 511 | "id": "FOlvN-n8LS0J" 512 | }, 513 | "execution_count": 7, 514 | "outputs": [] 515 | }, 516 | { 517 | "cell_type": "code", 518 | "source": [ 519 | "dataframe" 520 | ], 521 | "metadata": { 522 | "colab": { 523 | "base_uri": "https://localhost:8080/", 524 | "height": 174 525 | }, 526 | "id": "C3vCD4FGLcpZ", 527 | "outputId": "dd055229-5497-4388-d4be-bcf1d5e57779" 528 | }, 529 | "execution_count": 8, 530 | "outputs": [ 531 | { 532 | "output_type": "execute_result", 533 | "data": { 534 | "text/plain": [ 535 | " name age city\n", 536 | "0 priya 29 delhi\n", 537 | "1 nikhil 25 bengaluru\n", 538 | "2 sanjay 23 rohtak\n", 539 | "3 ravindra 32 delhi" 540 | ], 541 | "text/html": [ 542 | "\n", 543 | "
\n", 544 | "
\n", 545 | "\n", 558 | "\n", 559 | " \n", 560 | " \n", 561 | " \n", 562 | " \n", 563 | " \n", 564 | " \n", 565 | " \n", 566 | " \n", 567 | " \n", 568 | " \n", 569 | " \n", 570 | " \n", 571 | " \n", 572 | " \n", 573 | " \n", 574 | " \n", 575 | " \n", 576 | " \n", 577 | " \n", 578 | " \n", 579 | " \n", 580 | " \n", 581 | " \n", 582 | " \n", 583 | " \n", 584 | " \n", 585 | " \n", 586 | " \n", 587 | " \n", 588 | " \n", 589 | " \n", 590 | " \n", 591 | " \n", 592 | " \n", 593 | "
nameagecity
0priya29delhi
1nikhil25bengaluru
2sanjay23rohtak
3ravindra32delhi
\n", 594 | "
\n", 595 | "
\n", 596 | "\n", 597 | "
\n", 598 | " \n", 606 | "\n", 607 | " \n", 647 | "\n", 648 | " \n", 672 | "
\n", 673 | "\n", 674 | "\n", 675 | "
\n", 676 | " \n", 687 | "\n", 688 | "\n", 777 | "\n", 778 | " \n", 800 | "
\n", 801 | "
\n", 802 | "
\n" 803 | ] 804 | }, 805 | "metadata": {}, 806 | "execution_count": 8 807 | } 808 | ] 809 | }, 810 | { 811 | "cell_type": "code", 812 | "source": [ 813 | "data.shape" 814 | ], 815 | "metadata": { 816 | "colab": { 817 | "base_uri": "https://localhost:8080/" 818 | }, 819 | "id": "BT9yA0RGLddh", 820 | "outputId": "1afc8067-28ea-4e97-a602-bb81622789ce" 821 | }, 822 | "execution_count": 9, 823 | "outputs": [ 824 | { 825 | "output_type": "execute_result", 826 | "data": { 827 | "text/plain": [ 828 | "(891, 12)" 829 | ] 830 | }, 831 | "metadata": {}, 832 | "execution_count": 9 833 | } 834 | ] 835 | }, 836 | { 837 | "cell_type": "markdown", 838 | "source": [ 839 | "How many null values are available in a given dataset" 840 | ], 841 | "metadata": { 842 | "id": "ZP0Tdz4nMCi2" 843 | } 844 | }, 845 | { 846 | "cell_type": "code", 847 | "source": [ 848 | "data.isnull().sum()" 849 | ], 850 | "metadata": { 851 | "colab": { 852 | "base_uri": "https://localhost:8080/" 853 | }, 854 | "id": "B4u6cSxxLxYi", 855 | "outputId": "ab4945ad-57c9-44a4-fa50-6c9776dd7bb0" 856 | }, 857 | "execution_count": 10, 858 | "outputs": [ 859 | { 860 | "output_type": "execute_result", 861 | "data": { 862 | "text/plain": [ 863 | "PassengerId 0\n", 864 | "Survived 0\n", 865 | "Pclass 0\n", 866 | "Name 0\n", 867 | "Sex 0\n", 868 | "Age 177\n", 869 | "SibSp 0\n", 870 | "Parch 0\n", 871 | "Ticket 0\n", 872 | "Fare 0\n", 873 | "Cabin 687\n", 874 | "Embarked 2\n", 875 | "dtype: int64" 876 | ] 877 | }, 878 | "metadata": {}, 879 | "execution_count": 10 880 | } 881 | ] 882 | }, 883 | { 884 | "cell_type": "code", 885 | "source": [ 886 | "data.columns" 887 | ], 888 | "metadata": { 889 | "colab": { 890 | "base_uri": "https://localhost:8080/" 891 | }, 892 | "id": "u9FabiilMNEL", 893 | "outputId": "7edd9735-ff02-433e-91a9-2d6301136116" 894 | }, 895 | "execution_count": 11, 896 | "outputs": [ 897 | { 898 | "output_type": "execute_result", 899 | "data": { 900 | "text/plain": [ 901 | "Index(['PassengerId', 'Survived', 'Pclass', 'Name', 'Sex', 'Age', 'SibSp',\n", 902 | " 'Parch', 'Ticket', 'Fare', 'Cabin', 'Embarked'],\n", 903 | " dtype='object')" 904 | ] 905 | }, 906 | "metadata": {}, 907 | "execution_count": 11 908 | } 909 | ] 910 | }, 911 | { 912 | "cell_type": "code", 913 | "source": [ 914 | "data.dtypes" 915 | ], 916 | "metadata": { 917 | "colab": { 918 | "base_uri": "https://localhost:8080/" 919 | }, 920 | "id": "E6PcFN4QMUJy", 921 | "outputId": "dd9e4914-353e-4236-f9bb-35fb67f9bbf2" 922 | }, 923 | "execution_count": 12, 924 | "outputs": [ 925 | { 926 | "output_type": "execute_result", 927 | "data": { 928 | "text/plain": [ 929 | "PassengerId int64\n", 930 | "Survived int64\n", 931 | "Pclass int64\n", 932 | "Name object\n", 933 | "Sex object\n", 934 | "Age float64\n", 935 | "SibSp int64\n", 936 | "Parch int64\n", 937 | "Ticket object\n", 938 | "Fare float64\n", 939 | "Cabin object\n", 940 | "Embarked object\n", 941 | "dtype: object" 942 | ] 943 | }, 944 | "metadata": {}, 945 | "execution_count": 12 946 | } 947 | ] 948 | }, 949 | { 950 | "cell_type": "code", 951 | "source": [ 952 | "data.info()" 953 | ], 954 | "metadata": { 955 | "colab": { 956 | "base_uri": "https://localhost:8080/" 957 | }, 958 | "id": "Ur7GLxf0MZB5", 959 | "outputId": "2caa2ff9-6a9f-43b6-e901-83081bd62690" 960 | }, 961 | "execution_count": 13, 962 | "outputs": [ 963 | { 964 | "output_type": "stream", 965 | "name": "stdout", 966 | "text": [ 967 | "\n", 968 | "RangeIndex: 891 entries, 0 to 890\n", 969 | "Data columns (total 12 columns):\n", 970 | " # Column Non-Null Count Dtype \n", 971 | "--- ------ -------------- ----- \n", 972 | " 0 PassengerId 891 non-null int64 \n", 973 | " 1 Survived 891 non-null int64 \n", 974 | " 2 Pclass 891 non-null int64 \n", 975 | " 3 Name 891 non-null object \n", 976 | " 4 Sex 891 non-null object \n", 977 | " 5 Age 714 non-null float64\n", 978 | " 6 SibSp 891 non-null int64 \n", 979 | " 7 Parch 891 non-null int64 \n", 980 | " 8 Ticket 891 non-null object \n", 981 | " 9 Fare 891 non-null float64\n", 982 | " 10 Cabin 204 non-null object \n", 983 | " 11 Embarked 889 non-null object \n", 984 | "dtypes: float64(2), int64(5), object(5)\n", 985 | "memory usage: 83.7+ KB\n" 986 | ] 987 | } 988 | ] 989 | }, 990 | { 991 | "cell_type": "code", 992 | "source": [ 993 | "## column name - access the dataset\n", 994 | "type(data[['Age','Fare','Cabin']])" 995 | ], 996 | "metadata": { 997 | "colab": { 998 | "base_uri": "https://localhost:8080/" 999 | }, 1000 | "id": "KBL9WpM1MhIa", 1001 | "outputId": "39a8272b-2b9b-49b1-cf27-c127a98dd771" 1002 | }, 1003 | "execution_count": 18, 1004 | "outputs": [ 1005 | { 1006 | "output_type": "execute_result", 1007 | "data": { 1008 | "text/plain": [ 1009 | "pandas.core.frame.DataFrame" 1010 | ] 1011 | }, 1012 | "metadata": {}, 1013 | "execution_count": 18 1014 | } 1015 | ] 1016 | }, 1017 | { 1018 | "cell_type": "markdown", 1019 | "source": [ 1020 | "Series" 1021 | ], 1022 | "metadata": { 1023 | "id": "DQvbBiJ3OnWh" 1024 | } 1025 | }, 1026 | { 1027 | "cell_type": "code", 1028 | "source": [ 1029 | "type(data['Age'])" 1030 | ], 1031 | "metadata": { 1032 | "colab": { 1033 | "base_uri": "https://localhost:8080/" 1034 | }, 1035 | "id": "nnUKbJ1vM2Q5", 1036 | "outputId": "f5baee26-d551-41fe-9f27-12602be0b179" 1037 | }, 1038 | "execution_count": 17, 1039 | "outputs": [ 1040 | { 1041 | "output_type": "execute_result", 1042 | "data": { 1043 | "text/plain": [ 1044 | "pandas.core.series.Series" 1045 | ] 1046 | }, 1047 | "metadata": {}, 1048 | "execution_count": 17 1049 | } 1050 | ] 1051 | }, 1052 | { 1053 | "cell_type": "markdown", 1054 | "source": [ 1055 | "Descriptive Statistics of a given dataset" 1056 | ], 1057 | "metadata": { 1058 | "id": "b6hUajDyPAqF" 1059 | } 1060 | }, 1061 | { 1062 | "cell_type": "code", 1063 | "source": [ 1064 | "data.describe()" 1065 | ], 1066 | "metadata": { 1067 | "colab": { 1068 | "base_uri": "https://localhost:8080/", 1069 | "height": 300 1070 | }, 1071 | "id": "6qMmolgjNHqC", 1072 | "outputId": "f4983ce0-9030-43d6-96ac-519fdfede3d6" 1073 | }, 1074 | "execution_count": 19, 1075 | "outputs": [ 1076 | { 1077 | "output_type": "execute_result", 1078 | "data": { 1079 | "text/plain": [ 1080 | " PassengerId Survived Pclass Age SibSp \\\n", 1081 | "count 891.000000 891.000000 891.000000 714.000000 891.000000 \n", 1082 | "mean 446.000000 0.383838 2.308642 29.699118 0.523008 \n", 1083 | "std 257.353842 0.486592 0.836071 14.526497 1.102743 \n", 1084 | "min 1.000000 0.000000 1.000000 0.420000 0.000000 \n", 1085 | "25% 223.500000 0.000000 2.000000 20.125000 0.000000 \n", 1086 | "50% 446.000000 0.000000 3.000000 28.000000 0.000000 \n", 1087 | "75% 668.500000 1.000000 3.000000 38.000000 1.000000 \n", 1088 | "max 891.000000 1.000000 3.000000 80.000000 8.000000 \n", 1089 | "\n", 1090 | " Parch Fare \n", 1091 | "count 891.000000 891.000000 \n", 1092 | "mean 0.381594 32.204208 \n", 1093 | "std 0.806057 49.693429 \n", 1094 | "min 0.000000 0.000000 \n", 1095 | "25% 0.000000 7.910400 \n", 1096 | "50% 0.000000 14.454200 \n", 1097 | "75% 0.000000 31.000000 \n", 1098 | "max 6.000000 512.329200 " 1099 | ], 1100 | "text/html": [ 1101 | "\n", 1102 | "
\n", 1103 | "
\n", 1104 | "\n", 1117 | "\n", 1118 | " \n", 1119 | " \n", 1120 | " \n", 1121 | " \n", 1122 | " \n", 1123 | " \n", 1124 | " \n", 1125 | " \n", 1126 | " \n", 1127 | " \n", 1128 | " \n", 1129 | " \n", 1130 | " \n", 1131 | " \n", 1132 | " \n", 1133 | " \n", 1134 | " \n", 1135 | " \n", 1136 | " \n", 1137 | " \n", 1138 | " \n", 1139 | " \n", 1140 | " \n", 1141 | " \n", 1142 | " \n", 1143 | " \n", 1144 | " \n", 1145 | " \n", 1146 | " \n", 1147 | " \n", 1148 | " \n", 1149 | " \n", 1150 | " \n", 1151 | " \n", 1152 | " \n", 1153 | " \n", 1154 | " \n", 1155 | " \n", 1156 | " \n", 1157 | " \n", 1158 | " \n", 1159 | " \n", 1160 | " \n", 1161 | " \n", 1162 | " \n", 1163 | " \n", 1164 | " \n", 1165 | " \n", 1166 | " \n", 1167 | " \n", 1168 | " \n", 1169 | " \n", 1170 | " \n", 1171 | " \n", 1172 | " \n", 1173 | " \n", 1174 | " \n", 1175 | " \n", 1176 | " \n", 1177 | " \n", 1178 | " \n", 1179 | " \n", 1180 | " \n", 1181 | " \n", 1182 | " \n", 1183 | " \n", 1184 | " \n", 1185 | " \n", 1186 | " \n", 1187 | " \n", 1188 | " \n", 1189 | " \n", 1190 | " \n", 1191 | " \n", 1192 | " \n", 1193 | " \n", 1194 | " \n", 1195 | " \n", 1196 | " \n", 1197 | " \n", 1198 | " \n", 1199 | " \n", 1200 | " \n", 1201 | " \n", 1202 | " \n", 1203 | " \n", 1204 | " \n", 1205 | " \n", 1206 | " \n", 1207 | " \n", 1208 | " \n", 1209 | " \n", 1210 | " \n", 1211 | " \n", 1212 | "
PassengerIdSurvivedPclassAgeSibSpParchFare
count891.000000891.000000891.000000714.000000891.000000891.000000891.000000
mean446.0000000.3838382.30864229.6991180.5230080.38159432.204208
std257.3538420.4865920.83607114.5264971.1027430.80605749.693429
min1.0000000.0000001.0000000.4200000.0000000.0000000.000000
25%223.5000000.0000002.00000020.1250000.0000000.0000007.910400
50%446.0000000.0000003.00000028.0000000.0000000.00000014.454200
75%668.5000001.0000003.00000038.0000001.0000000.00000031.000000
max891.0000001.0000003.00000080.0000008.0000006.000000512.329200
\n", 1213 | "
\n", 1214 | "
\n", 1215 | "\n", 1216 | "
\n", 1217 | " \n", 1225 | "\n", 1226 | " \n", 1266 | "\n", 1267 | " \n", 1291 | "
\n", 1292 | "\n", 1293 | "\n", 1294 | "
\n", 1295 | " \n", 1306 | "\n", 1307 | "\n", 1396 | "\n", 1397 | " \n", 1419 | "
\n", 1420 | "
\n", 1421 | "
\n" 1422 | ] 1423 | }, 1424 | "metadata": {}, 1425 | "execution_count": 19 1426 | } 1427 | ] 1428 | }, 1429 | { 1430 | "cell_type": "markdown", 1431 | "source": [ 1432 | "Difference between loc and iloc" 1433 | ], 1434 | "metadata": { 1435 | "id": "gC36h6frQ41a" 1436 | } 1437 | }, 1438 | { 1439 | "cell_type": "code", 1440 | "source": [ 1441 | "## row indexing - loc\n", 1442 | "data.loc[[0,5]]\n" 1443 | ], 1444 | "metadata": { 1445 | "colab": { 1446 | "base_uri": "https://localhost:8080/", 1447 | "height": 129 1448 | }, 1449 | "id": "EaolNsAQO_qC", 1450 | "outputId": "76af4685-aea3-4558-f835-d1b23cdd1c7a" 1451 | }, 1452 | "execution_count": 21, 1453 | "outputs": [ 1454 | { 1455 | "output_type": "execute_result", 1456 | "data": { 1457 | "text/plain": [ 1458 | " PassengerId Survived Pclass Name Sex Age SibSp \\\n", 1459 | "0 1 0 3 Braund, Mr. Owen Harris male 22.0 1 \n", 1460 | "5 6 0 3 Moran, Mr. James male NaN 0 \n", 1461 | "\n", 1462 | " Parch Ticket Fare Cabin Embarked \n", 1463 | "0 0 A/5 21171 7.2500 NaN S \n", 1464 | "5 0 330877 8.4583 NaN Q " 1465 | ], 1466 | "text/html": [ 1467 | "\n", 1468 | "
\n", 1469 | "
\n", 1470 | "\n", 1483 | "\n", 1484 | " \n", 1485 | " \n", 1486 | " \n", 1487 | " \n", 1488 | " \n", 1489 | " \n", 1490 | " \n", 1491 | " \n", 1492 | " \n", 1493 | " \n", 1494 | " \n", 1495 | " \n", 1496 | " \n", 1497 | " \n", 1498 | " \n", 1499 | " \n", 1500 | " \n", 1501 | " \n", 1502 | " \n", 1503 | " \n", 1504 | " \n", 1505 | " \n", 1506 | " \n", 1507 | " \n", 1508 | " \n", 1509 | " \n", 1510 | " \n", 1511 | " \n", 1512 | " \n", 1513 | " \n", 1514 | " \n", 1515 | " \n", 1516 | " \n", 1517 | " \n", 1518 | " \n", 1519 | " \n", 1520 | " \n", 1521 | " \n", 1522 | " \n", 1523 | " \n", 1524 | " \n", 1525 | " \n", 1526 | " \n", 1527 | " \n", 1528 | " \n", 1529 | " \n", 1530 | " \n", 1531 | " \n", 1532 | " \n", 1533 | "
PassengerIdSurvivedPclassNameSexAgeSibSpParchTicketFareCabinEmbarked
0103Braund, Mr. Owen Harrismale22.010A/5 211717.2500NaNS
5603Moran, Mr. JamesmaleNaN003308778.4583NaNQ
\n", 1534 | "
\n", 1535 | "
\n", 1536 | "\n", 1537 | "
\n", 1538 | " \n", 1546 | "\n", 1547 | " \n", 1587 | "\n", 1588 | " \n", 1612 | "
\n", 1613 | "\n", 1614 | "\n", 1615 | "
\n", 1616 | " \n", 1627 | "\n", 1628 | "\n", 1717 | "\n", 1718 | " \n", 1740 | "
\n", 1741 | "
\n", 1742 | "
\n" 1743 | ] 1744 | }, 1745 | "metadata": {}, 1746 | "execution_count": 21 1747 | } 1748 | ] 1749 | }, 1750 | { 1751 | "cell_type": "code", 1752 | "source": [ 1753 | "## specific row and specific column\n", 1754 | "data.iloc[2:4, 0:2]" 1755 | ], 1756 | "metadata": { 1757 | "colab": { 1758 | "base_uri": "https://localhost:8080/", 1759 | "height": 112 1760 | }, 1761 | "id": "87cNBkvNQRyi", 1762 | "outputId": "c6281e01-fee3-4b59-8b08-7152a1ec6437" 1763 | }, 1764 | "execution_count": 22, 1765 | "outputs": [ 1766 | { 1767 | "output_type": "execute_result", 1768 | "data": { 1769 | "text/plain": [ 1770 | " PassengerId Survived\n", 1771 | "2 3 1\n", 1772 | "3 4 1" 1773 | ], 1774 | "text/html": [ 1775 | "\n", 1776 | "
\n", 1777 | "
\n", 1778 | "\n", 1791 | "\n", 1792 | " \n", 1793 | " \n", 1794 | " \n", 1795 | " \n", 1796 | " \n", 1797 | " \n", 1798 | " \n", 1799 | " \n", 1800 | " \n", 1801 | " \n", 1802 | " \n", 1803 | " \n", 1804 | " \n", 1805 | " \n", 1806 | " \n", 1807 | " \n", 1808 | " \n", 1809 | " \n", 1810 | " \n", 1811 | "
PassengerIdSurvived
231
341
\n", 1812 | "
\n", 1813 | "
\n", 1814 | "\n", 1815 | "
\n", 1816 | " \n", 1824 | "\n", 1825 | " \n", 1865 | "\n", 1866 | " \n", 1890 | "
\n", 1891 | "\n", 1892 | "\n", 1893 | "
\n", 1894 | " \n", 1905 | "\n", 1906 | "\n", 1995 | "\n", 1996 | " \n", 2018 | "
\n", 2019 | "
\n", 2020 | "
\n" 2021 | ] 2022 | }, 2023 | "metadata": {}, 2024 | "execution_count": 22 2025 | } 2026 | ] 2027 | }, 2028 | { 2029 | "cell_type": "code", 2030 | "source": [ 2031 | "data.columns" 2032 | ], 2033 | "metadata": { 2034 | "colab": { 2035 | "base_uri": "https://localhost:8080/" 2036 | }, 2037 | "id": "LwLL3XKoQpIj", 2038 | "outputId": "0740bd98-6edc-437f-d67c-1779f645810d" 2039 | }, 2040 | "execution_count": 23, 2041 | "outputs": [ 2042 | { 2043 | "output_type": "execute_result", 2044 | "data": { 2045 | "text/plain": [ 2046 | "Index(['PassengerId', 'Survived', 'Pclass', 'Name', 'Sex', 'Age', 'SibSp',\n", 2047 | " 'Parch', 'Ticket', 'Fare', 'Cabin', 'Embarked'],\n", 2048 | " dtype='object')" 2049 | ] 2050 | }, 2051 | "metadata": {}, 2052 | "execution_count": 23 2053 | } 2054 | ] 2055 | }, 2056 | { 2057 | "cell_type": "code", 2058 | "source": [], 2059 | "metadata": { 2060 | "id": "sMAfqCCaQvnz" 2061 | }, 2062 | "execution_count": null, 2063 | "outputs": [] 2064 | } 2065 | ] 2066 | } --------------------------------------------------------------------------------