diff --git a/Akpa Juliet Chisom Numpy and pandas WTF2.ipynb b/Akpa Juliet Chisom Numpy and pandas WTF2.ipynb new file mode 100644 index 0000000..58901ae --- /dev/null +++ b/Akpa Juliet Chisom Numpy and pandas WTF2.ipynb @@ -0,0 +1,2865 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 89, + "id": "07eeac9c", + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np" + ] + }, + { + "cell_type": "markdown", + "id": "ba2cc087", + "metadata": {}, + "source": [ + "### 1. Creating an array" + ] + }, + { + "cell_type": "code", + "execution_count": 90, + "id": "ad7506ca", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1 2 3 4]\n" + ] + } + ], + "source": [ + "a = np.array ([1,2,3,4])\n", + "print(a)" + ] + }, + { + "cell_type": "code", + "execution_count": 91, + "id": "52f529e8", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[3 4 5]\n", + " [6 7 8]]\n" + ] + } + ], + "source": [ + "b = np.array([[3,4,5,],[6,7,8]])\n", + "print(b)" + ] + }, + { + "cell_type": "markdown", + "id": "4152ea79", + "metadata": {}, + "source": [ + "### 2. Getting the dimensions of the array" + ] + }, + { + "cell_type": "code", + "execution_count": 92, + "id": "5b906004", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 92, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a.ndim" + ] + }, + { + "cell_type": "code", + "execution_count": 93, + "id": "28122488", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 93, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b.ndim" + ] + }, + { + "cell_type": "markdown", + "id": "8550b82d", + "metadata": {}, + "source": [ + "### 3. Get shape" + ] + }, + { + "cell_type": "code", + "execution_count": 94, + "id": "a46f0a04", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(4,)" + ] + }, + "execution_count": 94, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a.shape" + ] + }, + { + "cell_type": "code", + "execution_count": 95, + "id": "cf9a0c4f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(2, 3)" + ] + }, + "execution_count": 95, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b.shape" + ] + }, + { + "cell_type": "markdown", + "id": "baef9bed", + "metadata": {}, + "source": [ + "### 4. Getting type\n" + ] + }, + { + "cell_type": "code", + "execution_count": 97, + "id": "daca98a8", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "dtype('int32')" + ] + }, + "execution_count": 97, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a.dtype" + ] + }, + { + "cell_type": "code", + "execution_count": 98, + "id": "a2a53683", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "dtype('int32')" + ] + }, + "execution_count": 98, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b.dtype" + ] + }, + { + "cell_type": "markdown", + "id": "d2b88a95", + "metadata": {}, + "source": [ + "### 5.Get size\n" + ] + }, + { + "cell_type": "code", + "execution_count": 99, + "id": "84c24713", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 99, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a.itemsize" + ] + }, + { + "cell_type": "markdown", + "id": "7146dbfa", + "metadata": {}, + "source": [ + "### 6. Get total size\n" + ] + }, + { + "cell_type": "code", + "execution_count": 119, + "id": "06e85f57", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "16" + ] + }, + "execution_count": 119, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a.size*a.itemsize " + ] + }, + { + "cell_type": "code", + "execution_count": 120, + "id": "cfc2b78f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "24" + ] + }, + "execution_count": 120, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b.size*b.itemsize" + ] + }, + { + "cell_type": "code", + "execution_count": 121, + "id": "35d833c9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "16" + ] + }, + "execution_count": 121, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# OR\n", + "a.nbytes" + ] + }, + { + "cell_type": "code", + "execution_count": 122, + "id": "41b9b220", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "24" + ] + }, + "execution_count": 122, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\n", + "b.nbytes" + ] + }, + { + "cell_type": "markdown", + "id": "177e9baf", + "metadata": {}, + "source": [ + "### 7. arrange: Return evenly spaced values within a given interval." + ] + }, + { + "cell_type": "code", + "execution_count": 154, + "id": "472180af", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,\n", + " 17, 18, 19])" + ] + }, + "execution_count": 154, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "np.arange(0,20)" + ] + }, + { + "cell_type": "markdown", + "id": "7fab781e", + "metadata": {}, + "source": [ + "### 8. All 1s matrix\n" + ] + }, + { + "cell_type": "code", + "execution_count": 126, + "id": "9814154e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[1., 1., 1.],\n", + " [1., 1., 1.]])" + ] + }, + "execution_count": 126, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "np.ones((2,3))" + ] + }, + { + "cell_type": "markdown", + "id": "ce6cf75f", + "metadata": {}, + "source": [ + "### 9. Random Decimal number\n" + ] + }, + { + "cell_type": "code", + "execution_count": 127, + "id": "041ec266", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[0.79844965, 0.46638252],\n", + " [0.10030767, 0.7624191 ],\n", + " [0.89164678, 0.23442672],\n", + " [0.46971368, 0.52419522]])" + ] + }, + "execution_count": 127, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "np.random.rand(4,2)" + ] + }, + { + "cell_type": "markdown", + "id": "7f8cbf3f", + "metadata": {}, + "source": [ + "### 10. Random integer values\n" + ] + }, + { + "cell_type": "code", + "execution_count": 128, + "id": "3b2abe96", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[ 3, -3],\n", + " [-3, 1]])" + ] + }, + "execution_count": 128, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "np.random.randint(-3,5, size=(2,2))" + ] + }, + { + "cell_type": "markdown", + "id": "2c6e1ae4", + "metadata": {}, + "source": [ + "### 11. The identity matrix\n" + ] + }, + { + "cell_type": "code", + "execution_count": 129, + "id": "4ce176f6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[1., 0., 0., 0.],\n", + " [0., 1., 0., 0.],\n", + " [0., 0., 1., 0.],\n", + " [0., 0., 0., 1.]])" + ] + }, + "execution_count": 129, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "np.identity(4)" + ] + }, + { + "cell_type": "markdown", + "id": "19ecd6e7", + "metadata": {}, + "source": [ + "### 12. Repeating array\n" + ] + }, + { + "cell_type": "code", + "execution_count": 130, + "id": "06b69013", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[1 2 4]\n", + " [1 2 4]\n", + " [1 2 4]]\n" + ] + } + ], + "source": [ + "arr = np.array([[1,2,4]])\n", + "A1 = np.repeat(arr,3, axis = 0)\n", + "print(A1)" + ] + }, + { + "cell_type": "markdown", + "id": "5323f81d", + "metadata": {}, + "source": [ + "### 13. Copying arrays\n" + ] + }, + { + "cell_type": "code", + "execution_count": 131, + "id": "922f2c9a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([1, 2, 3])" + ] + }, + "execution_count": 131, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = np.array([1,2,3])\n", + "b = a\n", + "b" + ] + }, + { + "cell_type": "markdown", + "id": "0836c599", + "metadata": {}, + "source": [ + "### 14. Getting the maximum value" + ] + }, + { + "cell_type": "code", + "execution_count": 132, + "id": "9e3b207a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Largest value\n", + "3\n" + ] + } + ], + "source": [ + "n = a.max()\n", + "print(\"Largest value\")\n", + "print(n)" + ] + }, + { + "cell_type": "markdown", + "id": "0748c9c1", + "metadata": {}, + "source": [ + "### 15. Getting the minimum value" + ] + }, + { + "cell_type": "code", + "execution_count": 139, + "id": "f0edcb51", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "smallest value\n", + "1\n" + ] + } + ], + "source": [ + "n = a.min()\n", + "print(\"smallest value\")\n", + "print(n)" + ] + }, + { + "cell_type": "markdown", + "id": "c50ef487", + "metadata": {}, + "source": [ + "### 16. Appending arrays" + ] + }, + { + "cell_type": "code", + "execution_count": 140, + "id": "b4352a22", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Original array\n", + "[0 1 2 3 4 5 6 7]\n", + "\n", + "\n", + "Array with appended values at the end\n", + "[ 0 1 2 3 4 5 6 7 8 9 10]\n" + ] + } + ], + "source": [ + "print(\"Original array\")\n", + "numbers = np.arange(8)\n", + "print(numbers)\n", + "print(\"\\n\")\n", + "print(\"Array with appended values at the end\")\n", + "print(np.append(numbers, (8,9,10)))" + ] + }, + { + "cell_type": "code", + "execution_count": 141, + "id": "ed27bd7d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Original array\n", + "[[ 2 3 4]\n", + " [ 5 6 7]\n", + " [ 8 9 10]]\n", + "\n", + "\n", + "Arrays with appended values at the end\n", + "[[ 2 3 4]\n", + " [ 5 6 7]\n", + " [ 8 9 10]\n", + " [12 13 14]]\n" + ] + } + ], + "source": [ + "print(\"Original array\")\n", + "q = np.arange(2,11).reshape (3,3)\n", + "print(q)\n", + "print(\"\\n\")\n", + "print(\"Arrays with appended values at the end\")\n", + "print(np.append(q, [[12,13,14]], axis = 0))" + ] + }, + { + "cell_type": "markdown", + "id": "c2a3d5dc", + "metadata": {}, + "source": [ + "### 17. Printing all boarders 1s and 0s inside" + ] + }, + { + "cell_type": "code", + "execution_count": 142, + "id": "12d02b9f", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Original array\n", + "[[1. 1. 1. 1. 1. 1.]\n", + " [1. 1. 1. 1. 1. 1.]\n", + " [1. 1. 1. 1. 1. 1.]\n", + " [1. 1. 1. 1. 1. 1.]\n", + " [1. 1. 1. 1. 1. 1.]\n", + " [1. 1. 1. 1. 1. 1.]]\n", + "\n", + "\n", + "Arrays with one on the boarder and zeros inside\n", + "[[1. 1. 1. 1. 1. 1.]\n", + " [1. 0. 0. 0. 0. 1.]\n", + " [1. 0. 0. 0. 0. 1.]\n", + " [1. 0. 0. 0. 0. 1.]\n", + " [1. 0. 0. 0. 0. 1.]\n", + " [1. 1. 1. 1. 1. 1.]]\n" + ] + } + ], + "source": [ + "print(\"Original array\")\n", + "array_2d = np.ones((6,6))\n", + "print(array_2d)\n", + "print(\"\\n\")\n", + "print(\"Arrays with one on the boarder and zeros inside\")\n", + "array_2d[1:-1,1:-1] = 0\n", + "print(array_2d)" + ] + }, + { + "cell_type": "markdown", + "id": "a88b29fe", + "metadata": {}, + "source": [ + "### 18. eye: Another way of printing identity matrix" + ] + }, + { + "cell_type": "code", + "execution_count": 143, + "id": "19600f10", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([[1., 0., 0., 0., 0., 0.],\n", + " [0., 1., 0., 0., 0., 0.],\n", + " [0., 0., 1., 0., 0., 0.],\n", + " [0., 0., 0., 1., 0., 0.],\n", + " [0., 0., 0., 0., 1., 0.],\n", + " [0., 0., 0., 0., 0., 1.]])" + ] + }, + "execution_count": 143, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "np.eye(6)" + ] + }, + { + "cell_type": "markdown", + "id": "8b8dbff8", + "metadata": {}, + "source": [ + "### 19. linspace: Return evenly spaced numbers over a specified interval." + ] + }, + { + "cell_type": "code", + "execution_count": 144, + "id": "043bd1ce", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([ 0., 5., 10.])" + ] + }, + "execution_count": 144, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "np.linspace(0,10,3)" + ] + }, + { + "cell_type": "markdown", + "id": "bebae02a", + "metadata": {}, + "source": [ + "### 20. printing all zeros arrays" + ] + }, + { + "cell_type": "code", + "execution_count": 151, + "id": "b3de3a2f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([0., 0., 0.])" + ] + }, + "execution_count": 151, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "np.zeros((3))" + ] + }, + { + "cell_type": "markdown", + "id": "bb3a72a3", + "metadata": {}, + "source": [ + "# 20 FUNCTIONS IN PANDAS" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "e80da545", + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd" + ] + }, + { + "cell_type": "markdown", + "id": "b18d6183", + "metadata": {}, + "source": [ + "### 1. Creating a table from the scratch using dictionary" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "8238a201", + "metadata": {}, + "outputs": [], + "source": [ + "Table = {\"Names\": [\"Chisom\", \"Ugomsi\", \"Nneka\", \"Oge\", \"Blessing\"],\n", + " \"Age\":[25, 1, 23, 24, 22],\n", + " \"States\": [\"Enugu\", \"Enugu\", \"Anambra\", \"Ebonyi\", \"Abia\"]}" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "19e37430", + "metadata": {}, + "outputs": [], + "source": [ + "df = pd.DataFrame(Table)" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "13d61a32", + "metadata": {}, + "outputs": [ + { + "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", + "
NamesAgeStates
0Chisom25Enugu
1Ugomsi1Enugu
2Nneka23Anambra
3Oge24Ebonyi
4Blessing22Abia
\n", + "
" + ], + "text/plain": [ + " Names Age States\n", + "0 Chisom 25 Enugu\n", + "1 Ugomsi 1 Enugu\n", + "2 Nneka 23 Anambra\n", + "3 Oge 24 Ebonyi\n", + "4 Blessing 22 Abia" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df" + ] + }, + { + "cell_type": "markdown", + "id": "124e2365", + "metadata": {}, + "source": [ + "### 2. Sum: Return the sum of the values over the requested axis.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "3f928530", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "95" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df[\"Age\"].sum ()" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "8fd4bb5d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "26" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df[\"Age\"][0:2].sum()" + ] + }, + { + "cell_type": "markdown", + "id": "8e731ae9", + "metadata": {}, + "source": [ + "### 3. Mean: Return the mean of the values over the requested axis." + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "id": "1f055426", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "19.0" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df[\"Age\"].mean()" + ] + }, + { + "cell_type": "markdown", + "id": "e111b5a0", + "metadata": {}, + "source": [ + "### 4. Min: Return the minimum of the values over the requested axis.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "id": "94153215", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df[\"Age\"].min()" + ] + }, + { + "cell_type": "markdown", + "id": "43e802a2", + "metadata": {}, + "source": [ + "### 5. Max: Return the maximum of the values over the requested axis." + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "id": "3f2adada", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "25" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df[\"Age\"].max()" + ] + }, + { + "cell_type": "markdown", + "id": "ac8b98b8", + "metadata": {}, + "source": [ + "### 6. Count: Count non-NA cells for each column or row." + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "id": "ee7acc07", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "5" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df[\"Age\"].count()" + ] + }, + { + "cell_type": "markdown", + "id": "4c486c9c", + "metadata": {}, + "source": [ + "### 7. df.columns: Used to find the columns on the table" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "id": "c46389e7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Index(['Names', 'Age', 'States'], dtype='object')" + ] + }, + "execution_count": 50, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.columns" + ] + }, + { + "cell_type": "markdown", + "id": "287aeaf8", + "metadata": {}, + "source": [ + "### 8. Loc: Access a group of rows and columns by label(s) or a boolean array.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "id": "c8114a90", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Names Chisom\n", + "Age 25\n", + "States Enugu\n", + "Name: 0, dtype: object" + ] + }, + "execution_count": 55, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.loc[0]" + ] + }, + { + "cell_type": "code", + "execution_count": 67, + "id": "4416269f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0 Chisom\n", + "1 Ugomsi\n", + "2 Nneka\n", + "Name: Names, dtype: object" + ] + }, + "execution_count": 67, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.loc[0:2, \"Names\"]" + ] + }, + { + "cell_type": "markdown", + "id": "fbe1419d", + "metadata": {}, + "source": [ + "### 9. iloc: Purely integer-location based indexing for selection by position.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "id": "eeb3694b", + "metadata": {}, + "outputs": [ + { + "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", + "
NamesAgeStates
0Chisom25Enugu
1Ugomsi1Enugu
\n", + "
" + ], + "text/plain": [ + " Names Age States\n", + "0 Chisom 25 Enugu\n", + "1 Ugomsi 1 Enugu" + ] + }, + "execution_count": 69, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.iloc~[0:2]" + ] + }, + { + "cell_type": "markdown", + "id": "d039dbab", + "metadata": {}, + "source": [ + "### 10. Where: Replace values where the condition is False.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "id": "a6f3d93a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "94.0" + ] + }, + "execution_count": 61, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# method chaining (Equivalance of sumif)\n", + "df[\"Age\"].where(df[\"Age\"]>20).sum()" + ] + }, + { + "cell_type": "markdown", + "id": "45703af3", + "metadata": {}, + "source": [ + "### 11. Value_counts: Return a Series containing counts of unique rows in the DataFrame.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "id": "2519ff48", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "25.0 1\n", + "23.0 1\n", + "24.0 1\n", + "22.0 1\n", + "Name: Age, dtype: int64" + ] + }, + "execution_count": 63, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# method chain (Equivalance of countif)\n", + "df[\"Age\"].where(df[\"Age\"]>20).value_counts()" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "id": "e1384c12", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 64, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df[\"Age\"].where(df[\"Age\"]>20).value_counts().sum()" + ] + }, + { + "cell_type": "markdown", + "id": "5594d7d2", + "metadata": {}, + "source": [ + "### 12. Count: Count non-NA cells for each column or row." + ] + }, + { + "cell_type": "code", + "execution_count": 66, + "id": "8e37ff53", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 66, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df[\"Age\"].where(df[\"Age\"]>20).count()" + ] + }, + { + "cell_type": "markdown", + "id": "676a0c35", + "metadata": {}, + "source": [ + "### 13. pd.read: Read an Excel file into a pandas DataFrame." + ] + }, + { + "cell_type": "code", + "execution_count": 101, + "id": "839fe558", + "metadata": {}, + "outputs": [], + "source": [ + "df = pd.read_excel(\"Order sales pandas.xlsx\")" + ] + }, + { + "cell_type": "markdown", + "id": "fe0e8635", + "metadata": {}, + "source": [ + "### 14. head: This function returns the first `n` rows for the object based on position. It is useful for quickly testing if your object\n", + "### has the right type of data in it." + ] + }, + { + "cell_type": "code", + "execution_count": 108, + "id": "357fe0d1", + "metadata": {}, + "outputs": [ + { + "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", + "
Order QuantitySalesDiscountShip ModeProfitUnit PriceShipping CostCustomer NameProvinceRegionCustomer SegmentProduct CategoryProduct Sub-CategoryProduct NameProduct ContainerProduct Base MarginShip Date
06261.54000.04Regular Air-213.250038.9435.00Muhammed MacIntyreNunavutNunavutSmall BusinessOffice SuppliesStorage & OrganizationEldon Base for stackable storage shelf, platinumLarge Box0.802010-10-20
14910123.02000.07Delivery Truck457.8100208.1668.02Barry FrenchNunavutNunavutConsumerOffice SuppliesAppliances1.7 Cubic Foot Compact \"Cube\" Office Refrigera...Jumbo Drum0.582012-10-02
227244.57000.01Regular Air46.70758.692.99Barry FrenchNunavutNunavutConsumerOffice SuppliesBinders and Binder AccessoriesCardinal Slant-D® Ring Binder, Heavy Gauge VinylSmall Box0.392012-10-03
3304965.75950.08Regular Air1198.9710195.993.99Clay RozendalNunavutNunavutCorporateTechnologyTelephones and CommunicationR380Small Box0.582011-07-12
419394.27000.08Regular Air30.940021.785.94Carlos SolteroNunavutNunavutConsumerOffice SuppliesAppliancesHolmes HEPA Air PurifierMedium Box0.502010-08-30
\n", + "
" + ], + "text/plain": [ + " Order Quantity Sales Discount Ship Mode Profit \\\n", + "0 6 261.5400 0.04 Regular Air -213.2500 \n", + "1 49 10123.0200 0.07 Delivery Truck 457.8100 \n", + "2 27 244.5700 0.01 Regular Air 46.7075 \n", + "3 30 4965.7595 0.08 Regular Air 1198.9710 \n", + "4 19 394.2700 0.08 Regular Air 30.9400 \n", + "\n", + " Unit Price Shipping Cost Customer Name Province Region \\\n", + "0 38.94 35.00 Muhammed MacIntyre Nunavut Nunavut \n", + "1 208.16 68.02 Barry French Nunavut Nunavut \n", + "2 8.69 2.99 Barry French Nunavut Nunavut \n", + "3 195.99 3.99 Clay Rozendal Nunavut Nunavut \n", + "4 21.78 5.94 Carlos Soltero Nunavut Nunavut \n", + "\n", + " Customer Segment Product Category Product Sub-Category \\\n", + "0 Small Business Office Supplies Storage & Organization \n", + "1 Consumer Office Supplies Appliances \n", + "2 Consumer Office Supplies Binders and Binder Accessories \n", + "3 Corporate Technology Telephones and Communication \n", + "4 Consumer Office Supplies Appliances \n", + "\n", + " Product Name Product Container \\\n", + "0 Eldon Base for stackable storage shelf, platinum Large Box \n", + "1 1.7 Cubic Foot Compact \"Cube\" Office Refrigera... Jumbo Drum \n", + "2 Cardinal Slant-D® Ring Binder, Heavy Gauge Vinyl Small Box \n", + "3 R380 Small Box \n", + "4 Holmes HEPA Air Purifier Medium Box \n", + "\n", + " Product Base Margin Ship Date \n", + "0 0.80 2010-10-20 \n", + "1 0.58 2012-10-02 \n", + "2 0.39 2012-10-03 \n", + "3 0.58 2011-07-12 \n", + "4 0.50 2010-08-30 " + ] + }, + "execution_count": 108, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.head()" + ] + }, + { + "cell_type": "markdown", + "id": "081be31d", + "metadata": {}, + "source": [ + "### 15. info: Print a concise summary of a DataFrame." + ] + }, + { + "cell_type": "code", + "execution_count": 105, + "id": "6beb9c60", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "RangeIndex: 8399 entries, 0 to 8398\n", + "Data columns (total 17 columns):\n", + " # Column Non-Null Count Dtype \n", + "--- ------ -------------- ----- \n", + " 0 Order Quantity 8399 non-null int64 \n", + " 1 Sales 8399 non-null float64 \n", + " 2 Discount 8399 non-null float64 \n", + " 3 Ship Mode 8399 non-null object \n", + " 4 Profit 8399 non-null float64 \n", + " 5 Unit Price 8399 non-null float64 \n", + " 6 Shipping Cost 8399 non-null float64 \n", + " 7 Customer Name 8399 non-null object \n", + " 8 Province 8399 non-null object \n", + " 9 Region 8399 non-null object \n", + " 10 Customer Segment 8399 non-null object \n", + " 11 Product Category 8399 non-null object \n", + " 12 Product Sub-Category 8399 non-null object \n", + " 13 Product Name 8399 non-null object \n", + " 14 Product Container 8399 non-null object \n", + " 15 Product Base Margin 8336 non-null float64 \n", + " 16 Ship Date 8399 non-null datetime64[ns]\n", + "dtypes: datetime64[ns](1), float64(6), int64(1), object(9)\n", + "memory usage: 1.1+ MB\n" + ] + } + ], + "source": [ + "df.info()" + ] + }, + { + "cell_type": "markdown", + "id": "1bf50863", + "metadata": {}, + "source": [ + "### 16. Shape: Return a tuple representing the dimensionality of the DataFrame." + ] + }, + { + "cell_type": "code", + "execution_count": 114, + "id": "3ef2fa36", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(8399, 17)" + ] + }, + "execution_count": 114, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.shape" + ] + }, + { + "cell_type": "markdown", + "id": "c52a06d6", + "metadata": {}, + "source": [ + "### 17. Size: Return an int representing the number of elements in this object." + ] + }, + { + "cell_type": "code", + "execution_count": 115, + "id": "704c557f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "142783" + ] + }, + "execution_count": 115, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.size" + ] + }, + { + "cell_type": "markdown", + "id": "b12d6c54", + "metadata": {}, + "source": [ + "### 18. Sample: Return a random sample of items from an axis of object." + ] + }, + { + "cell_type": "code", + "execution_count": 116, + "id": "445c4582", + "metadata": {}, + "outputs": [ + { + "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", + "
Order QuantitySalesDiscountShip ModeProfitUnit PriceShipping CostCustomer NameProvinceRegionCustomer SegmentProduct CategoryProduct Sub-CategoryProduct NameProduct ContainerProduct Base MarginShip Date
57067189.73000.01Regular Air43.171524.952.99Jennifer JacksonSaskachewanPrarieHome OfficeOffice SuppliesBinders and Binder AccessoriesLarge Capacity Hanging Post BindersSmall Box0.392011-05-21
177213728.02500.04Regular Air19.998065.992.50Duane BenoitOntarioOntarioHome OfficeTechnologyTelephones and Communication6000Small Box0.552012-03-27
241150196.39000.07Regular Air82.60004.130.50George AshbrookOntarioOntarioConsumerOffice SuppliesLabelsAvery 506Small Box0.392011-02-18
7964361921.12750.08Regular Air248.580065.998.99Claire GoodAlbertaWestHome OfficeTechnologyTelephones and CommunicationTalkabout T8367Small Box0.562012-02-29
4329471291.35000.04Regular Air479.620026.385.86Odella NelsonOntarioOntarioSmall BusinessOffice SuppliesPaperXerox 1935Small Box0.392010-07-27
309930257.42000.01Regular Air59.18008.012.87Sanjit JacobsQuebecQuebecConsumerOffice SuppliesPaperTOPS Money Receipt Book, Consecutively Numbere...Wrap Bag0.402009-01-18
2199781.58000.04Regular Air-7.780010.983.37Edward NazzalOntarioOntarioHome OfficeOffice SuppliesScissors, Rulers and TrimmersFiskars® Softgrip ScissorsSmall Pack0.572012-03-27
2143281642.05000.03Regular Air829.730055.984.86Linda CazamiasOntarioOntarioCorporateOffice SuppliesPaperXerox 1908Small Box0.362009-09-20
1059172285.12000.08Delivery Truck-455.8000140.9836.09Khloe MillerBritish ColumbiaWestHome OfficeFurnitureBookcasesSauder Forest Hills Library, Woodland Oak FinishJumbo Box0.772010-12-27
6147196991.65000.08Delivery Truck906.8000399.9812.06Andy GerbodeSaskachewanPrarieConsumerTechnologyOffice MachinesOkidata ML320 Series Turbo Dot Matrix PrintersJumbo Box0.562009-01-18
\n", + "
" + ], + "text/plain": [ + " Order Quantity Sales Discount Ship Mode Profit \\\n", + "5706 7 189.7300 0.01 Regular Air 43.1715 \n", + "1772 13 728.0250 0.04 Regular Air 19.9980 \n", + "2411 50 196.3900 0.07 Regular Air 82.6000 \n", + "7964 36 1921.1275 0.08 Regular Air 248.5800 \n", + "4329 47 1291.3500 0.04 Regular Air 479.6200 \n", + "3099 30 257.4200 0.01 Regular Air 59.1800 \n", + "2199 7 81.5800 0.04 Regular Air -7.7800 \n", + "2143 28 1642.0500 0.03 Regular Air 829.7300 \n", + "1059 17 2285.1200 0.08 Delivery Truck -455.8000 \n", + "6147 19 6991.6500 0.08 Delivery Truck 906.8000 \n", + "\n", + " Unit Price Shipping Cost Customer Name Province Region \\\n", + "5706 24.95 2.99 Jennifer Jackson Saskachewan Prarie \n", + "1772 65.99 2.50 Duane Benoit Ontario Ontario \n", + "2411 4.13 0.50 George Ashbrook Ontario Ontario \n", + "7964 65.99 8.99 Claire Good Alberta West \n", + "4329 26.38 5.86 Odella Nelson Ontario Ontario \n", + "3099 8.01 2.87 Sanjit Jacobs Quebec Quebec \n", + "2199 10.98 3.37 Edward Nazzal Ontario Ontario \n", + "2143 55.98 4.86 Linda Cazamias Ontario Ontario \n", + "1059 140.98 36.09 Khloe Miller British Columbia West \n", + "6147 399.98 12.06 Andy Gerbode Saskachewan Prarie \n", + "\n", + " Customer Segment Product Category Product Sub-Category \\\n", + "5706 Home Office Office Supplies Binders and Binder Accessories \n", + "1772 Home Office Technology Telephones and Communication \n", + "2411 Consumer Office Supplies Labels \n", + "7964 Home Office Technology Telephones and Communication \n", + "4329 Small Business Office Supplies Paper \n", + "3099 Consumer Office Supplies Paper \n", + "2199 Home Office Office Supplies Scissors, Rulers and Trimmers \n", + "2143 Corporate Office Supplies Paper \n", + "1059 Home Office Furniture Bookcases \n", + "6147 Consumer Technology Office Machines \n", + "\n", + " Product Name Product Container \\\n", + "5706 Large Capacity Hanging Post Binders Small Box \n", + "1772 6000 Small Box \n", + "2411 Avery 506 Small Box \n", + "7964 Talkabout T8367 Small Box \n", + "4329 Xerox 1935 Small Box \n", + "3099 TOPS Money Receipt Book, Consecutively Numbere... Wrap Bag \n", + "2199 Fiskars® Softgrip Scissors Small Pack \n", + "2143 Xerox 1908 Small Box \n", + "1059 Sauder Forest Hills Library, Woodland Oak Finish Jumbo Box \n", + "6147 Okidata ML320 Series Turbo Dot Matrix Printers Jumbo Box \n", + "\n", + " Product Base Margin Ship Date \n", + "5706 0.39 2011-05-21 \n", + "1772 0.55 2012-03-27 \n", + "2411 0.39 2011-02-18 \n", + "7964 0.56 2012-02-29 \n", + "4329 0.39 2010-07-27 \n", + "3099 0.40 2009-01-18 \n", + "2199 0.57 2012-03-27 \n", + "2143 0.36 2009-09-20 \n", + "1059 0.77 2010-12-27 \n", + "6147 0.56 2009-01-18 " + ] + }, + "execution_count": 116, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.sample(n=10)" + ] + }, + { + "cell_type": "markdown", + "id": "1a7ca353", + "metadata": {}, + "source": [ + "### 19. Describe: Generate descriptive statistics.Descriptive statistics include those that summarize the central\n", + "### tendency, dispersion and shape of a\n", + "### dataset's distribution, excluding ``NaN`` values." + ] + }, + { + "cell_type": "code", + "execution_count": 117, + "id": "1100a487", + "metadata": {}, + "outputs": [ + { + "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", + "
Order QuantitySalesDiscountProfitUnit PriceShipping CostProduct Base Margin
count8399.0000008399.0000008399.0000008399.0000008399.0000008399.0000008336.000000
mean25.5717351775.8781790.049671181.18442289.34625912.8385570.512513
std14.4810713585.0505250.0318231196.653326290.35438317.2640520.135589
min1.0000002.2400000.000000-14140.7016000.9900000.4900000.350000
25%13.000000143.1950000.020000-83.3150006.4800003.3000000.380000
50%26.000000449.4200000.050000-1.50000020.9900006.0700000.520000
75%38.0000001709.3200000.080000162.74800085.99000013.9900000.590000
max50.00000089061.0500000.25000027220.6900006783.020000164.7300000.850000
\n", + "
" + ], + "text/plain": [ + " Order Quantity Sales Discount Profit Unit Price \\\n", + "count 8399.000000 8399.000000 8399.000000 8399.000000 8399.000000 \n", + "mean 25.571735 1775.878179 0.049671 181.184422 89.346259 \n", + "std 14.481071 3585.050525 0.031823 1196.653326 290.354383 \n", + "min 1.000000 2.240000 0.000000 -14140.701600 0.990000 \n", + "25% 13.000000 143.195000 0.020000 -83.315000 6.480000 \n", + "50% 26.000000 449.420000 0.050000 -1.500000 20.990000 \n", + "75% 38.000000 1709.320000 0.080000 162.748000 85.990000 \n", + "max 50.000000 89061.050000 0.250000 27220.690000 6783.020000 \n", + "\n", + " Shipping Cost Product Base Margin \n", + "count 8399.000000 8336.000000 \n", + "mean 12.838557 0.512513 \n", + "std 17.264052 0.135589 \n", + "min 0.490000 0.350000 \n", + "25% 3.300000 0.380000 \n", + "50% 6.070000 0.520000 \n", + "75% 13.990000 0.590000 \n", + "max 164.730000 0.850000 " + ] + }, + "execution_count": 117, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.describe()" + ] + }, + { + "cell_type": "code", + "execution_count": 155, + "id": "086f1b9f", + "metadata": {}, + "outputs": [ + { + "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", + "
countmeanstdmin25%50%75%max
Order Quantity8399.025.57173514.4810711.000013.00026.0038.00050.00
Sales8399.01775.8781793585.0505252.2400143.195449.421709.32089061.05
Discount8399.00.0496710.0318230.00000.0200.050.0800.25
Profit8399.0181.1844221196.653326-14140.7016-83.315-1.50162.74827220.69
Unit Price8399.089.346259290.3543830.99006.48020.9985.9906783.02
Shipping Cost8399.012.83855717.2640520.49003.3006.0713.990164.73
Product Base Margin8336.00.5125130.1355890.35000.3800.520.5900.85
\n", + "
" + ], + "text/plain": [ + " count mean std min 25% \\\n", + "Order Quantity 8399.0 25.571735 14.481071 1.0000 13.000 \n", + "Sales 8399.0 1775.878179 3585.050525 2.2400 143.195 \n", + "Discount 8399.0 0.049671 0.031823 0.0000 0.020 \n", + "Profit 8399.0 181.184422 1196.653326 -14140.7016 -83.315 \n", + "Unit Price 8399.0 89.346259 290.354383 0.9900 6.480 \n", + "Shipping Cost 8399.0 12.838557 17.264052 0.4900 3.300 \n", + "Product Base Margin 8336.0 0.512513 0.135589 0.3500 0.380 \n", + "\n", + " 50% 75% max \n", + "Order Quantity 26.00 38.000 50.00 \n", + "Sales 449.42 1709.320 89061.05 \n", + "Discount 0.05 0.080 0.25 \n", + "Profit -1.50 162.748 27220.69 \n", + "Unit Price 20.99 85.990 6783.02 \n", + "Shipping Cost 6.07 13.990 164.73 \n", + "Product Base Margin 0.52 0.590 0.85 " + ] + }, + "execution_count": 155, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# For Transposing\n", + "df.describe().T" + ] + }, + { + "cell_type": "markdown", + "id": "3f2ae6d9", + "metadata": {}, + "source": [ + "### 20. nunique: Count number of distinct elements in specified axis." + ] + }, + { + "cell_type": "code", + "execution_count": 159, + "id": "704e9281", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Order Quantity 50\n", + "Sales 8153\n", + "Discount 16\n", + "Ship Mode 3\n", + "Profit 7986\n", + "Unit Price 751\n", + "Shipping Cost 652\n", + "Customer Name 795\n", + "Province 13\n", + "Region 8\n", + "Customer Segment 4\n", + "Product Category 3\n", + "Product Sub-Category 17\n", + "Product Name 1263\n", + "Product Container 7\n", + "Product Base Margin 51\n", + "Ship Date 1450\n", + "dtype: int64" + ] + }, + "execution_count": 159, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.nunique()" + ] + }, + { + "cell_type": "markdown", + "id": "d5e4c056", + "metadata": {}, + "source": [ + "### 21.df.isna().any(): Detect missing values." + ] + }, + { + "cell_type": "code", + "execution_count": 161, + "id": "e8a49032", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Order Quantity False\n", + "Sales False\n", + "Discount False\n", + "Ship Mode False\n", + "Profit False\n", + "Unit Price False\n", + "Shipping Cost False\n", + "Customer Name False\n", + "Province False\n", + "Region False\n", + "Customer Segment False\n", + "Product Category False\n", + "Product Sub-Category False\n", + "Product Name False\n", + "Product Container False\n", + "Product Base Margin True\n", + "Ship Date False\n", + "dtype: bool" + ] + }, + "execution_count": 161, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.isna().any()" + ] + }, + { + "cell_type": "markdown", + "id": "d17b852a", + "metadata": {}, + "source": [ + "### 22. isnull: Detect missing values." + ] + }, + { + "cell_type": "code", + "execution_count": 163, + "id": "48b2a0ca", + "metadata": {}, + "outputs": [ + { + "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", + "
Order QuantitySalesDiscountShip ModeProfitUnit PriceShipping CostCustomer NameProvinceRegionCustomer SegmentProduct CategoryProduct Sub-CategoryProduct NameProduct ContainerProduct Base MarginShip Date
0FalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalse
1FalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalse
2FalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalse
3FalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalse
4FalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalse
......................................................
8394FalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalse
8395FalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalse
8396FalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalse
8397FalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalse
8398FalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalse
\n", + "

8399 rows × 17 columns

\n", + "
" + ], + "text/plain": [ + " Order Quantity Sales Discount Ship Mode Profit Unit Price \\\n", + "0 False False False False False False \n", + "1 False False False False False False \n", + "2 False False False False False False \n", + "3 False False False False False False \n", + "4 False False False False False False \n", + "... ... ... ... ... ... ... \n", + "8394 False False False False False False \n", + "8395 False False False False False False \n", + "8396 False False False False False False \n", + "8397 False False False False False False \n", + "8398 False False False False False False \n", + "\n", + " Shipping Cost Customer Name Province Region Customer Segment \\\n", + "0 False False False False False \n", + "1 False False False False False \n", + "2 False False False False False \n", + "3 False False False False False \n", + "4 False False False False False \n", + "... ... ... ... ... ... \n", + "8394 False False False False False \n", + "8395 False False False False False \n", + "8396 False False False False False \n", + "8397 False False False False False \n", + "8398 False False False False False \n", + "\n", + " Product Category Product Sub-Category Product Name Product Container \\\n", + "0 False False False False \n", + "1 False False False False \n", + "2 False False False False \n", + "3 False False False False \n", + "4 False False False False \n", + "... ... ... ... ... \n", + "8394 False False False False \n", + "8395 False False False False \n", + "8396 False False False False \n", + "8397 False False False False \n", + "8398 False False False False \n", + "\n", + " Product Base Margin Ship Date \n", + "0 False False \n", + "1 False False \n", + "2 False False \n", + "3 False False \n", + "4 False False \n", + "... ... ... \n", + "8394 False False \n", + "8395 False False \n", + "8396 False False \n", + "8397 False False \n", + "8398 False False \n", + "\n", + "[8399 rows x 17 columns]" + ] + }, + "execution_count": 163, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.isnull()" + ] + }, + { + "cell_type": "markdown", + "id": "bfb7781d", + "metadata": {}, + "source": [ + "### 23. columns: Immutable sequence used for indexing and alignment. The basic object storing axis labels for all ### pandas objects." + ] + }, + { + "cell_type": "code", + "execution_count": 164, + "id": "084fe30d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Index(['Order Quantity', 'Sales', 'Discount', 'Ship Mode', 'Profit',\n", + " 'Unit Price', 'Shipping Cost', 'Customer Name', 'Province', 'Region',\n", + " 'Customer Segment', 'Product Category', 'Product Sub-Category',\n", + " 'Product Name', 'Product Container', 'Product Base Margin',\n", + " 'Ship Date'],\n", + " dtype='object')" + ] + }, + "execution_count": 164, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.columns" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "016c99d7", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d041169e", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.9.7" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/Akpa Juliet Chisom WTF1.ipynb b/Akpa Juliet Chisom WTF1.ipynb new file mode 100644 index 0000000..4aaa70b --- /dev/null +++ b/Akpa Juliet Chisom WTF1.ipynb @@ -0,0 +1,360 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "60ea9d76", + "metadata": {}, + "source": [ + "### 1)Print all elements of a list using for loop." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "01538e9e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n", + "4\n", + "5\n", + "7\n", + "8\n", + "9\n", + "10\n" + ] + } + ], + "source": [ + "listx = [2,4,5,7,8,9,10]\n", + "for x in listx:\n", + " print(x)" + ] + }, + { + "cell_type": "markdown", + "id": "df211034", + "metadata": {}, + "source": [ + "# 2)Using range(1,101), make two list, one containing all even numbers andother containing all odd numbers." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "63991d9d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "even number [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100]\n", + "odd number [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99]\n" + ] + } + ], + "source": [ + "numbers = range (1,101)\n", + "even_no = []\n", + "odd_no = []\n", + "for i in numbers:\n", + " if i % 2 == 0:\n", + " even_no. append(i)\n", + " else:\n", + " odd_no.append(i)\n", + "print(\"even number\", even_no)\n", + "print(\"odd number\", odd_no)" + ] + }, + { + "cell_type": "markdown", + "id": "b0622138", + "metadata": {}, + "source": [ + "### 3)A company decided to give bonus of 5% to employee if his/her year of service is more than 5years. Ask user for their salary and year of service and print the net bonus amount. " + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "e100a6f1", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "salary30000\n", + "year of service5\n", + "1500.0\n" + ] + } + ], + "source": [ + "salary = int(input(\"salary\"))\n", + "year = int(input('year of service'))\n", + "if year == 5:\n", + " print(salary * 0.05)\n", + "else:\n", + " print(\"not eligible\")\n", + " \n" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "e411d4f6", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "salary50000\n", + "year of service5\n", + "2500.0\n" + ] + } + ], + "source": [ + "salary = int(input(\"salary\"))\n", + "year = int(input('year of service'))\n", + "if year == 5:\n", + " print(salary * 0.05)\n", + "else:\n", + " print(\"not eligible\")" + ] + }, + { + "cell_type": "markdown", + "id": "91800f7a", + "metadata": {}, + "source": [ + "### 4)Take input of age of 3 people by user and determine oldest and youngest among them. " + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "d2a0d0fc", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "enter your age 20\n", + "enter your age 25\n", + "enter your age 1\n", + "\n", + "\n", + "oldest among them is 25\n", + "youngest among them is 1\n" + ] + } + ], + "source": [ + "person1 = int(input(\"enter your age \"))\n", + "person2 = int(input(\"enter your age \"))\n", + "person3 = int(input(\"enter your age \"))\n", + "list = [person1, person2, person3]\n", + "print(\"\\n\")\n", + "print(\"oldest among them is \", max(list))\n", + "print(\"youngest among them is \", min(list))" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "b927c7ae", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Oldest among them is 25\n", + "Youngest among them is 1\n" + ] + } + ], + "source": [ + "Age = {\"Chisom\": 25, \"Jennifer\": 20, \"Ugomsi\": 1}\n", + "Oldest = print(\"Oldest among them is\", max(Age.values()))\n", + "Youngest = print(\"Youngest among them is\", min(Age.values()))\n" + ] + }, + { + "cell_type": "markdown", + "id": "9abbf98e", + "metadata": {}, + "source": [ + "A school has following rules for grading system:\n", + "a. Below 25 - F\n", + "b. 25 to 45 - E\n", + "c. 45 to 50 - D\n", + "d. 50 to 60 - C\n", + "e. 60 to 80 - B\n", + "f. Above 80 - A\n", + "5) Ask user to enter marks and print the corresponding grade" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "8e8b5b73", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "45\n", + "E\n" + ] + } + ], + "source": [ + "grades = int(input())\n", + "if grades < 25:\n", + " print(\"F\")\n", + "elif grades > 25 and grades <=45:\n", + " print(\"E\")\n", + "elif grades > 45 and grades <= 50:\n", + " print(\"D\")\n", + "elif grades > 50 and grades <= 60:\n", + " print(\"C\")\n", + "elif grades > 60 and grades <= 80:\n", + " print(\"B\")\n", + "elif grades > 80:\n", + " print(\"A\")" + ] + }, + { + "cell_type": "markdown", + "id": "0702b273", + "metadata": {}, + "source": [ + "### 6)Write a Python script to merge two Python dictionaries " + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "618c88cc", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'Chisom': 25, 'Jennifer': 20, 'Ugomsi': 1, 'Nneka': 24, 'Oge': 23}\n" + ] + } + ], + "source": [ + "age1 = {\"Chisom\": 25, \"Jennifer\": 20, \"Ugomsi\": 1}\n", + "age2 = {\"Nneka\": 24, \"Oge\": 23}\n", + "Age = age1.copy()\n", + "age1.update(age2)\n", + "print(age1)" + ] + }, + { + "cell_type": "markdown", + "id": "e3eedebb", + "metadata": {}, + "source": [ + "### 7)Write a Python program to remove a key from a dictionary." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "e76157f0", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'Chisom': 25, 'Jennifer': 20, 'Ugomsi': 1, 'Nneka': 24, 'Oge': 23}\n", + "{'Jennifer': 20, 'Ugomsi': 1, 'Nneka': 24, 'Oge': 23}\n" + ] + } + ], + "source": [ + "age = {'Chisom': 25, 'Jennifer': 20, 'Ugomsi': 1, 'Nneka': 24, 'Oge': 23}\n", + "print(age)\n", + "if \"Chisom\" in age:\n", + " del age [\"Chisom\"]\n", + "print(age)" + ] + }, + { + "cell_type": "markdown", + "id": "b036f74e", + "metadata": {}, + "source": [ + "### 8)Write a Python program to get the largest numberfrom a list" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "596f0ec3", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "70\n" + ] + } + ], + "source": [ + "def largest_no(list):\n", + " max = list[0]\n", + " for x in list:\n", + " if x > max:\n", + " max = x\n", + " return max\n", + "print(largest_no ([20,30,40,50,60,70]))\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "aedcd7c1", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.9.7" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}