|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 8, |
| 6 | + "id": "1943560c", |
| 7 | + "metadata": {}, |
| 8 | + "outputs": [ |
| 9 | + { |
| 10 | + "name": "stdout", |
| 11 | + "output_type": "stream", |
| 12 | + "text": [ |
| 13 | + "[['a' 'b']\n", |
| 14 | + " ['d' 'e']\n", |
| 15 | + " ['g' 'h']]\n" |
| 16 | + ] |
| 17 | + } |
| 18 | + ], |
| 19 | + "source": [ |
| 20 | + "import numpy as np\n", |
| 21 | + "A = np.array([\n", |
| 22 | + " ['a', 'b', 'c'],\n", |
| 23 | + " ['d', 'e', 'f'],\n", |
| 24 | + " ['g', 'h', 'i']\n", |
| 25 | + "])\n", |
| 26 | + "\n", |
| 27 | + "print(A[:, : 2])\n", |
| 28 | + "# because (rows and columns )\n" |
| 29 | + ] |
| 30 | + }, |
| 31 | + { |
| 32 | + "cell_type": "code", |
| 33 | + "execution_count": 12, |
| 34 | + "id": "bb3f9279", |
| 35 | + "metadata": {}, |
| 36 | + "outputs": [ |
| 37 | + { |
| 38 | + "data": { |
| 39 | + "text/plain": [ |
| 40 | + "array([20, 21, 22, 23, 24])" |
| 41 | + ] |
| 42 | + }, |
| 43 | + "execution_count": 12, |
| 44 | + "metadata": {}, |
| 45 | + "output_type": "execute_result" |
| 46 | + } |
| 47 | + ], |
| 48 | + "source": [ |
| 49 | + "a = np.arange(5)\n", |
| 50 | + "a + 20\n", |
| 51 | + "# it will be added with the every index of array" |
| 52 | + ] |
| 53 | + }, |
| 54 | + { |
| 55 | + "cell_type": "code", |
| 56 | + "execution_count": 14, |
| 57 | + "id": "b2b7604f", |
| 58 | + "metadata": {}, |
| 59 | + "outputs": [ |
| 60 | + { |
| 61 | + "name": "stdout", |
| 62 | + "output_type": "stream", |
| 63 | + "text": [ |
| 64 | + "[ True True True True False]\n" |
| 65 | + ] |
| 66 | + } |
| 67 | + ], |
| 68 | + "source": [ |
| 69 | + "a = np.arange(5)\n", |
| 70 | + "\n", |
| 71 | + "print(a <= 3)" |
| 72 | + ] |
| 73 | + }, |
| 74 | + { |
| 75 | + "cell_type": "code", |
| 76 | + "execution_count": 16, |
| 77 | + "id": "030a325a", |
| 78 | + "metadata": {}, |
| 79 | + "outputs": [ |
| 80 | + { |
| 81 | + "name": "stdout", |
| 82 | + "output_type": "stream", |
| 83 | + "text": [ |
| 84 | + "Tom 8\n", |
| 85 | + "Kris 2\n", |
| 86 | + "Ahmad 5\n", |
| 87 | + "Beau 6\n", |
| 88 | + "dtype: int64\n" |
| 89 | + ] |
| 90 | + } |
| 91 | + ], |
| 92 | + "source": [ |
| 93 | + "import pandas as pd\n", |
| 94 | + "\n", |
| 95 | + "certificates_earned = pd.Series(\n", |
| 96 | + " [8, 2, 5, 6],\n", |
| 97 | + " index=['Tom', 'Kris', 'Ahmad', 'Beau']\n", |
| 98 | + ")\n", |
| 99 | + "\n", |
| 100 | + "print(certificates_earned)" |
| 101 | + ] |
| 102 | + }, |
| 103 | + { |
| 104 | + "cell_type": "code", |
| 105 | + "execution_count": 18, |
| 106 | + "id": "a489afa1", |
| 107 | + "metadata": {}, |
| 108 | + "outputs": [ |
| 109 | + { |
| 110 | + "name": "stdout", |
| 111 | + "output_type": "stream", |
| 112 | + "text": [ |
| 113 | + "Tom 8\n", |
| 114 | + "Beau 6\n", |
| 115 | + "dtype: int64\n" |
| 116 | + ] |
| 117 | + } |
| 118 | + ], |
| 119 | + "source": [ |
| 120 | + "import pandas as pd\n", |
| 121 | + "\n", |
| 122 | + "certificates_earned = pd.Series(\n", |
| 123 | + " [8, 2, 5, 6],\n", |
| 124 | + " index=['Tom', 'Kris', 'Ahmad', 'Beau']\n", |
| 125 | + ")\n", |
| 126 | + "\n", |
| 127 | + "print(certificates_earned[certificates_earned > 5])" |
| 128 | + ] |
| 129 | + }, |
| 130 | + { |
| 131 | + "cell_type": "code", |
| 132 | + "execution_count": 20, |
| 133 | + "id": "887f672a", |
| 134 | + "metadata": {}, |
| 135 | + "outputs": [ |
| 136 | + { |
| 137 | + "name": "stdout", |
| 138 | + "output_type": "stream", |
| 139 | + "text": [ |
| 140 | + "Certificates 5\n", |
| 141 | + "Time (in months) 9\n", |
| 142 | + "Name: Ahmad, dtype: int64\n" |
| 143 | + ] |
| 144 | + } |
| 145 | + ], |
| 146 | + "source": [ |
| 147 | + "import pandas as pd\n", |
| 148 | + "\n", |
| 149 | + "certificates_earned = pd.DataFrame({\n", |
| 150 | + " 'Certificates': [8, 2, 5, 6],\n", |
| 151 | + " 'Time (in months)': [16, 5, 9, 12]\n", |
| 152 | + "})\n", |
| 153 | + "\n", |
| 154 | + "certificates_earned.index = ['Tom', 'Kris', 'Ahmad', 'Beau']\n", |
| 155 | + "\n", |
| 156 | + "print(certificates_earned.iloc[2])" |
| 157 | + ] |
| 158 | + }, |
| 159 | + { |
| 160 | + "cell_type": "code", |
| 161 | + "execution_count": 29, |
| 162 | + "id": "decbcb66", |
| 163 | + "metadata": {}, |
| 164 | + "outputs": [], |
| 165 | + "source": [ |
| 166 | + "ss = pd.Series(5)" |
| 167 | + ] |
| 168 | + }, |
| 169 | + { |
| 170 | + "cell_type": "code", |
| 171 | + "execution_count": 31, |
| 172 | + "id": "720ba625", |
| 173 | + "metadata": {}, |
| 174 | + "outputs": [ |
| 175 | + { |
| 176 | + "name": "stdout", |
| 177 | + "output_type": "stream", |
| 178 | + "text": [ |
| 179 | + " Certificates Time (in months) Longest streak\n", |
| 180 | + "Tom 8 16 13\n", |
| 181 | + "Kris 2 5 11\n", |
| 182 | + "Ahmad 5 9 9\n", |
| 183 | + "Beau 6 12 7\n" |
| 184 | + ] |
| 185 | + } |
| 186 | + ], |
| 187 | + "source": [ |
| 188 | + "import pandas as pd\n", |
| 189 | + "\n", |
| 190 | + "certificates_earned = pd.DataFrame({\n", |
| 191 | + " 'Certificates': [8, 2, 5, 6],\n", |
| 192 | + " 'Time (in months)': [16, 5, 9, 12]\n", |
| 193 | + "})\n", |
| 194 | + "names = ['Tom', 'Kris', 'Ahmad', 'Beau']\n", |
| 195 | + "\n", |
| 196 | + "certificates_earned.index = names\n", |
| 197 | + "longest_streak = pd.Series([13, 11, 9, 7], index=names)\n", |
| 198 | + "certificates_earned['Longest streak'] = longest_streak\n", |
| 199 | + "\n", |
| 200 | + "print(certificates_earned)" |
| 201 | + ] |
| 202 | + }, |
| 203 | + { |
| 204 | + "cell_type": "code", |
| 205 | + "execution_count": 33, |
| 206 | + "id": "f0e3a2cd", |
| 207 | + "metadata": {}, |
| 208 | + "outputs": [ |
| 209 | + { |
| 210 | + "name": "stdout", |
| 211 | + "output_type": "stream", |
| 212 | + "text": [ |
| 213 | + "3\n" |
| 214 | + ] |
| 215 | + } |
| 216 | + ], |
| 217 | + "source": [ |
| 218 | + "import pandas as pd\n", |
| 219 | + "import numpy as np\n", |
| 220 | + "\n", |
| 221 | + "s = pd.Series(['a', 3, np.nan, 1, np.nan])\n", |
| 222 | + "\n", |
| 223 | + "print(s.notnull().sum())" |
| 224 | + ] |
| 225 | + }, |
| 226 | + { |
| 227 | + "cell_type": "code", |
| 228 | + "execution_count": 35, |
| 229 | + "id": "9b31141e", |
| 230 | + "metadata": {}, |
| 231 | + "outputs": [ |
| 232 | + { |
| 233 | + "name": "stdout", |
| 234 | + "output_type": "stream", |
| 235 | + "text": [ |
| 236 | + "0 NaN\n", |
| 237 | + "1 1.0\n", |
| 238 | + "2 2.0\n", |
| 239 | + "3 2.0\n", |
| 240 | + "4 3.0\n", |
| 241 | + "dtype: float64\n" |
| 242 | + ] |
| 243 | + } |
| 244 | + ], |
| 245 | + "source": [ |
| 246 | + "import pandas as pd\n", |
| 247 | + "import numpy as np\n", |
| 248 | + "\n", |
| 249 | + "s = pd.Series([np.nan, 1, 2, np.nan, 3])\n", |
| 250 | + "s = s.fillna(method='ffill')\n", |
| 251 | + "\n", |
| 252 | + "print(s)" |
| 253 | + ] |
| 254 | + }, |
| 255 | + { |
| 256 | + "cell_type": "code", |
| 257 | + "execution_count": 36, |
| 258 | + "id": "2b22ee29", |
| 259 | + "metadata": {}, |
| 260 | + "outputs": [ |
| 261 | + { |
| 262 | + "ename": "NameError", |
| 263 | + "evalue": "name '__A__' is not defined", |
| 264 | + "output_type": "error", |
| 265 | + "traceback": [ |
| 266 | + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", |
| 267 | + "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", |
| 268 | + "Cell \u001b[1;32mIn [36], line 3\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mcsv\u001b[39;00m\n\u001b[1;32m----> 3\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28mopen\u001b[39m(\u001b[43m__A__\u001b[49m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mr\u001b[39m\u001b[38;5;124m'\u001b[39m) \u001b[38;5;28;01mas\u001b[39;00m fp:\n\u001b[0;32m 4\u001b[0m reader \u001b[38;5;241m=\u001b[39m csv\u001b[38;5;241m.\u001b[39mreader(fp, delimiter\u001b[38;5;241m=\u001b[39m__B__)\n\u001b[0;32m 5\u001b[0m \u001b[38;5;28mnext\u001b[39m(reader)\n", |
| 269 | + "\u001b[1;31mNameError\u001b[0m: name '__A__' is not defined" |
| 270 | + ] |
| 271 | + } |
| 272 | + ], |
| 273 | + "source": [ |
| 274 | + "import csv\n", |
| 275 | + "\n", |
| 276 | + "with open(__A__, 'r') as fp:\n", |
| 277 | + " reader = csv.reader(fp, delimiter=__B__)\n", |
| 278 | + " next(reader)\n", |
| 279 | + " for index, values in enumerate(reader):\n", |
| 280 | + " name, certs_num, months_num = values\n", |
| 281 | + " print(f\"{name} earned {__C__} certificates in {months_num} months\")" |
| 282 | + ] |
| 283 | + } |
| 284 | + ], |
| 285 | + "metadata": { |
| 286 | + "kernelspec": { |
| 287 | + "display_name": "Python 3 (ipykernel)", |
| 288 | + "language": "python", |
| 289 | + "name": "python3" |
| 290 | + }, |
| 291 | + "language_info": { |
| 292 | + "codemirror_mode": { |
| 293 | + "name": "ipython", |
| 294 | + "version": 3 |
| 295 | + }, |
| 296 | + "file_extension": ".py", |
| 297 | + "mimetype": "text/x-python", |
| 298 | + "name": "python", |
| 299 | + "nbconvert_exporter": "python", |
| 300 | + "pygments_lexer": "ipython3", |
| 301 | + "version": "3.10.7" |
| 302 | + } |
| 303 | + }, |
| 304 | + "nbformat": 4, |
| 305 | + "nbformat_minor": 5 |
| 306 | +} |
0 commit comments