|
60 | 60 | "id": "e71f1f45-a62c-4e71-acdc-636706992f9e",
|
61 | 61 | "metadata": {},
|
62 | 62 | "source": [
|
63 |
| - "Task: Change the text of this cell!" |
| 63 | + "> Change the text of this cell!" |
64 | 64 | ]
|
65 | 65 | },
|
66 | 66 | {
|
67 | 67 | "cell_type": "markdown",
|
68 | 68 | "id": "ce251bdc-3b8a-4c10-8e9d-87f2aeaae8d5",
|
69 | 69 | "metadata": {},
|
70 | 70 | "source": [
|
71 |
| - "Task: Create a new cell that reads \"Hi!\", then delete this cell!" |
| 71 | + "> Create a new cell that reads \"Hi!\", then delete this cell!" |
72 | 72 | ]
|
73 | 73 | },
|
74 | 74 | {
|
75 | 75 | "cell_type": "markdown",
|
76 | 76 | "id": "139fcdec-3e99-47af-8a49-bbbb2c786e88",
|
77 | 77 | "metadata": {},
|
78 | 78 | "source": [
|
79 |
| - "Task: Create a new Jupyter Notebook!" |
| 79 | + "> Create a new Jupyter Notebook!" |
80 | 80 | ]
|
81 | 81 | },
|
82 | 82 | {
|
|
92 | 92 | "id": "9210defe-4352-4790-89c6-db1a148c5449",
|
93 | 93 | "metadata": {},
|
94 | 94 | "source": [
|
95 |
| - "# Python" |
| 95 | + "# Python\n", |
| 96 | + "\n", |
| 97 | + "> *\"Python is the \"most powerful language you can still read\".*\n", |
| 98 | + ">\n", |
| 99 | + "> Paul Dubois " |
96 | 100 | ]
|
97 | 101 | },
|
98 | 102 | {
|
99 | 103 | "cell_type": "markdown",
|
100 | 104 | "id": "a08d6422-e6c6-405f-ab6c-3a0483e63d1e",
|
101 | 105 | "metadata": {},
|
102 | 106 | "source": [
|
103 |
| - "[Python](https://en.wikipedia.org/wiki/Python_(programming_language)) is a programming language that was developed in 1991 by Guido van Rossum.\n", |
| 107 | + "[Python](https://en.wikipedia.org/wiki/Python_(programming_language)) is a programming language that was developed in 1991 by \"Benevolent dictator for life\" Guido van Rossum.\n", |
104 | 108 | "\n",
|
105 | 109 | "Python is:\n",
|
106 | 110 | "\n",
|
107 |
| - "- **Interpreted**:\n", |
108 |
| - "- **Object-Oriented**: Most things in Python are Objects.\n", |
| 111 | + "- **Interpreted**: Programs are executed line by line by an interpreter instead of being compiled into machine code first.\n", |
| 112 | + "- **multi-paradigm**: programmers can choose their favorite way to conceptualize and structure programs\n", |
| 113 | + " - **Object-Oriented**: Programs are implemented via interacting objects. Most things in Python are objects, including functions.\n", |
| 114 | + " - **Procedural**: Programs are implemented via interacting functions.\n", |
| 115 | + " - **functional**: \n", |
109 | 116 | "- **dynamically typed**: type-safety of operations is checked at runtime. This allows programmers to write very flexible code, but eventually, the program will fail during runtime due to operations on unsupperted types.\n",
|
110 |
| - "\n", |
111 |
| - "- **Grabage Collected**: Dead variables are automatically identified and released. Programmers don't have to worry about memory management, but running the garbage collector takes time." |
| 117 | + "- **Grabage Collected**: Dead variables are automatically identified and released. Programmers don't have to worry about memory management, but running the garbage collector takes time.\n", |
| 118 | + "- etc." |
112 | 119 | ]
|
113 | 120 | },
|
114 | 121 | {
|
|
139 | 146 | " Namespaces are one honking great idea – let's do more of those!"
|
140 | 147 | ]
|
141 | 148 | },
|
| 149 | + { |
| 150 | + "cell_type": "code", |
| 151 | + "execution_count": 5, |
| 152 | + "id": "d0f745bf-8293-48fa-a33a-b3b8a36154a6", |
| 153 | + "metadata": {}, |
| 154 | + "outputs": [ |
| 155 | + { |
| 156 | + "name": "stdout", |
| 157 | + "output_type": "stream", |
| 158 | + "text": [ |
| 159 | + "Hello World!\n" |
| 160 | + ] |
| 161 | + } |
| 162 | + ], |
| 163 | + "source": [ |
| 164 | + "print(\"Hello World!\")" |
| 165 | + ] |
| 166 | + }, |
| 167 | + { |
| 168 | + "cell_type": "code", |
| 169 | + "execution_count": null, |
| 170 | + "id": "8da08c56-274f-49da-862e-b6cb5499e0d1", |
| 171 | + "metadata": {}, |
| 172 | + "outputs": [], |
| 173 | + "source": [ |
| 174 | + "# TODO: Add Python tasks" |
| 175 | + ] |
| 176 | + }, |
| 177 | + { |
| 178 | + "cell_type": "code", |
| 179 | + "execution_count": 20, |
| 180 | + "id": "ac17c77c-49d1-453b-ba25-05d039e04671", |
| 181 | + "metadata": {}, |
| 182 | + "outputs": [ |
| 183 | + { |
| 184 | + "data": { |
| 185 | + "text/plain": [ |
| 186 | + "6" |
| 187 | + ] |
| 188 | + }, |
| 189 | + "execution_count": 20, |
| 190 | + "metadata": {}, |
| 191 | + "output_type": "execute_result" |
| 192 | + } |
| 193 | + ], |
| 194 | + "source": [ |
| 195 | + "# import packages\n", |
| 196 | + "import random\n", |
| 197 | + "\n", |
| 198 | + "def throw_dice():\n", |
| 199 | + " return random.randint(1,6)\n", |
| 200 | + "\n", |
| 201 | + "throw_dice()" |
| 202 | + ] |
| 203 | + }, |
142 | 204 | {
|
143 | 205 | "cell_type": "markdown",
|
144 | 206 | "id": "ccbea933-9e85-43d7-af07-b458874fee77",
|
|
147 | 209 | "# Package Management in Python"
|
148 | 210 | ]
|
149 | 211 | },
|
| 212 | + { |
| 213 | + "cell_type": "markdown", |
| 214 | + "id": "5b9422bf-84e3-4c60-bd22-90badd0521f1", |
| 215 | + "metadata": {}, |
| 216 | + "source": [ |
| 217 | + "While Python's standard library is already pretty powerful, there are many more great packages for data science.\n", |
| 218 | + "Existing Data Science projects will probably depend on some of them.\n", |
| 219 | + "Next, let's have a look how to install and manage packages in Python." |
| 220 | + ] |
| 221 | + }, |
150 | 222 | {
|
151 | 223 | "cell_type": "markdown",
|
152 | 224 | "id": "6e7e6447-0dd9-4b72-8920-5acfc014931d",
|
153 | 225 | "metadata": {},
|
154 | 226 | "source": [
|
155 |
| - "## Pip" |
| 227 | + "## pip\n", |
| 228 | + "\n", |
| 229 | + "pip is Python's package-management tool for installing new packages.\n", |
| 230 | + "Python packages are provided by an online repository called the **Python Package Index**, or short [PyPI](https://pypi.org/)." |
| 231 | + ] |
| 232 | + }, |
| 233 | + { |
| 234 | + "cell_type": "markdown", |
| 235 | + "id": "254e4992-81b6-4676-9cea-65429c0094da", |
| 236 | + "metadata": {}, |
| 237 | + "source": [ |
| 238 | + "```sh\n", |
| 239 | + "pip install {PACKAGE NAME}\n", |
| 240 | + "```" |
| 241 | + ] |
| 242 | + }, |
| 243 | + { |
| 244 | + "cell_type": "markdown", |
| 245 | + "id": "0d65e168-f265-46a7-8ece-ddb006a20207", |
| 246 | + "metadata": {}, |
| 247 | + "source": [ |
| 248 | + "Often projects come with a `requirements.txt` file that specifies their requirements. It can be installed with pip:\n", |
| 249 | + "\n", |
| 250 | + "```sh\n", |
| 251 | + "pip install -r requirements.txt\n", |
| 252 | + "```" |
| 253 | + ] |
| 254 | + }, |
| 255 | + { |
| 256 | + "cell_type": "markdown", |
| 257 | + "id": "4ba3d734-4570-4883-b69c-1db012431ffd", |
| 258 | + "metadata": {}, |
| 259 | + "source": [ |
| 260 | + "> install the package pyjokes and run the next cell" |
| 261 | + ] |
| 262 | + }, |
| 263 | + { |
| 264 | + "cell_type": "code", |
| 265 | + "execution_count": 21, |
| 266 | + "id": "c539f499-e744-43b6-b6fc-eedc5c793f5b", |
| 267 | + "metadata": {}, |
| 268 | + "outputs": [ |
| 269 | + { |
| 270 | + "name": "stdout", |
| 271 | + "output_type": "stream", |
| 272 | + "text": [ |
| 273 | + "Collecting pyjokes\n", |
| 274 | + " Downloading pyjokes-0.8.3-py3-none-any.whl.metadata (3.4 kB)\n", |
| 275 | + "Downloading pyjokes-0.8.3-py3-none-any.whl (47 kB)\n", |
| 276 | + "Installing collected packages: pyjokes\n", |
| 277 | + "Successfully installed pyjokes-0.8.3\n" |
| 278 | + ] |
| 279 | + } |
| 280 | + ], |
| 281 | + "source": [ |
| 282 | + "!pip install pyjokes" |
| 283 | + ] |
| 284 | + }, |
| 285 | + { |
| 286 | + "cell_type": "code", |
| 287 | + "execution_count": 22, |
| 288 | + "id": "7aa1feaa-e9db-4085-984d-93038671b76f", |
| 289 | + "metadata": {}, |
| 290 | + "outputs": [ |
| 291 | + { |
| 292 | + "data": { |
| 293 | + "text/plain": [ |
| 294 | + "\"There are 10 types of people: those who understand binary and those who don't.\"" |
| 295 | + ] |
| 296 | + }, |
| 297 | + "execution_count": 22, |
| 298 | + "metadata": {}, |
| 299 | + "output_type": "execute_result" |
| 300 | + } |
| 301 | + ], |
| 302 | + "source": [ |
| 303 | + "import pyjokes\n", |
| 304 | + "\n", |
| 305 | + "pyjokes.get_joke()" |
| 306 | + ] |
| 307 | + }, |
| 308 | + { |
| 309 | + "cell_type": "markdown", |
| 310 | + "id": "8d8fd3e0-74e2-43b6-974c-e3f86dc6ccc0", |
| 311 | + "metadata": {}, |
| 312 | + "source": [ |
| 313 | + "## Virtual Environments" |
| 314 | + ] |
| 315 | + }, |
| 316 | + { |
| 317 | + "cell_type": "markdown", |
| 318 | + "id": "6f921af2-652f-45a9-855c-e146cb8e48da", |
| 319 | + "metadata": {}, |
| 320 | + "source": [ |
| 321 | + "pip is great! But things start to get messy as soon as you have multiple projects, each requiring their own dependencies.\n", |
| 322 | + "Fortunately, there is one solution: [Virtual Environments](https://docs.python.org/3/library/venv.html)!" |
| 323 | + ] |
| 324 | + }, |
| 325 | + { |
| 326 | + "cell_type": "markdown", |
| 327 | + "id": "a1082271-20c8-433b-8d7d-5aac760823d2", |
| 328 | + "metadata": {}, |
| 329 | + "source": [ |
| 330 | + "```sh\n", |
| 331 | + "# create a new virtual environment\n", |
| 332 | + "python -m venv myproject\n", |
| 333 | + "\n", |
| 334 | + "# don't forget to activate it!\n", |
| 335 | + "source myenv/bin/activate\n", |
| 336 | + "\n", |
| 337 | + "# install your packages\n", |
| 338 | + "pip install jupyter\n", |
| 339 | + "\n", |
| 340 | + "# try to start a new jupyter notebook\n", |
| 341 | + "jupyter notebook\n", |
| 342 | + "\n", |
| 343 | + "# deactivate the environment\n", |
| 344 | + "deactivate\n", |
| 345 | + "```" |
| 346 | + ] |
| 347 | + }, |
| 348 | + { |
| 349 | + "cell_type": "markdown", |
| 350 | + "id": "0b5e65d4-3995-4b8b-bc5c-f6fda9b3567e", |
| 351 | + "metadata": {}, |
| 352 | + "source": [ |
| 353 | + "## Conda" |
| 354 | + ] |
| 355 | + }, |
| 356 | + { |
| 357 | + "cell_type": "markdown", |
| 358 | + "id": "adf69db9-7594-4b10-ade4-e3d05b4257e9", |
| 359 | + "metadata": {}, |
| 360 | + "source": [ |
| 361 | + "- https://docs.conda.io\n", |
| 362 | + "- Miniconda: https://docs.anaconda.com/miniconda/" |
| 363 | + ] |
| 364 | + }, |
| 365 | + { |
| 366 | + "cell_type": "markdown", |
| 367 | + "id": "c069f3b6-fe16-4836-abab-16337903076c", |
| 368 | + "metadata": {}, |
| 369 | + "source": [ |
| 370 | + "```sh\n", |
| 371 | + "conda create -n myenv\n", |
| 372 | + "conda activate myenv\n", |
| 373 | + "conda install python=3.12 numpy jupyter\n", |
| 374 | + "```" |
| 375 | + ] |
| 376 | + }, |
| 377 | + { |
| 378 | + "cell_type": "markdown", |
| 379 | + "id": "720d22f6-ed29-4385-ae9f-b0afbbe15841", |
| 380 | + "metadata": {}, |
| 381 | + "source": [ |
| 382 | + "Quick Reference:\n", |
| 383 | + "\n", |
| 384 | + "```sh\n", |
| 385 | + "# create a new conda environment with a name\n", |
| 386 | + "conda create -n myenv\n", |
| 387 | + "# create a conda environment from a yml file\n", |
| 388 | + "conda env create -f environment.yml\n", |
| 389 | + "# list available conda environments\n", |
| 390 | + "conda env list\n", |
| 391 | + "# activate a conda environment\n", |
| 392 | + "conda activate myenv\n", |
| 393 | + "# install dependencies in active environment\n", |
| 394 | + "conda install numpy \n", |
| 395 | + "# export your environment to a yml file\n", |
| 396 | + "conda env export -f environment.yml\n", |
| 397 | + "conda env export > environment.yml\n", |
| 398 | + "# deactivate an environment\n", |
| 399 | + "conda deactivate\n", |
| 400 | + "# remove an environment\n", |
| 401 | + "conda remove --name myenv --all\n", |
| 402 | + "```" |
| 403 | + ] |
| 404 | + }, |
| 405 | + { |
| 406 | + "cell_type": "markdown", |
| 407 | + "id": "91adae1a-892b-40f3-908f-0cf99801d981", |
| 408 | + "metadata": {}, |
| 409 | + "source": [ |
| 410 | + "## Pointers" |
| 411 | + ] |
| 412 | + }, |
| 413 | + { |
| 414 | + "cell_type": "markdown", |
| 415 | + "id": "5ff781fc-3d42-4415-ae02-c97576161939", |
| 416 | + "metadata": {}, |
| 417 | + "source": [ |
| 418 | + "- https://ipython.readthedocs.io/en/stable/interactive/magics.html" |
156 | 419 | ]
|
157 | 420 | },
|
158 | 421 | {
|
159 | 422 | "cell_type": "code",
|
160 | 423 | "execution_count": null,
|
161 |
| - "id": "6bce9a93-e7db-4a4f-bf45-bf9b787fec2a", |
| 424 | + "id": "9a2be204-a8d8-4b84-a454-1982b858076b", |
162 | 425 | "metadata": {},
|
163 | 426 | "outputs": [],
|
164 | 427 | "source": []
|
|
0 commit comments