From 6d6e7b684ce1dec1748f613ba87f55da234b25d8 Mon Sep 17 00:00:00 2001 From: Diya Nag Chaudhury <43166705+dnc2k@users.noreply.github.com> Date: Thu, 27 Sep 2018 22:04:05 +0530 Subject: [PATCH 1/8] Lists Assignment Solved --- Copy_of_dnc2k.ipynb | 93 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 Copy_of_dnc2k.ipynb diff --git a/Copy_of_dnc2k.ipynb b/Copy_of_dnc2k.ipynb new file mode 100644 index 0000000..c048631 --- /dev/null +++ b/Copy_of_dnc2k.ipynb @@ -0,0 +1,93 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "Copy of dnc2k.ipynb", + "version": "0.3.2", + "provenance": [], + "include_colab_link": true + }, + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "[View in Colaboratory](https://colab.research.google.com/github/dnc2k/Assignment-2/blob/dnc2k/Copy_of_dnc2k.ipynb)" + ] + }, + { + "metadata": { + "id": "lqNVh-T-sXGj", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 201 + }, + "outputId": "2830c962-2b72-4da3-8646-cad7e83ab7b8" + }, + "cell_type": "code", + "source": [ + "dummy_list=[23,82,98,62,16]\n", + "\n", + "print (dummy_list)\n", + "\n", + "dummy_list.reverse()\n", + "print (dummy_list)\n", + "\n", + "dummy_list_2 = [2, 200, 16, 4, 1, 0, 9.45, 45.67, 90, 12.01, 12.02]\n", + "for item in dummy_list_2:\n", + " dummy_list.append(item)\n", + "print (dummy_list)\n", + "\n", + "dummy_dict={16:2, 62:1, 98:1, 82:1, 23:1, 2:1, 200:1, 4:1, 1:1, 0:1, 9.45:1, 45.67:1, 90:1, 12.01:1, 12.02:1}\n", + "\n", + "print (dummy_dict)\n", + "\n", + "dummy_list.sort()\n", + "print (dummy_list)\n", + "dummy_list.sort(reverse=True)\n", + "print (dummy_list)\n", + "\n", + "x = 16\n", + "dummy_list.remove(x)\n", + "print (dummy_list)\n", + "\n", + "x=int(input())\n", + "del dummy_list[x]\n", + "print (dummy_list)\n", + "\n", + "dummy_list.clear()\n", + "print (dummy_list)" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[23, 82, 98, 62, 16]\n", + "[16, 62, 98, 82, 23]\n", + "[16, 62, 98, 82, 23, 2, 200, 16, 4, 1, 0, 9.45, 45.67, 90, 12.01, 12.02]\n", + "{16: 2, 62: 1, 98: 1, 82: 1, 23: 1, 2: 1, 200: 1, 4: 1, 1: 1, 0: 1, 9.45: 1, 45.67: 1, 90: 1, 12.01: 1, 12.02: 1}\n", + "[0, 1, 2, 4, 9.45, 12.01, 12.02, 16, 16, 23, 45.67, 62, 82, 90, 98, 200]\n", + "[200, 98, 90, 82, 62, 45.67, 23, 16, 16, 12.02, 12.01, 9.45, 4, 2, 1, 0]\n", + "[200, 98, 90, 82, 62, 45.67, 23, 16, 12.02, 12.01, 9.45, 4, 2, 1, 0]\n", + "3\n", + "[200, 98, 90, 62, 45.67, 23, 16, 12.02, 12.01, 9.45, 4, 2, 1, 0]\n", + "[]\n" + ], + "name": "stdout" + } + ] + } + ] +} \ No newline at end of file From 5117d980a081bd5e032957df60cbbb0193f6b0c1 Mon Sep 17 00:00:00 2001 From: Diya Nag Chaudhury <43166705+dnc2k@users.noreply.github.com> Date: Thu, 27 Sep 2018 22:13:04 +0530 Subject: [PATCH 2/8] Lists Assignment solved --- dnc2k.ipynb | 121 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 91 insertions(+), 30 deletions(-) diff --git a/dnc2k.ipynb b/dnc2k.ipynb index 9e2543a..078df9a 100644 --- a/dnc2k.ipynb +++ b/dnc2k.ipynb @@ -1,32 +1,93 @@ { - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "dnc2k.ipynb", + "version": "0.3.2", + "provenance": [], + "include_colab_link": true + }, + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + } }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.5.2" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "[View in Colaboratory](https://colab.research.google.com/github/dnc2k/Assignment-2/blob/dnc2k/dnc2k.ipynb)" + ] + }, + { + "metadata": { + "id": "VSHhNc1q4AJF", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 201 + }, + "outputId": "eff259d6-8576-4bf5-ad11-6d59c2eb9bac" + }, + "cell_type": "code", + "source": [ + "dummy_list=[23,82,98,62,16]\n", + "\n", + "print (dummy_list)\n", + "\n", + "dummy_list.reverse()\n", + "print (dummy_list)\n", + "\n", + "dummy_list_2 = [2, 200, 16, 4, 1, 0, 9.45, 45.67, 90, 12.01, 12.02]\n", + "for item in dummy_list_2:\n", + " dummy_list.append(item)\n", + "print (dummy_list)\n", + "\n", + "dummy_dict={16:2, 62:1, 98:1, 82:1, 23:1, 2:1, 200:1, 4:1, 1:1, 0:1, 9.45:1, 45.67:1, 90:1, 12.01:1, 12.02:1}\n", + "\n", + "print (dummy_dict)\n", + "\n", + "dummy_list.sort()\n", + "print (dummy_list)\n", + "dummy_list.sort(reverse=True)\n", + "print (dummy_list)\n", + "\n", + "x = 16\n", + "dummy_list.remove(x)\n", + "print (dummy_list)\n", + "\n", + "x=int(input())\n", + "del dummy_list[x]\n", + "print (dummy_list)\n", + "\n", + "dummy_list.clear()\n", + "print (dummy_list)" + ], + "execution_count": 1, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[23, 82, 98, 62, 16]\n", + "[16, 62, 98, 82, 23]\n", + "[16, 62, 98, 82, 23, 2, 200, 16, 4, 1, 0, 9.45, 45.67, 90, 12.01, 12.02]\n", + "{16: 2, 62: 1, 98: 1, 82: 1, 23: 1, 2: 1, 200: 1, 4: 1, 1: 1, 0: 1, 9.45: 1, 45.67: 1, 90: 1, 12.01: 1, 12.02: 1}\n", + "[0, 1, 2, 4, 9.45, 12.01, 12.02, 16, 16, 23, 45.67, 62, 82, 90, 98, 200]\n", + "[200, 98, 90, 82, 62, 45.67, 23, 16, 16, 12.02, 12.01, 9.45, 4, 2, 1, 0]\n", + "[200, 98, 90, 82, 62, 45.67, 23, 16, 12.02, 12.01, 9.45, 4, 2, 1, 0]\n", + "2\n", + "[200, 98, 82, 62, 45.67, 23, 16, 12.02, 12.01, 9.45, 4, 2, 1, 0]\n", + "[]\n" + ], + "name": "stdout" + } + ] + } + ] +} \ No newline at end of file From b640138520dcca712f573b7c5265f705579a2c33 Mon Sep 17 00:00:00 2001 From: Diya Nag Chaudhury <43166705+dnc2k@users.noreply.github.com> Date: Thu, 27 Sep 2018 22:51:56 +0530 Subject: [PATCH 3/8] Numpy Exercise solved --- Copy_of_Numpy_Exercises.ipynb | 371 ++++++++++++++++++++++++++++++++++ 1 file changed, 371 insertions(+) create mode 100644 Copy_of_Numpy_Exercises.ipynb diff --git a/Copy_of_Numpy_Exercises.ipynb b/Copy_of_Numpy_Exercises.ipynb new file mode 100644 index 0000000..d5ac3ec --- /dev/null +++ b/Copy_of_Numpy_Exercises.ipynb @@ -0,0 +1,371 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "Copy of Numpy_Exercises.ipynb", + "version": "0.3.2", + "provenance": [], + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "[View in Colaboratory](https://colab.research.google.com/github/dnc2k/Assignment-2/blob/dnc2k/Copy_of_Numpy_Exercises.ipynb)" + ] + }, + { + "metadata": { + "id": "a_4UupTr9fbX", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "# Numpy Exercises\n", + "\n", + "1) Create a uniform subdivision of the interval -1.3 to 2.5 with 64 subdivisions" + ] + }, + { + "metadata": { + "id": "LIP5u4zi0Nmg", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 311 + }, + "outputId": "23b1a117-1e5b-4256-d322-3b95cec3d1c5" + }, + "cell_type": "code", + "source": [ + "import numpy as np #import numpy\n", + "a=np.linspace(-1.3,2.5,64).reshape(8,8)\n", + "print (a)" + ], + "execution_count": 2, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[[-1.3 -1.23968254 -1.17936508 -1.11904762 -1.05873016 -0.9984127\n", + " -0.93809524 -0.87777778]\n", + " [-0.81746032 -0.75714286 -0.6968254 -0.63650794 -0.57619048 -0.51587302\n", + " -0.45555556 -0.3952381 ]\n", + " [-0.33492063 -0.27460317 -0.21428571 -0.15396825 -0.09365079 -0.03333333\n", + " 0.02698413 0.08730159]\n", + " [ 0.14761905 0.20793651 0.26825397 0.32857143 0.38888889 0.44920635\n", + " 0.50952381 0.56984127]\n", + " [ 0.63015873 0.69047619 0.75079365 0.81111111 0.87142857 0.93174603\n", + " 0.99206349 1.05238095]\n", + " [ 1.11269841 1.17301587 1.23333333 1.29365079 1.35396825 1.41428571\n", + " 1.47460317 1.53492063]\n", + " [ 1.5952381 1.65555556 1.71587302 1.77619048 1.83650794 1.8968254\n", + " 1.95714286 2.01746032]\n", + " [ 2.07777778 2.13809524 2.1984127 2.25873016 2.31904762 2.37936508\n", + " 2.43968254 2.5 ]]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "dBoH_A7M9jjL", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "2) Generate an array of length 3n filled with the cyclic pattern 1, 2, 3" + ] + }, + { + "metadata": { + "id": "4TxT66309n1o", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "outputId": "13ce8763-8b0e-4de1-ad88-7f870e808022" + }, + "cell_type": "code", + "source": [ + "a1=np.array([1,2,3])\n", + "a2=np.resize(a1,3)\n", + "print (a2)" + ], + "execution_count": 11, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[1 2 3]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "Vh-UKizx9oTp", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "3) Create an array of the first 10 odd integers." + ] + }, + { + "metadata": { + "id": "ebhEUZq29r32", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "outputId": "0efbd9b4-7bc8-4978-e6f6-0fe847326a45" + }, + "cell_type": "code", + "source": [ + "a2=np.arange(1,20,2)\n", + "print (a2)" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[ 1 3 5 7 9 11 13 15 17 19]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "QfJRdMat90f4", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "4) Find intersection of a and b" + ] + }, + { + "metadata": { + "id": "gOlfuJCo-JwF", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "outputId": "766a60e1-d170-41e5-8526-8e13d55546a3" + }, + "cell_type": "code", + "source": [ + "#expected output array([2, 4])\n", + "a = np.array([1,2,3,2,3,4,3,4,5,6])\n", + "b = np.array([7,2,10,2,7,4,9,4,9,8])\n", + "I = np.intersect1d(a,b)\n", + "print ('I',I)\n" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "I [2 4]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "RtVCf0UoCeB8", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "5) Reshape 1d array a to 2d array of 2X5" + ] + }, + { + "metadata": { + "id": "2E8b55_2Cjx5", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 72 + }, + "outputId": "0321e16b-580e-4f68-e128-ef07b70086f1" + }, + "cell_type": "code", + "source": [ + "a = np.arange(10)\n", + "a1= a.reshape(2,5)\n", + "print ('After reshape \\n',a1)" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "After reshape \n", + " [[0 1 2 3 4]\n", + " [5 6 7 8 9]]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "dVrSBW1zEjp2", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "6) Create a numpy array to list and vice versa" + ] + }, + { + "metadata": { + "id": "tcBCyhXPEp9C", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 90 + }, + "outputId": "b11709dd-14c1-441f-ea05-42815cc546d8" + }, + "cell_type": "code", + "source": [ + "a = [1, 2, 3, 4, 5, 6, 7, 8, 9]\n", + "a1=np.array(a)\n", + "print (\"1-D array:\\n\" , a1)\n", + "l1=a1.tolist()\n", + "print (\"Array to List:\\n\", l1)" + ], + "execution_count": 15, + "outputs": [ + { + "output_type": "stream", + "text": [ + "1-D array:\n", + " [1 2 3 4 5 6 7 8 9]\n", + "Array to List:\n", + " [1, 2, 3, 4, 5, 6, 7, 8, 9]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "JNqX8wnz9sQJ", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "7) Create a 10 x 10 arrays of zeros and then \"frame\" it with a border of ones." + ] + }, + { + "metadata": { + "id": "4bjP3JAc9vRD", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 201 + }, + "outputId": "2618d44e-9f7a-423c-f4f4-ba5b2cc4b2b9" + }, + "cell_type": "code", + "source": [ + "a=np.zeros(shape=(10,10),dtype=int)\n", + "a[0,:]=1\n", + "a[:,0]=1\n", + "a[9,:]=1\n", + "a[:,9]=1\n", + "print (a)" + ], + "execution_count": 4, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[[1 1 1 1 1 1 1 1 1 1]\n", + " [1 0 0 0 0 0 0 0 0 1]\n", + " [1 0 0 0 0 0 0 0 0 1]\n", + " [1 0 0 0 0 0 0 0 0 1]\n", + " [1 0 0 0 0 0 0 0 0 1]\n", + " [1 0 0 0 0 0 0 0 0 1]\n", + " [1 0 0 0 0 0 0 0 0 1]\n", + " [1 0 0 0 0 0 0 0 0 1]\n", + " [1 0 0 0 0 0 0 0 0 1]\n", + " [1 1 1 1 1 1 1 1 1 1]]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "xaQgf8tT9v-n", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "8) Create an 8 x 8 array with a checkerboard pattern of zeros and ones using a slicing+striding approach." + ] + }, + { + "metadata": { + "id": "No7fx0Xy9zEh", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 182 + }, + "outputId": "0e8bcd3c-2881-467b-ffdb-6c57153a46c0" + }, + "cell_type": "code", + "source": [ + "import numpy as np\n", + "x=np.zeros(shape=(8,8),dtype=int)\n", + "x[1::2,::2]=1\n", + "x[::2,1::2]=1\n", + "print (\"Checkerboard Pattern:\\n\",x)" + ], + "execution_count": 3, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Checkerboard Pattern:\n", + " [[0 1 0 1 0 1 0 1]\n", + " [1 0 1 0 1 0 1 0]\n", + " [0 1 0 1 0 1 0 1]\n", + " [1 0 1 0 1 0 1 0]\n", + " [0 1 0 1 0 1 0 1]\n", + " [1 0 1 0 1 0 1 0]\n", + " [0 1 0 1 0 1 0 1]\n", + " [1 0 1 0 1 0 1 0]]\n" + ], + "name": "stdout" + } + ] + } + ] +} \ No newline at end of file From 07486f97e13ccfb9380f5e07281a0275cbd32171 Mon Sep 17 00:00:00 2001 From: Diya Nag Chaudhury <43166705+dnc2k@users.noreply.github.com> Date: Fri, 28 Sep 2018 18:54:16 +0530 Subject: [PATCH 4/8] Numpy Examples --- Numpy_Examples_1.ipynb | 526 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 526 insertions(+) create mode 100644 Numpy_Examples_1.ipynb diff --git a/Numpy_Examples_1.ipynb b/Numpy_Examples_1.ipynb new file mode 100644 index 0000000..2b10093 --- /dev/null +++ b/Numpy_Examples_1.ipynb @@ -0,0 +1,526 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "Numpy_Examples 1.ipynb", + "version": "0.3.2", + "provenance": [], + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "[View in Colaboratory](https://colab.research.google.com/github/dnc2k/Assignment-2/blob/dnc2k/Numpy_Examples_1.ipynb)" + ] + }, + { + "metadata": { + "id": "3pSVAeWfuPcq", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "# Numpy Examples\n", + "\n", + "## What is numpy?\n", + "\n", + "#### Python has built-in:\n", + "\n", + "- containers: lists (costless insertion and append), dictionnaries (fast lookup)\n", + "- high-level number objects: integers, floating point\n", + "\n", + "#### Numpy is:\n", + "\n", + " - extension package to Python for multidimensional arrays\n", + " - closer to hardware (efficiency)\n", + " - designed for scientific computation (convenience)\n", + "\n", + "\n", + "#### Import numpy\n", + "\n" + ] + }, + { + "metadata": { + "id": "ozUi4_X55UHE", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "import numpy as np" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "3-1ghFDF5N2z", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "### Uncomment Print statement and run each cell to see the output\n", + "\n", + "#### Create numpy arrays\n" + ] + }, + { + "metadata": { + "id": "atYpk2ert0b-", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 90 + }, + "outputId": "4ff1f20c-14bb-4cb8-ceca-c7c1cd6a24c5" + }, + "cell_type": "code", + "source": [ + "a = np.array([1, 2, 3]) # Create a rank 1 array\n", + "print(a)\n", + "print(type(a)) #print type of a\n", + "\n", + "b = np.array([[1,2,3],[4,5,6]]) # Create a rank 2 array\n", + "print(b.shape) # Prints \"(2, 3)\"\n", + "print(b[0, 0], b[0, 1], b[1, 0])" + ], + "execution_count": 3, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[1 2 3]\n", + "\n", + "(2, 3)\n", + "1 2 4\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "Kro5ZOwXue5n", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "#### Some basic functions for creating arrays. Print all the defined arrays and see the results." + ] + }, + { + "metadata": { + "id": "V3rdzgr9uhHS", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 237 + }, + "outputId": "e25a51e1-4c70-4177-af60-164aa8901f45" + }, + "cell_type": "code", + "source": [ + "a = np.zeros(shape=(2,2))\n", + "b = np.ones(shape = (3,3))\n", + "c = np.eye(2)\n", + "d = np.full(shape=(3,3), fill_value=5)\n", + "e = np.random.random((2,2))\n", + "\n", + "print('a', a)\n", + "print('b',b)\n", + "print('c',c)\n", + "print('d',d)\n", + "print('e',e)" + ], + "execution_count": 4, + "outputs": [ + { + "output_type": "stream", + "text": [ + "a [[0. 0.]\n", + " [0. 0.]]\n", + "b [[1. 1. 1.]\n", + " [1. 1. 1.]\n", + " [1. 1. 1.]]\n", + "c [[1. 0.]\n", + " [0. 1.]]\n", + "d [[5 5 5]\n", + " [5 5 5]\n", + " [5 5 5]]\n", + "e [[0.16463418 0.51575979]\n", + " [0.87927607 0.06306851]]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "8RPW_SutukjF", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "#### Execute and understand :)" + ] + }, + { + "metadata": { + "id": "-8JuqYt4upeo", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 202 + }, + "outputId": "2aa5b0a6-66dd-4953-8bf2-4907078c05db" + }, + "cell_type": "code", + "source": [ + "a == np.arange(10)\n", + "b == np.linspace(0,10, num=6)\n", + "print(a)\n", + "print(b)" + ], + "execution_count": 5, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[[0. 0.]\n", + " [0. 0.]]\n", + "[[1. 1. 1.]\n", + " [1. 1. 1.]\n", + " [1. 1. 1.]]\n" + ], + "name": "stdout" + }, + { + "output_type": "stream", + "text": [ + "/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:1: DeprecationWarning: elementwise == comparison failed; this will raise an error in the future.\n", + " \"\"\"Entry point for launching an IPython kernel.\n", + "/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:2: DeprecationWarning: elementwise == comparison failed; this will raise an error in the future.\n", + " \n" + ], + "name": "stderr" + } + ] + }, + { + "metadata": { + "id": "MRHhbjx4uvYN", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "#### Array Indexing" + ] + }, + { + "metadata": { + "id": "grF5_yUSuxVK", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 90 + }, + "outputId": "00a0aace-b1a6-4652-cadb-4fa881762e71" + }, + "cell_type": "code", + "source": [ + "a = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]])\n", + "\n", + "# Use slicing to pull out the subarray consisting of the first 2 rows\n", + "# and columns 1 and 2; b is the following array of shape (2, 2):\n", + "# [[2 3]\n", + "# [6 7]]\n", + "b = a[:2, 1:3]\n", + "print (b)\n", + "# A slice of an array is a view into the same data, so modifying it\n", + "# will modify the original array.\n", + "\n", + "print(a[0, 1]) # Prints \"2\"\n", + "\n", + "b[0, 0] = 77 # b[0, 0] is the same piece of data as a[0, 1]\n", + "print(a[0, 1]) # Prints \"77\"" + ], + "execution_count": 8, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[[2 3]\n", + " [6 7]]\n", + "2\n", + "77\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "s400Gijxu0kO", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "#### Slicing" + ] + }, + { + "metadata": { + "id": "kubpegh2u4zF", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 127 + }, + "outputId": "79290990-bd7a-4cde-a777-34e3a6da9241" + }, + "cell_type": "code", + "source": [ + "a = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]])\n", + "\n", + "row_r1 = a[1, :] # Rank 1 view of the second row of a\n", + "row_r2 = a[1:2, :] # Rank 2 view of the second row of a\n", + "\n", + "print(row_r1, row_r1.shape) # Prints \"[5 6 7 8] (4,)\"\n", + "print(row_r2, row_r2.shape) # Prints \"[[5 6 7 8]] (1, 4)\"\n", + "\n", + "col_r1 = a[:, 1]\n", + "col_r2 = a[:, 1:2]\n", + "\n", + "print(col_r1, col_r1.shape) # Prints \"[ 2 6 10] (3,)\"\n", + "print(col_r2, col_r2.shape)" + ], + "execution_count": 10, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[5 6 7 8] (4,)\n", + "[[5 6 7 8]] (1, 4)\n", + "[ 2 6 10] (3,)\n", + "[[ 2]\n", + " [ 6]\n", + " [10]] (3, 1)\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "TmGnCO3AvE8t", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "#### Aritmetic operations" + ] + }, + { + "metadata": { + "id": "YvBw3ImjvGqD", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 72 + }, + "outputId": "85c537ca-e089-4714-a430-911232c66ef1" + }, + "cell_type": "code", + "source": [ + "x = np.array([[1,2],[3,4]])\n", + "\n", + "print(np.sum(x)) # Compute sum of all elements; prints \"10\"\n", + "print(np.sum(x, axis=0)) # Compute sum of each column; prints \"[4 6]\"\n", + "print(np.sum(x, axis=1)) # Compute sum of each row; prints \"[3 7]\"" + ], + "execution_count": 11, + "outputs": [ + { + "output_type": "stream", + "text": [ + "10\n", + "[4 6]\n", + "[3 7]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "uaVY3ZzD4pC2", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "#### Using Boolean Mask" + ] + }, + { + "metadata": { + "id": "-PNfOMvh4_Gp", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 72 + }, + "outputId": "da128d9b-2bd3-4832-f0e9-1fc395281fbe" + }, + "cell_type": "code", + "source": [ + "b = np.arange(10)\n", + "\n", + "print(b)\n", + "\n", + "mask = b%2!=0 #perform computations on the list \n", + "\n", + "print(mask)\n", + "\n", + "print(b[mask]) #applying the mask on the numpy array\n" + ], + "execution_count": 12, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[0 1 2 3 4 5 6 7 8 9]\n", + "[False True False True False True False True False True]\n", + "[1 3 5 7 9]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "HbEPBbz-5J9K", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "outputId": "bbf0f757-9b46-411d-a516-8ab550cb86bf" + }, + "cell_type": "code", + "source": [ + "modified_b = b\n", + "modified_b[mask] = -1\n", + "\n", + "print(modified_b)" + ], + "execution_count": 13, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[ 0 -1 2 -1 4 -1 6 -1 8 -1]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "zgSd71EEAHC7", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "#### Swapping two columns in a 2d numpy array" + ] + }, + { + "metadata": { + "id": "-cvqeXd_AGo1", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 127 + }, + "outputId": "bed3a174-f512-4eb6-a7de-00a6e7a53087" + }, + "cell_type": "code", + "source": [ + "a = np.arange(9).reshape(3,3)\n", + "print(a)\n", + "\n", + "print(a[:, [1,0,2]])" + ], + "execution_count": 14, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[[0 1 2]\n", + " [3 4 5]\n", + " [6 7 8]]\n", + "[[1 0 2]\n", + " [4 3 5]\n", + " [7 6 8]]\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "U7ifiLY3Ayky", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "#### Swapping two rows in a 2d numpy array" + ] + }, + { + "metadata": { + "id": "0FrOURRDAZNP", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 127 + }, + "outputId": "0407ee33-bb36-42ac-e542-e0076bc3847d" + }, + "cell_type": "code", + "source": [ + "a = np.arange(9).reshape(3,3)\n", + "print(a)\n", + "\n", + "print(a[[1,0,2], :])" + ], + "execution_count": 16, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[[0 1 2]\n", + " [3 4 5]\n", + " [6 7 8]]\n", + "[[3 4 5]\n", + " [0 1 2]\n", + " [6 7 8]]\n" + ], + "name": "stdout" + } + ] + } + ] +} \ No newline at end of file From 432ffe6a45773bff4b39a99dda2bff028cf11305 Mon Sep 17 00:00:00 2001 From: Diya Nag Chaudhury <43166705+dnc2k@users.noreply.github.com> Date: Fri, 28 Sep 2018 18:55:58 +0530 Subject: [PATCH 5/8] Numpy Examples --- Numpy_Examples_1.ipynb | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/Numpy_Examples_1.ipynb b/Numpy_Examples_1.ipynb index 2b10093..2827a4b 100644 --- a/Numpy_Examples_1.ipynb +++ b/Numpy_Examples_1.ipynb @@ -182,39 +182,26 @@ "colab_type": "code", "colab": { "base_uri": "https://localhost:8080/", - "height": 202 + "height": 54 }, - "outputId": "2aa5b0a6-66dd-4953-8bf2-4907078c05db" + "outputId": "c54a2f16-6ccb-41f7-825d-21b527156b3d" }, "cell_type": "code", "source": [ - "a == np.arange(10)\n", - "b == np.linspace(0,10, num=6)\n", + "a = np.arange(10)\n", + "b = np.linspace(0,10, num=6)\n", "print(a)\n", "print(b)" ], - "execution_count": 5, + "execution_count": 17, "outputs": [ { "output_type": "stream", "text": [ - "[[0. 0.]\n", - " [0. 0.]]\n", - "[[1. 1. 1.]\n", - " [1. 1. 1.]\n", - " [1. 1. 1.]]\n" + "[0 1 2 3 4 5 6 7 8 9]\n", + "[ 0. 2. 4. 6. 8. 10.]\n" ], "name": "stdout" - }, - { - "output_type": "stream", - "text": [ - "/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:1: DeprecationWarning: elementwise == comparison failed; this will raise an error in the future.\n", - " \"\"\"Entry point for launching an IPython kernel.\n", - "/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:2: DeprecationWarning: elementwise == comparison failed; this will raise an error in the future.\n", - " \n" - ], - "name": "stderr" } ] }, From 6efe34e658c393449d51d4aba07c9ff0a32aec21 Mon Sep 17 00:00:00 2001 From: Diya Nag Chaudhury <43166705+dnc2k@users.noreply.github.com> Date: Sat, 29 Sep 2018 06:28:02 +0530 Subject: [PATCH 6/8] Pandas Examples --- Basic_Pandas.ipynb | 1026 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1026 insertions(+) create mode 100644 Basic_Pandas.ipynb diff --git a/Basic_Pandas.ipynb b/Basic_Pandas.ipynb new file mode 100644 index 0000000..cc5c2a6 --- /dev/null +++ b/Basic_Pandas.ipynb @@ -0,0 +1,1026 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "Basic Pandas.ipynb", + "version": "0.3.2", + "provenance": [], + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "[View in Colaboratory](https://colab.research.google.com/github/dnc2k/Assignment-2/blob/dnc2k/Basic_Pandas.ipynb)" + ] + }, + { + "metadata": { + "id": "cGbE814_Xaf9", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "# Pandas\n", + "\n", + "Pandas is an open-source, BSD-licensed Python library providing high-performance, easy-to-use data structures and data analysis tools for the Python programming language. Python with Pandas is used in a wide range of fields including academic and commercial domains including finance, economics, Statistics, analytics, etc.In this tutorial, we will learn the various features of Python Pandas and how to use them in practice.\n", + "\n", + "\n", + "## Import pandas and numpy" + ] + }, + { + "metadata": { + "id": "irlVYeeAXPDL", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "import pandas as pd\n", + "import numpy as np" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "BI2J-zdMbGwE", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "### This is your playground feel free to explore other functions on pandas\n", + "\n", + "#### Create Series from numpy array, list and dict\n", + "\n", + "Don't know what a series is?\n", + "\n", + "[Series Doc](https://pandas.pydata.org/pandas-docs/version/0.22/generated/pandas.Series.html)" + ] + }, + { + "metadata": { + "id": "GeEct691YGE3", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 147 + }, + "outputId": "448aec2f-244f-4e30-c2f9-2bd92b587314" + }, + "cell_type": "code", + "source": [ + "a_ascii = ord('A')\n", + "z_ascii = ord('Z')\n", + "alphabets = [chr(i) for i in range(a_ascii, z_ascii+1)]\n", + "\n", + "print(alphabets)\n", + "\n", + "numbers = np.arange(26)\n", + "\n", + "print(numbers)\n", + "\n", + "print(type(alphabets), type(numbers))\n", + "\n", + "alpha_numbers = dict(zip(alphabets, numbers))\n", + "\n", + "print(alpha_numbers)\n", + "\n", + "print(type(alpha_numbers))" + ], + "execution_count": 2, + "outputs": [ + { + "output_type": "stream", + "text": [ + "['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']\n", + "[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23\n", + " 24 25]\n", + " \n", + "{'A': 0, 'B': 1, 'C': 2, 'D': 3, 'E': 4, 'F': 5, 'G': 6, 'H': 7, 'I': 8, 'J': 9, 'K': 10, 'L': 11, 'M': 12, 'N': 13, 'O': 14, 'P': 15, 'Q': 16, 'R': 17, 'S': 18, 'T': 19, 'U': 20, 'V': 21, 'W': 22, 'X': 23, 'Y': 24, 'Z': 25}\n", + "\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "6ouDfjWab_Mc", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 513 + }, + "outputId": "1c4b50a5-138d-4fc3-a1b8-167121590285" + }, + "cell_type": "code", + "source": [ + "series1 = pd.Series(alphabets)\n", + "print(series1)" + ], + "execution_count": 3, + "outputs": [ + { + "output_type": "stream", + "text": [ + "0 A\n", + "1 B\n", + "2 C\n", + "3 D\n", + "4 E\n", + "5 F\n", + "6 G\n", + "7 H\n", + "8 I\n", + "9 J\n", + "10 K\n", + "11 L\n", + "12 M\n", + "13 N\n", + "14 O\n", + "15 P\n", + "16 Q\n", + "17 R\n", + "18 S\n", + "19 T\n", + "20 U\n", + "21 V\n", + "22 W\n", + "23 X\n", + "24 Y\n", + "25 Z\n", + "dtype: object\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "At7nY7vVcBZ3", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 513 + }, + "outputId": "4d071048-cd01-445a-8654-a26543b686df" + }, + "cell_type": "code", + "source": [ + "series2 = pd.Series(numbers)\n", + "print(series2)" + ], + "execution_count": 4, + "outputs": [ + { + "output_type": "stream", + "text": [ + "0 0\n", + "1 1\n", + "2 2\n", + "3 3\n", + "4 4\n", + "5 5\n", + "6 6\n", + "7 7\n", + "8 8\n", + "9 9\n", + "10 10\n", + "11 11\n", + "12 12\n", + "13 13\n", + "14 14\n", + "15 15\n", + "16 16\n", + "17 17\n", + "18 18\n", + "19 19\n", + "20 20\n", + "21 21\n", + "22 22\n", + "23 23\n", + "24 24\n", + "25 25\n", + "dtype: int64\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "J5z-2CWAdH6N", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 513 + }, + "outputId": "b9ed4864-bf52-409e-a07a-a56eb4abee9f" + }, + "cell_type": "code", + "source": [ + "series3 = pd.Series(alpha_numbers)\n", + "print(series3)" + ], + "execution_count": 5, + "outputs": [ + { + "output_type": "stream", + "text": [ + "A 0\n", + "B 1\n", + "C 2\n", + "D 3\n", + "E 4\n", + "F 5\n", + "G 6\n", + "H 7\n", + "I 8\n", + "J 9\n", + "K 10\n", + "L 11\n", + "M 12\n", + "N 13\n", + "O 14\n", + "P 15\n", + "Q 16\n", + "R 17\n", + "S 18\n", + "T 19\n", + "U 20\n", + "V 21\n", + "W 22\n", + "X 23\n", + "Y 24\n", + "Z 25\n", + "dtype: int64\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "fYzblGGudKjO", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 127 + }, + "outputId": "01d11b62-8fba-419a-8e51-f36bc07c2ba5" + }, + "cell_type": "code", + "source": [ + "#replace head() with head(n) where n can be any number between [0-25] and observe the output in deach case \n", + "series3.head(5)" + ], + "execution_count": 10, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "A 0\n", + "B 1\n", + "C 2\n", + "D 3\n", + "E 4\n", + "dtype: int64" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 10 + } + ] + }, + { + "metadata": { + "id": "OwsJIf5feTtg", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "#### Create DataFrame from lists\n", + "\n", + "[DataFrame Doc](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.html)" + ] + }, + { + "metadata": { + "id": "73UTZ07EdWki", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 865 + }, + "outputId": "f6b26a00-e9b7-43bc-e1d2-505f2723f82f" + }, + "cell_type": "code", + "source": [ + "data = {'alphabets': alphabets, 'values': numbers}\n", + "\n", + "df = pd.DataFrame(data)\n", + "\n", + "#Lets Change the column `values` to `alpha_numbers`\n", + "\n", + "df.columns = ['alphabets', 'alpha_numbers']\n", + "\n", + "df" + ], + "execution_count": 8, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
alphabetsalpha_numbers
0A0
1B1
2C2
3D3
4E4
5F5
6G6
7H7
8I8
9J9
10K10
11L11
12M12
13N13
14O14
15P15
16Q16
17R17
18S18
19T19
20U20
21V21
22W22
23X23
24Y24
25Z25
\n", + "
" + ], + "text/plain": [ + " alphabets alpha_numbers\n", + "0 A 0\n", + "1 B 1\n", + "2 C 2\n", + "3 D 3\n", + "4 E 4\n", + "5 F 5\n", + "6 G 6\n", + "7 H 7\n", + "8 I 8\n", + "9 J 9\n", + "10 K 10\n", + "11 L 11\n", + "12 M 12\n", + "13 N 13\n", + "14 O 14\n", + "15 P 15\n", + "16 Q 16\n", + "17 R 17\n", + "18 S 18\n", + "19 T 19\n", + "20 U 20\n", + "21 V 21\n", + "22 W 22\n", + "23 X 23\n", + "24 Y 24\n", + "25 Z 25" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 8 + } + ] + }, + { + "metadata": { + "id": "uaK_1EO9etGS", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 141 + }, + "outputId": "3766ccdc-5b8d-4b12-92db-156b1c1f0bce" + }, + "cell_type": "code", + "source": [ + "# transpose\n", + "\n", + "df.T\n", + "\n", + "# there are many more operations which we can perform look at the documentation with the subsequent exercises we will learn more" + ], + "execution_count": 9, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
0123456789...16171819202122232425
alphabetsABCDEFGHIJ...QRSTUVWXYZ
alpha_numbers0123456789...16171819202122232425
\n", + "

2 rows × 26 columns

\n", + "
" + ], + "text/plain": [ + " 0 1 2 3 4 5 6 7 8 9 ... 16 17 18 19 20 21 22 \\\n", + "alphabets A B C D E F G H I J ... Q R S T U V W \n", + "alpha_numbers 0 1 2 3 4 5 6 7 8 9 ... 16 17 18 19 20 21 22 \n", + "\n", + " 23 24 25 \n", + "alphabets X Y Z \n", + "alpha_numbers 23 24 25 \n", + "\n", + "[2 rows x 26 columns]" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 9 + } + ] + }, + { + "metadata": { + "id": "ZYonoaW8gEAJ", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "#### Extract Items from a series" + ] + }, + { + "metadata": { + "id": "tc1-KX_Bfe7U", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 206 + }, + "outputId": "6baf4b89-80fa-49b4-de26-190f1008d245" + }, + "cell_type": "code", + "source": [ + "ser = pd.Series(list('abcdefghijklmnopqrstuvwxyz'))\n", + "pos = [0, 4, 8, 14, 20]\n", + "\n", + "vowels = ser.take(pos)\n", + "\n", + "df = pd.DataFrame(vowels)#, columns=['vowels'])\n", + "\n", + "df.columns = ['vowels']\n", + "\n", + "df.index = [0, 1, 2, 3, 4]\n", + "\n", + "df" + ], + "execution_count": 15, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
vowels
0a
1e
2i
3o
4u
\n", + "
" + ], + "text/plain": [ + " vowels\n", + "0 a\n", + "1 e\n", + "2 i\n", + "3 o\n", + "4 u" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 15 + } + ] + }, + { + "metadata": { + "id": "cmDxwtDNjWpO", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "#### Change the first character of each word to upper case in each word of ser" + ] + }, + { + "metadata": { + "id": "5KagP9PpgV2F", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "outputId": "69ac4989-7430-4cb8-8f5b-7fbfe73a33b9" + }, + "cell_type": "code", + "source": [ + "ser = pd.Series(['we', 'are', 'learning', 'pandas'])\n", + "\n", + "ser.map(lambda x : x.title())\n", + "\n", + "titles = [i.title() for i in ser]\n", + "\n", + "titles" + ], + "execution_count": 16, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "['We', 'Are', 'Learning', 'Pandas']" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 16 + } + ] + }, + { + "metadata": { + "id": "qn47ee-MkZN8", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "#### Reindexing" + ] + }, + { + "metadata": { + "id": "h5R0JL2NjuFS", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 206 + }, + "outputId": "0da25db2-170f-4e2a-a545-0e21fd5c10e1" + }, + "cell_type": "code", + "source": [ + "my_index = [1, 2, 3, 4, 5]\n", + "\n", + "df1 = pd.DataFrame({'upper values': ['A', 'B', 'C', 'D', 'E'],\n", + " 'lower values': ['a', 'b', 'c', 'd', 'e']},\n", + " index = my_index)\n", + "\n", + "df1" + ], + "execution_count": 17, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
lower valuesupper values
1aA
2bB
3cC
4dD
5eE
\n", + "
" + ], + "text/plain": [ + " lower values upper values\n", + "1 a A\n", + "2 b B\n", + "3 c C\n", + "4 d D\n", + "5 e E" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 17 + } + ] + }, + { + "metadata": { + "id": "G_Frvc3mk93k", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 206 + }, + "outputId": "30daf710-853d-43e0-d52c-f1301b9522e9" + }, + "cell_type": "code", + "source": [ + "new_index = [2, 5, 4, 3, 1]\n", + "\n", + "df1.reindex(index = new_index)" + ], + "execution_count": 18, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
lower valuesupper values
2bB
5eE
4dD
3cC
1aA
\n", + "
" + ], + "text/plain": [ + " lower values upper values\n", + "2 b B\n", + "5 e E\n", + "4 d D\n", + "3 c C\n", + "1 a A" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 18 + } + ] + } + ] +} \ No newline at end of file From 640a11847292484297cec6edf58d5f8a875eba1f Mon Sep 17 00:00:00 2001 From: Diya Nag Chaudhury <43166705+dnc2k@users.noreply.github.com> Date: Sat, 29 Sep 2018 06:44:56 +0530 Subject: [PATCH 7/8] Get to know your Data in Pandas --- Get_to_know_your_Data.ipynb | 2354 +++++++++++++++++++++++++++++++++++ 1 file changed, 2354 insertions(+) create mode 100644 Get_to_know_your_Data.ipynb diff --git a/Get_to_know_your_Data.ipynb b/Get_to_know_your_Data.ipynb new file mode 100644 index 0000000..9065529 --- /dev/null +++ b/Get_to_know_your_Data.ipynb @@ -0,0 +1,2354 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "Get to know your Data.ipynb", + "version": "0.3.2", + "provenance": [], + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "[View in Colaboratory](https://colab.research.google.com/github/dnc2k/Assignment-2/blob/dnc2k/Get_to_know_your_Data.ipynb)" + ] + }, + { + "metadata": { + "id": "J82LU53m_OU0", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "# Get to know your Data\n", + "\n", + "\n", + "#### Import necessary modules\n" + ] + }, + { + "metadata": { + "id": "ZyO1UXL8mtSj", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "import pandas as pd\n", + "import numpy as np" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "yXTzTowtnwGI", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "#### Loading CSV Data to a DataFrame" + ] + }, + { + "metadata": { + "id": "H1Bjlb5wm9f-", + "colab_type": "code", + "colab": {} + }, + "cell_type": "code", + "source": [ + "iris_df = pd.read_csv('https://raw.githubusercontent.com/uiuc-cse/data-fa14/gh-pages/data/iris.csv')\n" + ], + "execution_count": 0, + "outputs": [] + }, + { + "metadata": { + "id": "KE-k7b_Mn5iN", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "#### See the top 10 rows\n" + ] + }, + { + "metadata": { + "id": "HY2Ps7xMn4ao", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 206 + }, + "outputId": "b3885b8d-976d-4d86-b736-455a1b4dacbd" + }, + "cell_type": "code", + "source": [ + "iris_df.head()" + ], + "execution_count": 3, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sepal_lengthsepal_widthpetal_lengthpetal_widthspecies
05.13.51.40.2setosa
14.93.01.40.2setosa
24.73.21.30.2setosa
34.63.11.50.2setosa
45.03.61.40.2setosa
\n", + "
" + ], + "text/plain": [ + " sepal_length sepal_width petal_length petal_width species\n", + "0 5.1 3.5 1.4 0.2 setosa\n", + "1 4.9 3.0 1.4 0.2 setosa\n", + "2 4.7 3.2 1.3 0.2 setosa\n", + "3 4.6 3.1 1.5 0.2 setosa\n", + "4 5.0 3.6 1.4 0.2 setosa" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 3 + } + ] + }, + { + "metadata": { + "id": "ZQXekIodqOZu", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "#### Find number of rows and columns\n" + ] + }, + { + "metadata": { + "id": "6Y-A-lbFqR82", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 72 + }, + "outputId": "16f316ca-d432-4e85-c69e-858b96ac6223" + }, + "cell_type": "code", + "source": [ + "print(iris_df.shape)\n", + "\n", + "#first is row and second is column\n", + "#select row by simple indexing\n", + "\n", + "print(iris_df.shape[0])\n", + "print(iris_df.shape[1])" + ], + "execution_count": 5, + "outputs": [ + { + "output_type": "stream", + "text": [ + "(150, 5)\n", + "150\n", + "5\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "4ckCiGPhrC_t", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "#### Print all columns" + ] + }, + { + "metadata": { + "id": "S6jgMyRDrF2a", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 72 + }, + "outputId": "fafa4cc7-b62d-4f89-80c2-9675b7e27275" + }, + "cell_type": "code", + "source": [ + "print(iris_df.columns)" + ], + "execution_count": 6, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Index(['sepal_length', 'sepal_width', 'petal_length', 'petal_width',\n", + " 'species'],\n", + " dtype='object')\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "kVav5-ACtIqS", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "#### Check Index\n" + ] + }, + { + "metadata": { + "id": "iu3I9zIGtLDX", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "outputId": "bb648e8c-d63a-48a6-d120-ecb0fa35dc9b" + }, + "cell_type": "code", + "source": [ + "print(iris_df.index)" + ], + "execution_count": 7, + "outputs": [ + { + "output_type": "stream", + "text": [ + "RangeIndex(start=0, stop=150, step=1)\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "psCc7PborOCQ", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "#### Right now the iris_data set has all the species grouped together let's shuffle it" + ] + }, + { + "metadata": { + "id": "Bxc8i6avrZPw", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 237 + }, + "outputId": "83f93cef-be1a-446d-e113-7dd23d70f087" + }, + "cell_type": "code", + "source": [ + "#generate a random permutaion on index\n", + "\n", + "print(iris_df.head())\n", + "\n", + "new_index = np.random.permutation(iris_df.index)\n", + "iris_df = iris_df.reindex(index = new_index)\n", + "\n", + "print(iris_df.head())" + ], + "execution_count": 8, + "outputs": [ + { + "output_type": "stream", + "text": [ + " sepal_length sepal_width petal_length petal_width species\n", + "0 5.1 3.5 1.4 0.2 setosa\n", + "1 4.9 3.0 1.4 0.2 setosa\n", + "2 4.7 3.2 1.3 0.2 setosa\n", + "3 4.6 3.1 1.5 0.2 setosa\n", + "4 5.0 3.6 1.4 0.2 setosa\n", + " sepal_length sepal_width petal_length petal_width species\n", + "97 6.2 2.9 4.3 1.3 versicolor\n", + "103 6.3 2.9 5.6 1.8 virginica\n", + "6 4.6 3.4 1.4 0.3 setosa\n", + "1 4.9 3.0 1.4 0.2 setosa\n", + "58 6.6 2.9 4.6 1.3 versicolor\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "j32h8022sRT8", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "#### We can also apply an operation on whole column of iris_df" + ] + }, + { + "metadata": { + "id": "seYXHXsYsYJI", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 348 + }, + "outputId": "1101114c-d7bc-4667-ec14-a215ed860945" + }, + "cell_type": "code", + "source": [ + "#original\n", + "\n", + "print(iris_df.head())\n", + "\n", + "iris_df['sepal_width'] *= 10\n", + "\n", + "#changed\n", + "\n", + "print(iris_df.head())\n", + "\n", + "#lets undo the operation\n", + "\n", + "iris_df['sepal_width'] /= 10\n", + "\n", + "print(iris_df.head())" + ], + "execution_count": 9, + "outputs": [ + { + "output_type": "stream", + "text": [ + " sepal_length sepal_width petal_length petal_width species\n", + "97 6.2 2.9 4.3 1.3 versicolor\n", + "103 6.3 2.9 5.6 1.8 virginica\n", + "6 4.6 3.4 1.4 0.3 setosa\n", + "1 4.9 3.0 1.4 0.2 setosa\n", + "58 6.6 2.9 4.6 1.3 versicolor\n", + " sepal_length sepal_width petal_length petal_width species\n", + "97 6.2 29.0 4.3 1.3 versicolor\n", + "103 6.3 29.0 5.6 1.8 virginica\n", + "6 4.6 34.0 1.4 0.3 setosa\n", + "1 4.9 30.0 1.4 0.2 setosa\n", + "58 6.6 29.0 4.6 1.3 versicolor\n", + " sepal_length sepal_width petal_length petal_width species\n", + "97 6.2 2.9 4.3 1.3 versicolor\n", + "103 6.3 2.9 5.6 1.8 virginica\n", + "6 4.6 3.4 1.4 0.3 setosa\n", + "1 4.9 3.0 1.4 0.2 setosa\n", + "58 6.6 2.9 4.6 1.3 versicolor\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "R-Ca-LBLzjiF", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "#### Show all the rows where sepal_width > 3.3" + ] + }, + { + "metadata": { + "id": "WJ7W-F-d0AoZ", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1179 + }, + "outputId": "f304de3d-0e95-4b9f-c3d5-e835e62d33f8" + }, + "cell_type": "code", + "source": [ + "iris_df[iris_df['sepal_width']>3.3]" + ], + "execution_count": 10, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sepal_lengthsepal_widthpetal_lengthpetal_widthspecies
64.63.41.40.3setosa
335.54.21.40.2setosa
165.43.91.30.4setosa
445.13.81.90.4setosa
365.53.51.30.2setosa
405.03.51.30.3setosa
275.23.51.50.2setosa
205.43.41.70.2setosa
195.13.81.50.3setosa
1486.23.45.42.3virginica
435.03.51.60.6setosa
1317.93.86.42.0virginica
1177.73.86.72.2virginica
315.43.41.50.4setosa
224.63.61.00.2setosa
215.13.71.50.4setosa
856.03.44.51.6versicolor
395.13.41.50.2setosa
145.84.01.20.2setosa
05.13.51.40.2setosa
45.03.61.40.2setosa
265.03.41.60.4setosa
185.73.81.70.3setosa
1097.23.66.12.5virginica
155.74.41.50.4setosa
244.83.41.90.2setosa
285.23.41.40.2setosa
75.03.41.50.2setosa
114.83.41.60.2setosa
325.24.11.50.1setosa
1366.33.45.62.4virginica
175.13.51.40.3setosa
105.43.71.50.2setosa
55.43.91.70.4setosa
485.33.71.50.2setosa
465.13.81.60.2setosa
\n", + "
" + ], + "text/plain": [ + " sepal_length sepal_width petal_length petal_width species\n", + "6 4.6 3.4 1.4 0.3 setosa\n", + "33 5.5 4.2 1.4 0.2 setosa\n", + "16 5.4 3.9 1.3 0.4 setosa\n", + "44 5.1 3.8 1.9 0.4 setosa\n", + "36 5.5 3.5 1.3 0.2 setosa\n", + "40 5.0 3.5 1.3 0.3 setosa\n", + "27 5.2 3.5 1.5 0.2 setosa\n", + "20 5.4 3.4 1.7 0.2 setosa\n", + "19 5.1 3.8 1.5 0.3 setosa\n", + "148 6.2 3.4 5.4 2.3 virginica\n", + "43 5.0 3.5 1.6 0.6 setosa\n", + "131 7.9 3.8 6.4 2.0 virginica\n", + "117 7.7 3.8 6.7 2.2 virginica\n", + "31 5.4 3.4 1.5 0.4 setosa\n", + "22 4.6 3.6 1.0 0.2 setosa\n", + "21 5.1 3.7 1.5 0.4 setosa\n", + "85 6.0 3.4 4.5 1.6 versicolor\n", + "39 5.1 3.4 1.5 0.2 setosa\n", + "14 5.8 4.0 1.2 0.2 setosa\n", + "0 5.1 3.5 1.4 0.2 setosa\n", + "4 5.0 3.6 1.4 0.2 setosa\n", + "26 5.0 3.4 1.6 0.4 setosa\n", + "18 5.7 3.8 1.7 0.3 setosa\n", + "109 7.2 3.6 6.1 2.5 virginica\n", + "15 5.7 4.4 1.5 0.4 setosa\n", + "24 4.8 3.4 1.9 0.2 setosa\n", + "28 5.2 3.4 1.4 0.2 setosa\n", + "7 5.0 3.4 1.5 0.2 setosa\n", + "11 4.8 3.4 1.6 0.2 setosa\n", + "32 5.2 4.1 1.5 0.1 setosa\n", + "136 6.3 3.4 5.6 2.4 virginica\n", + "17 5.1 3.5 1.4 0.3 setosa\n", + "10 5.4 3.7 1.5 0.2 setosa\n", + "5 5.4 3.9 1.7 0.4 setosa\n", + "48 5.3 3.7 1.5 0.2 setosa\n", + "46 5.1 3.8 1.6 0.2 setosa" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 10 + } + ] + }, + { + "metadata": { + "id": "gH3DnhCq2Cbl", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "#### Club two filters together - Find all samples where sepal_width > 3.3 and species is versicolor" + ] + }, + { + "metadata": { + "id": "4U7ksr_R2H7M", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 81 + }, + "outputId": "b1b304dc-251b-42d8-b214-25f51493e578" + }, + "cell_type": "code", + "source": [ + "iris_df[(iris_df['sepal_width']>3.3) & (iris_df['species'] == 'versicolor')] " + ], + "execution_count": 11, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sepal_lengthsepal_widthpetal_lengthpetal_widthspecies
856.03.44.51.6versicolor
\n", + "
" + ], + "text/plain": [ + " sepal_length sepal_width petal_length petal_width species\n", + "85 6.0 3.4 4.5 1.6 versicolor" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 11 + } + ] + }, + { + "metadata": { + "id": "1lmnB3ot2u7I", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "#### Sorting a column by value" + ] + }, + { + "metadata": { + "id": "K7KIj6fv2zWP", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1992 + }, + "outputId": "9c54e5a0-60ce-4853-f6c7-5311daa91e60" + }, + "cell_type": "code", + "source": [ + "iris_df.sort_values(by='sepal_width')#, ascending = False)\n", + "#pass ascending = False for descending order" + ], + "execution_count": 12, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sepal_lengthsepal_widthpetal_lengthpetal_widthspecies
605.02.03.51.0versicolor
1196.02.25.01.5virginica
686.22.24.51.5versicolor
626.02.24.01.0versicolor
535.52.34.01.3versicolor
876.32.34.41.3versicolor
935.02.33.31.0versicolor
414.52.31.30.3setosa
574.92.43.31.0versicolor
815.52.43.71.0versicolor
805.52.43.81.1versicolor
895.52.54.01.3versicolor
1086.72.55.81.8virginica
985.12.53.01.1versicolor
1466.32.55.01.9virginica
1064.92.54.51.7virginica
726.32.54.91.5versicolor
695.62.53.91.1versicolor
1135.72.55.02.0virginica
905.52.64.41.2versicolor
1187.72.66.92.3virginica
795.72.63.51.0versicolor
1346.12.65.61.4virginica
925.82.64.01.2versicolor
825.82.73.91.2versicolor
595.22.73.91.4versicolor
1116.42.75.31.9virginica
945.62.74.21.3versicolor
1015.82.75.11.9virginica
675.82.74.11.0versicolor
..................
205.43.41.70.2setosa
1486.23.45.42.3virginica
395.13.41.50.2setosa
856.03.44.51.6versicolor
64.63.41.40.3setosa
244.83.41.90.2setosa
365.53.51.30.2setosa
275.23.51.50.2setosa
05.13.51.40.2setosa
175.13.51.40.3setosa
435.03.51.60.6setosa
405.03.51.30.3setosa
224.63.61.00.2setosa
1097.23.66.12.5virginica
45.03.61.40.2setosa
215.13.71.50.4setosa
105.43.71.50.2setosa
485.33.71.50.2setosa
465.13.81.60.2setosa
445.13.81.90.4setosa
1177.73.86.72.2virginica
185.73.81.70.3setosa
195.13.81.50.3setosa
1317.93.86.42.0virginica
55.43.91.70.4setosa
165.43.91.30.4setosa
145.84.01.20.2setosa
325.24.11.50.1setosa
335.54.21.40.2setosa
155.74.41.50.4setosa
\n", + "

150 rows × 5 columns

\n", + "
" + ], + "text/plain": [ + " sepal_length sepal_width petal_length petal_width species\n", + "60 5.0 2.0 3.5 1.0 versicolor\n", + "119 6.0 2.2 5.0 1.5 virginica\n", + "68 6.2 2.2 4.5 1.5 versicolor\n", + "62 6.0 2.2 4.0 1.0 versicolor\n", + "53 5.5 2.3 4.0 1.3 versicolor\n", + "87 6.3 2.3 4.4 1.3 versicolor\n", + "93 5.0 2.3 3.3 1.0 versicolor\n", + "41 4.5 2.3 1.3 0.3 setosa\n", + "57 4.9 2.4 3.3 1.0 versicolor\n", + "81 5.5 2.4 3.7 1.0 versicolor\n", + "80 5.5 2.4 3.8 1.1 versicolor\n", + "89 5.5 2.5 4.0 1.3 versicolor\n", + "108 6.7 2.5 5.8 1.8 virginica\n", + "98 5.1 2.5 3.0 1.1 versicolor\n", + "146 6.3 2.5 5.0 1.9 virginica\n", + "106 4.9 2.5 4.5 1.7 virginica\n", + "72 6.3 2.5 4.9 1.5 versicolor\n", + "69 5.6 2.5 3.9 1.1 versicolor\n", + "113 5.7 2.5 5.0 2.0 virginica\n", + "90 5.5 2.6 4.4 1.2 versicolor\n", + "118 7.7 2.6 6.9 2.3 virginica\n", + "79 5.7 2.6 3.5 1.0 versicolor\n", + "134 6.1 2.6 5.6 1.4 virginica\n", + "92 5.8 2.6 4.0 1.2 versicolor\n", + "82 5.8 2.7 3.9 1.2 versicolor\n", + "59 5.2 2.7 3.9 1.4 versicolor\n", + "111 6.4 2.7 5.3 1.9 virginica\n", + "94 5.6 2.7 4.2 1.3 versicolor\n", + "101 5.8 2.7 5.1 1.9 virginica\n", + "67 5.8 2.7 4.1 1.0 versicolor\n", + ".. ... ... ... ... ...\n", + "20 5.4 3.4 1.7 0.2 setosa\n", + "148 6.2 3.4 5.4 2.3 virginica\n", + "39 5.1 3.4 1.5 0.2 setosa\n", + "85 6.0 3.4 4.5 1.6 versicolor\n", + "6 4.6 3.4 1.4 0.3 setosa\n", + "24 4.8 3.4 1.9 0.2 setosa\n", + "36 5.5 3.5 1.3 0.2 setosa\n", + "27 5.2 3.5 1.5 0.2 setosa\n", + "0 5.1 3.5 1.4 0.2 setosa\n", + "17 5.1 3.5 1.4 0.3 setosa\n", + "43 5.0 3.5 1.6 0.6 setosa\n", + "40 5.0 3.5 1.3 0.3 setosa\n", + "22 4.6 3.6 1.0 0.2 setosa\n", + "109 7.2 3.6 6.1 2.5 virginica\n", + "4 5.0 3.6 1.4 0.2 setosa\n", + "21 5.1 3.7 1.5 0.4 setosa\n", + "10 5.4 3.7 1.5 0.2 setosa\n", + "48 5.3 3.7 1.5 0.2 setosa\n", + "46 5.1 3.8 1.6 0.2 setosa\n", + "44 5.1 3.8 1.9 0.4 setosa\n", + "117 7.7 3.8 6.7 2.2 virginica\n", + "18 5.7 3.8 1.7 0.3 setosa\n", + "19 5.1 3.8 1.5 0.3 setosa\n", + "131 7.9 3.8 6.4 2.0 virginica\n", + "5 5.4 3.9 1.7 0.4 setosa\n", + "16 5.4 3.9 1.3 0.4 setosa\n", + "14 5.8 4.0 1.2 0.2 setosa\n", + "32 5.2 4.1 1.5 0.1 setosa\n", + "33 5.5 4.2 1.4 0.2 setosa\n", + "15 5.7 4.4 1.5 0.4 setosa\n", + "\n", + "[150 rows x 5 columns]" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 12 + } + ] + }, + { + "metadata": { + "id": "9jg_Z4YCoMSV", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "#### List all the unique species" + ] + }, + { + "metadata": { + "id": "M6EN78ufoJY7", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "outputId": "a2e0fe49-7270-4b54-8f3f-2329a6024c84" + }, + "cell_type": "code", + "source": [ + "species = iris_df['species'].unique()\n", + "\n", + "print(species)" + ], + "execution_count": 13, + "outputs": [ + { + "output_type": "stream", + "text": [ + "['versicolor' 'virginica' 'setosa']\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "wG1i5nxBodmB", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "#### Selecting a particular species using boolean mask (learnt in previous exercise)" + ] + }, + { + "metadata": { + "id": "gZvpbKBwoVUe", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 206 + }, + "outputId": "ebf829ba-a0de-4393-a898-5b2d8fc62991" + }, + "cell_type": "code", + "source": [ + "setosa = iris_df[iris_df['species'] == species[0]]\n", + "\n", + "setosa.head()" + ], + "execution_count": 14, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sepal_lengthsepal_widthpetal_lengthpetal_widthspecies
976.22.94.31.3versicolor
586.62.94.61.3versicolor
766.82.84.81.4versicolor
955.73.04.21.2versicolor
845.43.04.51.5versicolor
\n", + "
" + ], + "text/plain": [ + " sepal_length sepal_width petal_length petal_width species\n", + "97 6.2 2.9 4.3 1.3 versicolor\n", + "58 6.6 2.9 4.6 1.3 versicolor\n", + "76 6.8 2.8 4.8 1.4 versicolor\n", + "95 5.7 3.0 4.2 1.2 versicolor\n", + "84 5.4 3.0 4.5 1.5 versicolor" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 14 + } + ] + }, + { + "metadata": { + "id": "7tumfZ3DotPG", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 206 + }, + "outputId": "ed1e77a9-5413-40d5-9af7-5f6d31b60128" + }, + "cell_type": "code", + "source": [ + "# do the same for other 2 species \n", + "versicolor = iris_df[iris_df['species'] == species[1]]\n", + "\n", + "versicolor.head()" + ], + "execution_count": 15, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sepal_lengthsepal_widthpetal_lengthpetal_widthspecies
1036.32.95.61.8virginica
1126.83.05.52.1virginica
1246.73.35.72.1virginica
1336.32.85.11.5virginica
1486.23.45.42.3virginica
\n", + "
" + ], + "text/plain": [ + " sepal_length sepal_width petal_length petal_width species\n", + "103 6.3 2.9 5.6 1.8 virginica\n", + "112 6.8 3.0 5.5 2.1 virginica\n", + "124 6.7 3.3 5.7 2.1 virginica\n", + "133 6.3 2.8 5.1 1.5 virginica\n", + "148 6.2 3.4 5.4 2.3 virginica" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 15 + } + ] + }, + { + "metadata": { + "id": "cUYm5UqVpDPy", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 206 + }, + "outputId": "bda8d3a2-07b1-4b58-99f7-82380218806f" + }, + "cell_type": "code", + "source": [ + "\n", + "\n", + "virginica = iris_df[iris_df['species'] == species[2]]\n", + "\n", + "virginica.head()" + ], + "execution_count": 16, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sepal_lengthsepal_widthpetal_lengthpetal_widthspecies
64.63.41.40.3setosa
14.93.01.40.2setosa
335.54.21.40.2setosa
84.42.91.40.2setosa
384.43.01.30.2setosa
\n", + "
" + ], + "text/plain": [ + " sepal_length sepal_width petal_length petal_width species\n", + "6 4.6 3.4 1.4 0.3 setosa\n", + "1 4.9 3.0 1.4 0.2 setosa\n", + "33 5.5 4.2 1.4 0.2 setosa\n", + "8 4.4 2.9 1.4 0.2 setosa\n", + "38 4.4 3.0 1.3 0.2 setosa" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 16 + } + ] + }, + { + "metadata": { + "id": "-y1wDc8SpdQs", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "#### Describe each created species to see the difference\n", + "\n" + ] + }, + { + "metadata": { + "id": "eHrn3ZVRpOk5", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 300 + }, + "outputId": "bac6caca-dbfb-492e-8f17-bce2825a6451" + }, + "cell_type": "code", + "source": [ + "setosa.describe()" + ], + "execution_count": 17, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sepal_lengthsepal_widthpetal_lengthpetal_width
count50.00000050.00000050.00000050.000000
mean5.9360002.7700004.2600001.326000
std0.5161710.3137980.4699110.197753
min4.9000002.0000003.0000001.000000
25%5.6000002.5250004.0000001.200000
50%5.9000002.8000004.3500001.300000
75%6.3000003.0000004.6000001.500000
max7.0000003.4000005.1000001.800000
\n", + "
" + ], + "text/plain": [ + " sepal_length sepal_width petal_length petal_width\n", + "count 50.000000 50.000000 50.000000 50.000000\n", + "mean 5.936000 2.770000 4.260000 1.326000\n", + "std 0.516171 0.313798 0.469911 0.197753\n", + "min 4.900000 2.000000 3.000000 1.000000\n", + "25% 5.600000 2.525000 4.000000 1.200000\n", + "50% 5.900000 2.800000 4.350000 1.300000\n", + "75% 6.300000 3.000000 4.600000 1.500000\n", + "max 7.000000 3.400000 5.100000 1.800000" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 17 + } + ] + }, + { + "metadata": { + "id": "GwJFT2GlpwUv", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 300 + }, + "outputId": "f3bc1793-3de4-44ed-dc79-35ac4e28c423" + }, + "cell_type": "code", + "source": [ + "versicolor.describe()" + ], + "execution_count": 18, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sepal_lengthsepal_widthpetal_lengthpetal_width
count50.0000050.00000050.00000050.00000
mean6.588002.9740005.5520002.02600
std0.635880.3224970.5518950.27465
min4.900002.2000004.5000001.40000
25%6.225002.8000005.1000001.80000
50%6.500003.0000005.5500002.00000
75%6.900003.1750005.8750002.30000
max7.900003.8000006.9000002.50000
\n", + "
" + ], + "text/plain": [ + " sepal_length sepal_width petal_length petal_width\n", + "count 50.00000 50.000000 50.000000 50.00000\n", + "mean 6.58800 2.974000 5.552000 2.02600\n", + "std 0.63588 0.322497 0.551895 0.27465\n", + "min 4.90000 2.200000 4.500000 1.40000\n", + "25% 6.22500 2.800000 5.100000 1.80000\n", + "50% 6.50000 3.000000 5.550000 2.00000\n", + "75% 6.90000 3.175000 5.875000 2.30000\n", + "max 7.90000 3.800000 6.900000 2.50000" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 18 + } + ] + }, + { + "metadata": { + "id": "Ad4qhSZLpztf", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 300 + }, + "outputId": "1bef7a2a-5454-4371-a158-775085a3905c" + }, + "cell_type": "code", + "source": [ + "virginica.describe()" + ], + "execution_count": 19, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sepal_lengthsepal_widthpetal_lengthpetal_width
count50.0000050.00000050.00000050.00000
mean5.006003.4180001.4640000.24400
std0.352490.3810240.1735110.10721
min4.300002.3000001.0000000.10000
25%4.800003.1250001.4000000.20000
50%5.000003.4000001.5000000.20000
75%5.200003.6750001.5750000.30000
max5.800004.4000001.9000000.60000
\n", + "
" + ], + "text/plain": [ + " sepal_length sepal_width petal_length petal_width\n", + "count 50.00000 50.000000 50.000000 50.00000\n", + "mean 5.00600 3.418000 1.464000 0.24400\n", + "std 0.35249 0.381024 0.173511 0.10721\n", + "min 4.30000 2.300000 1.000000 0.10000\n", + "25% 4.80000 3.125000 1.400000 0.20000\n", + "50% 5.00000 3.400000 1.500000 0.20000\n", + "75% 5.20000 3.675000 1.575000 0.30000\n", + "max 5.80000 4.400000 1.900000 0.60000" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 19 + } + ] + }, + { + "metadata": { + "id": "Vdu0ulZWtr09", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "#### Let's plot and see the difference" + ] + }, + { + "metadata": { + "id": "PEVMzRvpttmD", + "colab_type": "text" + }, + "cell_type": "markdown", + "source": [ + "##### import matplotlib.pyplot " + ] + }, + { + "metadata": { + "id": "rqDXuuAtt7C3", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 402 + }, + "outputId": "021c56dd-a9fb-4313-e553-f75a57683298" + }, + "cell_type": "code", + "source": [ + "import matplotlib.pyplot as plt\n", + "\n", + "#hist creates a histogram there are many more plots(see the documentation) you can play with it.\n", + "\n", + "plt.hist(setosa['sepal_length'])\n", + "plt.hist(versicolor['sepal_length'])\n", + "plt.hist(virginica['sepal_length'])" + ], + "execution_count": 20, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "(array([ 4., 1., 6., 5., 12., 8., 4., 5., 2., 3.]),\n", + " array([4.3 , 4.45, 4.6 , 4.75, 4.9 , 5.05, 5.2 , 5.35, 5.5 , 5.65, 5.8 ]),\n", + " )" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 20 + }, + { + "output_type": "display_data", + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAd8AAAFKCAYAAABcq1WoAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAFGpJREFUeJzt3X9s1Hf9wPFX6cmwpWKHLQzdcFk0\ni9twkG0ZP92QH264uaErP8KQZCYiDGaCGdhgICExYeG7MN3cdEPmF0LCBgh8jZFFhMRsgEYMisnC\nwMTwY4Myys9CgO6+fxgacdDS6/V93PXx+Iv73PVzrzdvcs/eHb2WZbPZbAAAyXQr9AAA0NWILwAk\nJr4AkJj4AkBi4gsAiYkvACSWSXEnDQ2nUtxNXlRXV0RjY1Ohx+hUpb5G6yt+pb5G6yt+17LGmpqq\nq17nme9/yWTKCz1Cpyv1NVpf8Sv1NVpf8evoGsUXABITXwBITHwBIDHxBYDExBcAEhNfAEhMfAEg\nMfEFgMSuKb579uyJUaNGxcqVKyMi4v33349p06bFlClTYtq0adHQ0NC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\nTtp+EyZMiPr6+pgyZUpcvHgxFi5cmLf98/GSAJBYl33ZGQAKRXwBIDHxBYDExBcAEhNfAEhMfAEg\nMfEFgMTEFwAS+3/wQITBxOH0DQAAAABJRU5ErkJggg==\n", + "text/plain": [ + "" + ] + }, + "metadata": { + "tags": [] + } + } + ] + } + ] +} \ No newline at end of file From 101c8f408b193142a75fc82a9c33bc132c289d46 Mon Sep 17 00:00:00 2001 From: Diya N <43166705+dnc2k@users.noreply.github.com> Date: Tue, 22 Jan 2019 23:10:18 +0530 Subject: [PATCH 8/8] Delete Basic_Pandas.ipynb --- Basic_Pandas.ipynb | 1026 -------------------------------------------- 1 file changed, 1026 deletions(-) delete mode 100644 Basic_Pandas.ipynb diff --git a/Basic_Pandas.ipynb b/Basic_Pandas.ipynb deleted file mode 100644 index cc5c2a6..0000000 --- a/Basic_Pandas.ipynb +++ /dev/null @@ -1,1026 +0,0 @@ -{ - "nbformat": 4, - "nbformat_minor": 0, - "metadata": { - "colab": { - "name": "Basic Pandas.ipynb", - "version": "0.3.2", - "provenance": [], - "include_colab_link": true - }, - "kernelspec": { - "name": "python3", - "display_name": "Python 3" - } - }, - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "id": "view-in-github", - "colab_type": "text" - }, - "source": [ - "[View in Colaboratory](https://colab.research.google.com/github/dnc2k/Assignment-2/blob/dnc2k/Basic_Pandas.ipynb)" - ] - }, - { - "metadata": { - "id": "cGbE814_Xaf9", - "colab_type": "text" - }, - "cell_type": "markdown", - "source": [ - "# Pandas\n", - "\n", - "Pandas is an open-source, BSD-licensed Python library providing high-performance, easy-to-use data structures and data analysis tools for the Python programming language. Python with Pandas is used in a wide range of fields including academic and commercial domains including finance, economics, Statistics, analytics, etc.In this tutorial, we will learn the various features of Python Pandas and how to use them in practice.\n", - "\n", - "\n", - "## Import pandas and numpy" - ] - }, - { - "metadata": { - "id": "irlVYeeAXPDL", - "colab_type": "code", - "colab": {} - }, - "cell_type": "code", - "source": [ - "import pandas as pd\n", - "import numpy as np" - ], - "execution_count": 0, - "outputs": [] - }, - { - "metadata": { - "id": "BI2J-zdMbGwE", - "colab_type": "text" - }, - "cell_type": "markdown", - "source": [ - "### This is your playground feel free to explore other functions on pandas\n", - "\n", - "#### Create Series from numpy array, list and dict\n", - "\n", - "Don't know what a series is?\n", - "\n", - "[Series Doc](https://pandas.pydata.org/pandas-docs/version/0.22/generated/pandas.Series.html)" - ] - }, - { - "metadata": { - "id": "GeEct691YGE3", - "colab_type": "code", - "colab": { - "base_uri": "https://localhost:8080/", - "height": 147 - }, - "outputId": "448aec2f-244f-4e30-c2f9-2bd92b587314" - }, - "cell_type": "code", - "source": [ - "a_ascii = ord('A')\n", - "z_ascii = ord('Z')\n", - "alphabets = [chr(i) for i in range(a_ascii, z_ascii+1)]\n", - "\n", - "print(alphabets)\n", - "\n", - "numbers = np.arange(26)\n", - "\n", - "print(numbers)\n", - "\n", - "print(type(alphabets), type(numbers))\n", - "\n", - "alpha_numbers = dict(zip(alphabets, numbers))\n", - "\n", - "print(alpha_numbers)\n", - "\n", - "print(type(alpha_numbers))" - ], - "execution_count": 2, - "outputs": [ - { - "output_type": "stream", - "text": [ - "['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']\n", - "[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23\n", - " 24 25]\n", - " \n", - "{'A': 0, 'B': 1, 'C': 2, 'D': 3, 'E': 4, 'F': 5, 'G': 6, 'H': 7, 'I': 8, 'J': 9, 'K': 10, 'L': 11, 'M': 12, 'N': 13, 'O': 14, 'P': 15, 'Q': 16, 'R': 17, 'S': 18, 'T': 19, 'U': 20, 'V': 21, 'W': 22, 'X': 23, 'Y': 24, 'Z': 25}\n", - "\n" - ], - "name": "stdout" - } - ] - }, - { - "metadata": { - "id": "6ouDfjWab_Mc", - "colab_type": "code", - "colab": { - "base_uri": "https://localhost:8080/", - "height": 513 - }, - "outputId": "1c4b50a5-138d-4fc3-a1b8-167121590285" - }, - "cell_type": "code", - "source": [ - "series1 = pd.Series(alphabets)\n", - "print(series1)" - ], - "execution_count": 3, - "outputs": [ - { - "output_type": "stream", - "text": [ - "0 A\n", - "1 B\n", - "2 C\n", - "3 D\n", - "4 E\n", - "5 F\n", - "6 G\n", - "7 H\n", - "8 I\n", - "9 J\n", - "10 K\n", - "11 L\n", - "12 M\n", - "13 N\n", - "14 O\n", - "15 P\n", - "16 Q\n", - "17 R\n", - "18 S\n", - "19 T\n", - "20 U\n", - "21 V\n", - "22 W\n", - "23 X\n", - "24 Y\n", - "25 Z\n", - "dtype: object\n" - ], - "name": "stdout" - } - ] - }, - { - "metadata": { - "id": "At7nY7vVcBZ3", - "colab_type": "code", - "colab": { - "base_uri": "https://localhost:8080/", - "height": 513 - }, - "outputId": "4d071048-cd01-445a-8654-a26543b686df" - }, - "cell_type": "code", - "source": [ - "series2 = pd.Series(numbers)\n", - "print(series2)" - ], - "execution_count": 4, - "outputs": [ - { - "output_type": "stream", - "text": [ - "0 0\n", - "1 1\n", - "2 2\n", - "3 3\n", - "4 4\n", - "5 5\n", - "6 6\n", - "7 7\n", - "8 8\n", - "9 9\n", - "10 10\n", - "11 11\n", - "12 12\n", - "13 13\n", - "14 14\n", - "15 15\n", - "16 16\n", - "17 17\n", - "18 18\n", - "19 19\n", - "20 20\n", - "21 21\n", - "22 22\n", - "23 23\n", - "24 24\n", - "25 25\n", - "dtype: int64\n" - ], - "name": "stdout" - } - ] - }, - { - "metadata": { - "id": "J5z-2CWAdH6N", - "colab_type": "code", - "colab": { - "base_uri": "https://localhost:8080/", - "height": 513 - }, - "outputId": "b9ed4864-bf52-409e-a07a-a56eb4abee9f" - }, - "cell_type": "code", - "source": [ - "series3 = pd.Series(alpha_numbers)\n", - "print(series3)" - ], - "execution_count": 5, - "outputs": [ - { - "output_type": "stream", - "text": [ - "A 0\n", - "B 1\n", - "C 2\n", - "D 3\n", - "E 4\n", - "F 5\n", - "G 6\n", - "H 7\n", - "I 8\n", - "J 9\n", - "K 10\n", - "L 11\n", - "M 12\n", - "N 13\n", - "O 14\n", - "P 15\n", - "Q 16\n", - "R 17\n", - "S 18\n", - "T 19\n", - "U 20\n", - "V 21\n", - "W 22\n", - "X 23\n", - "Y 24\n", - "Z 25\n", - "dtype: int64\n" - ], - "name": "stdout" - } - ] - }, - { - "metadata": { - "id": "fYzblGGudKjO", - "colab_type": "code", - "colab": { - "base_uri": "https://localhost:8080/", - "height": 127 - }, - "outputId": "01d11b62-8fba-419a-8e51-f36bc07c2ba5" - }, - "cell_type": "code", - "source": [ - "#replace head() with head(n) where n can be any number between [0-25] and observe the output in deach case \n", - "series3.head(5)" - ], - "execution_count": 10, - "outputs": [ - { - "output_type": "execute_result", - "data": { - "text/plain": [ - "A 0\n", - "B 1\n", - "C 2\n", - "D 3\n", - "E 4\n", - "dtype: int64" - ] - }, - "metadata": { - "tags": [] - }, - "execution_count": 10 - } - ] - }, - { - "metadata": { - "id": "OwsJIf5feTtg", - "colab_type": "text" - }, - "cell_type": "markdown", - "source": [ - "#### Create DataFrame from lists\n", - "\n", - "[DataFrame Doc](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.html)" - ] - }, - { - "metadata": { - "id": "73UTZ07EdWki", - "colab_type": "code", - "colab": { - "base_uri": "https://localhost:8080/", - "height": 865 - }, - "outputId": "f6b26a00-e9b7-43bc-e1d2-505f2723f82f" - }, - "cell_type": "code", - "source": [ - "data = {'alphabets': alphabets, 'values': numbers}\n", - "\n", - "df = pd.DataFrame(data)\n", - "\n", - "#Lets Change the column `values` to `alpha_numbers`\n", - "\n", - "df.columns = ['alphabets', 'alpha_numbers']\n", - "\n", - "df" - ], - "execution_count": 8, - "outputs": [ - { - "output_type": "execute_result", - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
alphabetsalpha_numbers
0A0
1B1
2C2
3D3
4E4
5F5
6G6
7H7
8I8
9J9
10K10
11L11
12M12
13N13
14O14
15P15
16Q16
17R17
18S18
19T19
20U20
21V21
22W22
23X23
24Y24
25Z25
\n", - "
" - ], - "text/plain": [ - " alphabets alpha_numbers\n", - "0 A 0\n", - "1 B 1\n", - "2 C 2\n", - "3 D 3\n", - "4 E 4\n", - "5 F 5\n", - "6 G 6\n", - "7 H 7\n", - "8 I 8\n", - "9 J 9\n", - "10 K 10\n", - "11 L 11\n", - "12 M 12\n", - "13 N 13\n", - "14 O 14\n", - "15 P 15\n", - "16 Q 16\n", - "17 R 17\n", - "18 S 18\n", - "19 T 19\n", - "20 U 20\n", - "21 V 21\n", - "22 W 22\n", - "23 X 23\n", - "24 Y 24\n", - "25 Z 25" - ] - }, - "metadata": { - "tags": [] - }, - "execution_count": 8 - } - ] - }, - { - "metadata": { - "id": "uaK_1EO9etGS", - "colab_type": "code", - "colab": { - "base_uri": "https://localhost:8080/", - "height": 141 - }, - "outputId": "3766ccdc-5b8d-4b12-92db-156b1c1f0bce" - }, - "cell_type": "code", - "source": [ - "# transpose\n", - "\n", - "df.T\n", - "\n", - "# there are many more operations which we can perform look at the documentation with the subsequent exercises we will learn more" - ], - "execution_count": 9, - "outputs": [ - { - "output_type": "execute_result", - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
0123456789...16171819202122232425
alphabetsABCDEFGHIJ...QRSTUVWXYZ
alpha_numbers0123456789...16171819202122232425
\n", - "

2 rows × 26 columns

\n", - "
" - ], - "text/plain": [ - " 0 1 2 3 4 5 6 7 8 9 ... 16 17 18 19 20 21 22 \\\n", - "alphabets A B C D E F G H I J ... Q R S T U V W \n", - "alpha_numbers 0 1 2 3 4 5 6 7 8 9 ... 16 17 18 19 20 21 22 \n", - "\n", - " 23 24 25 \n", - "alphabets X Y Z \n", - "alpha_numbers 23 24 25 \n", - "\n", - "[2 rows x 26 columns]" - ] - }, - "metadata": { - "tags": [] - }, - "execution_count": 9 - } - ] - }, - { - "metadata": { - "id": "ZYonoaW8gEAJ", - "colab_type": "text" - }, - "cell_type": "markdown", - "source": [ - "#### Extract Items from a series" - ] - }, - { - "metadata": { - "id": "tc1-KX_Bfe7U", - "colab_type": "code", - "colab": { - "base_uri": "https://localhost:8080/", - "height": 206 - }, - "outputId": "6baf4b89-80fa-49b4-de26-190f1008d245" - }, - "cell_type": "code", - "source": [ - "ser = pd.Series(list('abcdefghijklmnopqrstuvwxyz'))\n", - "pos = [0, 4, 8, 14, 20]\n", - "\n", - "vowels = ser.take(pos)\n", - "\n", - "df = pd.DataFrame(vowels)#, columns=['vowels'])\n", - "\n", - "df.columns = ['vowels']\n", - "\n", - "df.index = [0, 1, 2, 3, 4]\n", - "\n", - "df" - ], - "execution_count": 15, - "outputs": [ - { - "output_type": "execute_result", - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
vowels
0a
1e
2i
3o
4u
\n", - "
" - ], - "text/plain": [ - " vowels\n", - "0 a\n", - "1 e\n", - "2 i\n", - "3 o\n", - "4 u" - ] - }, - "metadata": { - "tags": [] - }, - "execution_count": 15 - } - ] - }, - { - "metadata": { - "id": "cmDxwtDNjWpO", - "colab_type": "text" - }, - "cell_type": "markdown", - "source": [ - "#### Change the first character of each word to upper case in each word of ser" - ] - }, - { - "metadata": { - "id": "5KagP9PpgV2F", - "colab_type": "code", - "colab": { - "base_uri": "https://localhost:8080/", - "height": 35 - }, - "outputId": "69ac4989-7430-4cb8-8f5b-7fbfe73a33b9" - }, - "cell_type": "code", - "source": [ - "ser = pd.Series(['we', 'are', 'learning', 'pandas'])\n", - "\n", - "ser.map(lambda x : x.title())\n", - "\n", - "titles = [i.title() for i in ser]\n", - "\n", - "titles" - ], - "execution_count": 16, - "outputs": [ - { - "output_type": "execute_result", - "data": { - "text/plain": [ - "['We', 'Are', 'Learning', 'Pandas']" - ] - }, - "metadata": { - "tags": [] - }, - "execution_count": 16 - } - ] - }, - { - "metadata": { - "id": "qn47ee-MkZN8", - "colab_type": "text" - }, - "cell_type": "markdown", - "source": [ - "#### Reindexing" - ] - }, - { - "metadata": { - "id": "h5R0JL2NjuFS", - "colab_type": "code", - "colab": { - "base_uri": "https://localhost:8080/", - "height": 206 - }, - "outputId": "0da25db2-170f-4e2a-a545-0e21fd5c10e1" - }, - "cell_type": "code", - "source": [ - "my_index = [1, 2, 3, 4, 5]\n", - "\n", - "df1 = pd.DataFrame({'upper values': ['A', 'B', 'C', 'D', 'E'],\n", - " 'lower values': ['a', 'b', 'c', 'd', 'e']},\n", - " index = my_index)\n", - "\n", - "df1" - ], - "execution_count": 17, - "outputs": [ - { - "output_type": "execute_result", - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
lower valuesupper values
1aA
2bB
3cC
4dD
5eE
\n", - "
" - ], - "text/plain": [ - " lower values upper values\n", - "1 a A\n", - "2 b B\n", - "3 c C\n", - "4 d D\n", - "5 e E" - ] - }, - "metadata": { - "tags": [] - }, - "execution_count": 17 - } - ] - }, - { - "metadata": { - "id": "G_Frvc3mk93k", - "colab_type": "code", - "colab": { - "base_uri": "https://localhost:8080/", - "height": 206 - }, - "outputId": "30daf710-853d-43e0-d52c-f1301b9522e9" - }, - "cell_type": "code", - "source": [ - "new_index = [2, 5, 4, 3, 1]\n", - "\n", - "df1.reindex(index = new_index)" - ], - "execution_count": 18, - "outputs": [ - { - "output_type": "execute_result", - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
lower valuesupper values
2bB
5eE
4dD
3cC
1aA
\n", - "
" - ], - "text/plain": [ - " lower values upper values\n", - "2 b B\n", - "5 e E\n", - "4 d D\n", - "3 c C\n", - "1 a A" - ] - }, - "metadata": { - "tags": [] - }, - "execution_count": 18 - } - ] - } - ] -} \ No newline at end of file