├── 1. Variabili, stringhe e numeri.ipynb ├── 2. Funzioni.ipynb ├── 3. Liste, cicli e comprensioni.ipynb ├── 4. Condizioni, valori e operatori booleani.ipynb ├── 5. Dizionari.ipynb ├── 6. NumPy.ipynb ├── 7. Scikit-learn.ipynb ├── 8. Pandas.ipynb ├── LICENSE ├── README.md ├── Soluzioni.ipynb ├── data ├── parrot.jpg ├── titanic.csv └── trump.jpg └── images ├── tree2.pdf └── treemax.pdf /1. Variabili, stringhe e numeri.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "*Contenuti*\n", 8 | "===\n", 9 | "- [Info](#Info)\n", 10 | "- [Hello, world!](#Hello,-world!)\n", 11 | "- [Commenti](#Commenti)\n", 12 | "- [Variabili](#Variabili)\n", 13 | "- [Qualche tipo: stringhe e numeri](#Qualche-tipo:-stringhe-e-numeri)\n", 14 | " - [Stringhe](#Stringhe)\n", 15 | " - [Numeri: interi e float](#Numeri:-interi-e-float)\n", 16 | " - [Stampare stringhe e numeri](#Stampare-stringhe-e-numeri)\n", 17 | "- [*Esercizio*](#Esercizio)" 18 | ] 19 | }, 20 | { 21 | "cell_type": "markdown", 22 | "metadata": {}, 23 | "source": [ 24 | "Info\n", 25 | "---\n", 26 | "A prescindere dall'applicazione, programmare è un'abilità molto utile, e **Python** è il linguaggio perfetto per iniziare. \n", 27 | "\n", 28 | "Inoltre, Python è un ottimo linguaggio per lavorare con i dati. [Python Data Science Handbook](https://jakevdp.github.io/PythonDataScienceHandbook/index.html) è un buon libro per imparare Python nel contesto della Data Science. [**Anaconda**](https://www.anaconda.com/download) è una distribuzione di Python pensata per la Data Science, ed è quella che consiglio di [installare](https://docs.anaconda.com/free/anaconda/install/index.html).\n", 29 | "\n", 30 | "Queste lezioni sono realizzate con [**Jupyter**](https://jupyter.org/), che troviamo dentro Anaconda. Oltre ad essere un *ambiente di sviluppo* interattivo, molto efficiente nella prototipazione di idee e algoritmi, è uno strumento utile per realizzare presentazioni a carattere scientifico." 31 | ] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "metadata": {}, 36 | "source": [ 37 | "Hello, world!\n", 38 | "--\n", 39 | "La prima cosa che si fa quando si impara un nuovo linguaggio di programmazione è stampare *hello, world!*" 40 | ] 41 | }, 42 | { 43 | "cell_type": "code", 44 | "execution_count": 15, 45 | "metadata": {}, 46 | "outputs": [ 47 | { 48 | "name": "stdout", 49 | "output_type": "stream", 50 | "text": [ 51 | "hello, world!\n" 52 | ] 53 | } 54 | ], 55 | "source": [ 56 | "print('hello, world!')" 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "metadata": {}, 62 | "source": [ 63 | "Abbiamo usato la *funzione* print. Vedremo presto in dettaglio cosa è una funzione. Possiamo intanto pensare ad un comando che\n", 64 | "\n", 65 | "- ha un nome univoco\n", 66 | "- accetta uno o più input\n", 67 | "- fa *qualcosa* che abbia qualcosa a che fare col nome." 68 | ] 69 | }, 70 | { 71 | "cell_type": "markdown", 72 | "metadata": {}, 73 | "source": [ 74 | "Commenti\n", 75 | "---\n", 76 | "I *commenti* sono fondamentali nella programmazione: aiutano a scrivere, organizzare e leggere il codice." 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": 16, 82 | "metadata": {}, 83 | "outputs": [ 84 | { 85 | "name": "stdout", 86 | "output_type": "stream", 87 | "text": [ 88 | "questo non è un commento\n" 89 | ] 90 | } 91 | ], 92 | "source": [ 93 | "#questo è un commento: non produce nessuna azione quando il codice viene eseguito\n", 94 | "print('questo non è un commento')" 95 | ] 96 | }, 97 | { 98 | "cell_type": "markdown", 99 | "metadata": {}, 100 | "source": [ 101 | "Variabili\n", 102 | "---\n", 103 | "Una *variabile* contiene un valore, che può essere cambiato in qualsiasi momento." 104 | ] 105 | }, 106 | { 107 | "cell_type": "code", 108 | "execution_count": 17, 109 | "metadata": {}, 110 | "outputs": [ 111 | { 112 | "name": "stdout", 113 | "output_type": "stream", 114 | "text": [ 115 | "hello, world!\n" 116 | ] 117 | } 118 | ], 119 | "source": [ 120 | "a = 'hello, world!'\n", 121 | "print(a)" 122 | ] 123 | }, 124 | { 125 | "cell_type": "code", 126 | "execution_count": 18, 127 | "metadata": {}, 128 | "outputs": [ 129 | { 130 | "name": "stdout", 131 | "output_type": "stream", 132 | "text": [ 133 | "ciao, mondo!\n" 134 | ] 135 | } 136 | ], 137 | "source": [ 138 | "a = 'ciao, mondo!'\n", 139 | "print(a)" 140 | ] 141 | }, 142 | { 143 | "cell_type": "markdown", 144 | "metadata": {}, 145 | "source": [ 146 | "Una variabile dichiarata in una *cella* del notebook può essere usata in tutte le altre celle." 147 | ] 148 | }, 149 | { 150 | "cell_type": "code", 151 | "execution_count": 19, 152 | "metadata": {}, 153 | "outputs": [ 154 | { 155 | "data": { 156 | "text/plain": [ 157 | "'ciao, mondo!'" 158 | ] 159 | }, 160 | "execution_count": 19, 161 | "metadata": {}, 162 | "output_type": "execute_result" 163 | } 164 | ], 165 | "source": [ 166 | "a" 167 | ] 168 | }, 169 | { 170 | "cell_type": "markdown", 171 | "metadata": {}, 172 | "source": [ 173 | "Ogni cella funziona come un terminale interattivo. Eseguendo la cella qui sopra sto chiedendo a Jupyter *qual è il valore della variabile a*?\n", 174 | "\n", 175 | "Si può usare questa sintassi in alternativa alla funzione print. In queste lezioni userò entrambi i costrutti." 176 | ] 177 | }, 178 | { 179 | "cell_type": "markdown", 180 | "metadata": {}, 181 | "source": [ 182 | "Jupyter dà la possibilità di conoscere, in ogni momento, tutte le variabili che sono state dichiarate. Per questo si usa il comando\n", 183 | "\n", 184 | " %whos" 185 | ] 186 | }, 187 | { 188 | "cell_type": "code", 189 | "execution_count": 20, 190 | "metadata": {}, 191 | "outputs": [ 192 | { 193 | "name": "stdout", 194 | "output_type": "stream", 195 | "text": [ 196 | "Variable Type Data/Info\n", 197 | "-----------------------------\n", 198 | "a str ciao, mondo!\n", 199 | "b int 1\n", 200 | "c float 1.1\n", 201 | "d list n=0\n" 202 | ] 203 | } 204 | ], 205 | "source": [ 206 | "%whos" 207 | ] 208 | }, 209 | { 210 | "cell_type": "markdown", 211 | "metadata": {}, 212 | "source": [ 213 | "Qualche tipo: stringhe e numeri\n", 214 | "---\n", 215 | "Python intuisce di che *tipo* è una variabile in base a come questa viene dichiarata. Ci sono diversi tipi di variabili, e il programmatore può definirne di nuovi." 216 | ] 217 | }, 218 | { 219 | "cell_type": "code", 220 | "execution_count": 21, 221 | "metadata": {}, 222 | "outputs": [ 223 | { 224 | "data": { 225 | "text/plain": [ 226 | "str" 227 | ] 228 | }, 229 | "execution_count": 21, 230 | "metadata": {}, 231 | "output_type": "execute_result" 232 | } 233 | ], 234 | "source": [ 235 | "a = 'ciao'#dichiarata come stringa, cioè con gli apici\n", 236 | "\n", 237 | "type(a)#la funzione type restituisce il tipo di una variabile" 238 | ] 239 | }, 240 | { 241 | "cell_type": "code", 242 | "execution_count": 22, 243 | "metadata": {}, 244 | "outputs": [ 245 | { 246 | "data": { 247 | "text/plain": [ 248 | "int" 249 | ] 250 | }, 251 | "execution_count": 22, 252 | "metadata": {}, 253 | "output_type": "execute_result" 254 | } 255 | ], 256 | "source": [ 257 | "b = 1#dichiarata come intero \n", 258 | "\n", 259 | "type(b)" 260 | ] 261 | }, 262 | { 263 | "cell_type": "code", 264 | "execution_count": 23, 265 | "metadata": {}, 266 | "outputs": [ 267 | { 268 | "data": { 269 | "text/plain": [ 270 | "float" 271 | ] 272 | }, 273 | "execution_count": 23, 274 | "metadata": {}, 275 | "output_type": "execute_result" 276 | } 277 | ], 278 | "source": [ 279 | "c = 1.1#float (decimale)\n", 280 | "\n", 281 | "type(c)" 282 | ] 283 | }, 284 | { 285 | "cell_type": "code", 286 | "execution_count": 24, 287 | "metadata": {}, 288 | "outputs": [ 289 | { 290 | "data": { 291 | "text/plain": [ 292 | "list" 293 | ] 294 | }, 295 | "execution_count": 24, 296 | "metadata": {}, 297 | "output_type": "execute_result" 298 | } 299 | ], 300 | "source": [ 301 | "d = []#lista\n", 302 | "\n", 303 | "type(d)" 304 | ] 305 | }, 306 | { 307 | "cell_type": "code", 308 | "execution_count": 25, 309 | "metadata": {}, 310 | "outputs": [ 311 | { 312 | "name": "stdout", 313 | "output_type": "stream", 314 | "text": [ 315 | "Variable Type Data/Info\n", 316 | "-----------------------------\n", 317 | "a str ciao\n", 318 | "b int 1\n", 319 | "c float 1.1\n", 320 | "d list n=0\n" 321 | ] 322 | } 323 | ], 324 | "source": [ 325 | "%whos" 326 | ] 327 | }, 328 | { 329 | "cell_type": "markdown", 330 | "metadata": {}, 331 | "source": [ 332 | "### Stringhe\n", 333 | "\n", 334 | "Una *stringa* è un insieme ordinato di caratteri. Può essere contenuta da 'singoli' o \"doppi\" apici, non fa differenza." 335 | ] 336 | }, 337 | { 338 | "cell_type": "code", 339 | "execution_count": 26, 340 | "metadata": {}, 341 | "outputs": [ 342 | { 343 | "data": { 344 | "text/plain": [ 345 | "'ciao mamma!'" 346 | ] 347 | }, 348 | "execution_count": 26, 349 | "metadata": {}, 350 | "output_type": "execute_result" 351 | } 352 | ], 353 | "source": [ 354 | "a = 'ciao mamma!'\n", 355 | "\n", 356 | "a" 357 | ] 358 | }, 359 | { 360 | "cell_type": "code", 361 | "execution_count": 27, 362 | "metadata": {}, 363 | "outputs": [ 364 | { 365 | "data": { 366 | "text/plain": [ 367 | "'ciao mamma!'" 368 | ] 369 | }, 370 | "execution_count": 27, 371 | "metadata": {}, 372 | "output_type": "execute_result" 373 | } 374 | ], 375 | "source": [ 376 | "b = \"ciao mamma!\"\n", 377 | "\n", 378 | "b" 379 | ] 380 | }, 381 | { 382 | "cell_type": "markdown", 383 | "metadata": {}, 384 | "source": [ 385 | "Alle stringhe (come a tutti i tipi di variabili) possono essere applicate delle funzioni, come print vista in precedenza." 386 | ] 387 | }, 388 | { 389 | "cell_type": "code", 390 | "execution_count": 28, 391 | "metadata": {}, 392 | "outputs": [ 393 | { 394 | "data": { 395 | "text/plain": [ 396 | "'francesco'" 397 | ] 398 | }, 399 | "execution_count": 28, 400 | "metadata": {}, 401 | "output_type": "execute_result" 402 | } 403 | ], 404 | "source": [ 405 | "a = 'Francesco'\n", 406 | "\n", 407 | "a.lower()#trasforma la stringa in minuscolo" 408 | ] 409 | }, 410 | { 411 | "cell_type": "code", 412 | "execution_count": 29, 413 | "metadata": {}, 414 | "outputs": [ 415 | { 416 | "data": { 417 | "text/plain": [ 418 | "'FRANCESCO'" 419 | ] 420 | }, 421 | "execution_count": 29, 422 | "metadata": {}, 423 | "output_type": "execute_result" 424 | } 425 | ], 426 | "source": [ 427 | "a.upper()#trasforma la stringa in maiuscolo" 428 | ] 429 | }, 430 | { 431 | "cell_type": "code", 432 | "execution_count": 30, 433 | "metadata": {}, 434 | "outputs": [ 435 | { 436 | "data": { 437 | "text/plain": [ 438 | "'Francesca'" 439 | ] 440 | }, 441 | "execution_count": 30, 442 | "metadata": {}, 443 | "output_type": "execute_result" 444 | } 445 | ], 446 | "source": [ 447 | "a.replace('o','a')#costruisce una nuova stringa operando una sostituzione di carattere" 448 | ] 449 | }, 450 | { 451 | "cell_type": "code", 452 | "execution_count": 31, 453 | "metadata": {}, 454 | "outputs": [ 455 | { 456 | "data": { 457 | "text/plain": [ 458 | "'Francesca'" 459 | ] 460 | }, 461 | "execution_count": 31, 462 | "metadata": {}, 463 | "output_type": "execute_result" 464 | } 465 | ], 466 | "source": [ 467 | "b = a.replace('o','a')#assegnazione della nuova stringa ad altra variabile\n", 468 | "\n", 469 | "b" 470 | ] 471 | }, 472 | { 473 | "cell_type": "markdown", 474 | "metadata": {}, 475 | "source": [ 476 | "Due stringhe possono essere concatenate con l'operazione *+*: il risultato è una nuova stringa." 477 | ] 478 | }, 479 | { 480 | "cell_type": "code", 481 | "execution_count": 32, 482 | "metadata": {}, 483 | "outputs": [], 484 | "source": [ 485 | "a = 'Ciao mamma, guarda come'\n", 486 | "b = ' mi diverto'\n", 487 | "c = a + b" 488 | ] 489 | }, 490 | { 491 | "cell_type": "code", 492 | "execution_count": 33, 493 | "metadata": {}, 494 | "outputs": [ 495 | { 496 | "data": { 497 | "text/plain": [ 498 | "'Ciao mamma, guarda come mi diverto'" 499 | ] 500 | }, 501 | "execution_count": 33, 502 | "metadata": {}, 503 | "output_type": "execute_result" 504 | } 505 | ], 506 | "source": [ 507 | "c" 508 | ] 509 | }, 510 | { 511 | "cell_type": "markdown", 512 | "metadata": {}, 513 | "source": [ 514 | "### Numeri: interi e float\n", 515 | "\n", 516 | "*int* (numeri interi) e *float* (numeri decimali) sono altri due tipi standard di Python. " 517 | ] 518 | }, 519 | { 520 | "cell_type": "code", 521 | "execution_count": 34, 522 | "metadata": {}, 523 | "outputs": [ 524 | { 525 | "data": { 526 | "text/plain": [ 527 | "2.0" 528 | ] 529 | }, 530 | "execution_count": 34, 531 | "metadata": {}, 532 | "output_type": "execute_result" 533 | } 534 | ], 535 | "source": [ 536 | "a = 1#intero\n", 537 | "b = 1.0#float\n", 538 | "c = a + b\n", 539 | "\n", 540 | "c" 541 | ] 542 | }, 543 | { 544 | "cell_type": "markdown", 545 | "metadata": {}, 546 | "source": [ 547 | "Per convenzione, operazioni tra interi e float restituiscono float." 548 | ] 549 | }, 550 | { 551 | "cell_type": "code", 552 | "execution_count": 35, 553 | "metadata": {}, 554 | "outputs": [ 555 | { 556 | "data": { 557 | "text/plain": [ 558 | "float" 559 | ] 560 | }, 561 | "execution_count": 35, 562 | "metadata": {}, 563 | "output_type": "execute_result" 564 | } 565 | ], 566 | "source": [ 567 | "type(c)" 568 | ] 569 | }, 570 | { 571 | "cell_type": "markdown", 572 | "metadata": {}, 573 | "source": [ 574 | "Le operazioni aritmetiche hanno una priorità: moltiplicazione e divisione vengono eseguite per prime. La priorità viene alterata dalle parentesi." 575 | ] 576 | }, 577 | { 578 | "cell_type": "code", 579 | "execution_count": 36, 580 | "metadata": {}, 581 | "outputs": [ 582 | { 583 | "data": { 584 | "text/plain": [ 585 | "25" 586 | ] 587 | }, 588 | "execution_count": 36, 589 | "metadata": {}, 590 | "output_type": "execute_result" 591 | } 592 | ], 593 | "source": [ 594 | "2*10+5#2*10 viene eseguito prima" 595 | ] 596 | }, 597 | { 598 | "cell_type": "code", 599 | "execution_count": 37, 600 | "metadata": {}, 601 | "outputs": [ 602 | { 603 | "data": { 604 | "text/plain": [ 605 | "30" 606 | ] 607 | }, 608 | "execution_count": 37, 609 | "metadata": {}, 610 | "output_type": "execute_result" 611 | } 612 | ], 613 | "source": [ 614 | "2*(10+5)#adesso 10+5 viene eseguito prima" 615 | ] 616 | }, 617 | { 618 | "cell_type": "markdown", 619 | "metadata": {}, 620 | "source": [ 621 | "**Nota**: Python interpreta l'operazione di addizione, +, in base al tipo delle variabili con cui opera." 622 | ] 623 | }, 624 | { 625 | "cell_type": "markdown", 626 | "metadata": {}, 627 | "source": [ 628 | "### Stampare stringhe e numeri" 629 | ] 630 | }, 631 | { 632 | "cell_type": "code", 633 | "execution_count": 38, 634 | "metadata": {}, 635 | "outputs": [ 636 | { 637 | "name": "stdout", 638 | "output_type": "stream", 639 | "text": [ 640 | "Oggi è il 28\n" 641 | ] 642 | } 643 | ], 644 | "source": [ 645 | "a = 'Oggi è il'\n", 646 | "b = 28\n", 647 | "print(a, b)#print aggiunge uno spazio tra gli argomenti e converte b in una stringa" 648 | ] 649 | }, 650 | { 651 | "cell_type": "code", 652 | "execution_count": 39, 653 | "metadata": {}, 654 | "outputs": [ 655 | { 656 | "name": "stdout", 657 | "output_type": "stream", 658 | "text": [ 659 | "Oggi ci sono 25.7 gradi\n" 660 | ] 661 | } 662 | ], 663 | "source": [ 664 | "a = 'Oggi ci sono'\n", 665 | "b = 25.7\n", 666 | "c = 'gradi'\n", 667 | "print(a, b, c)" 668 | ] 669 | }, 670 | { 671 | "cell_type": "markdown", 672 | "metadata": {}, 673 | "source": [ 674 | "Un'alternativa è utilizzare i *segnaposto* e la funzione *format*." 675 | ] 676 | }, 677 | { 678 | "cell_type": "code", 679 | "execution_count": 40, 680 | "metadata": {}, 681 | "outputs": [ 682 | { 683 | "name": "stdout", 684 | "output_type": "stream", 685 | "text": [ 686 | "Il risultato di 10 diviso 2 è 5.0\n" 687 | ] 688 | } 689 | ], 690 | "source": [ 691 | "a = 10\n", 692 | "b = 2\n", 693 | "c = a/b\n", 694 | "print('Il risultato di {} diviso {} è {}'.format(a, b, c))" 695 | ] 696 | }, 697 | { 698 | "cell_type": "markdown", 699 | "metadata": {}, 700 | "source": [ 701 | "Questo è utile se si vuole specificare un formato di stampa." 702 | ] 703 | }, 704 | { 705 | "cell_type": "code", 706 | "execution_count": 41, 707 | "metadata": {}, 708 | "outputs": [ 709 | { 710 | "name": "stdout", 711 | "output_type": "stream", 712 | "text": [ 713 | "Il risultato di 10 diviso 3 è 3.3333333333333335\n" 714 | ] 715 | } 716 | ], 717 | "source": [ 718 | "a = 10\n", 719 | "b = 3\n", 720 | "c = a/b\n", 721 | "print('Il risultato di {} diviso {} è {}'.format(a, b, c))" 722 | ] 723 | }, 724 | { 725 | "cell_type": "code", 726 | "execution_count": 42, 727 | "metadata": {}, 728 | "outputs": [ 729 | { 730 | "name": "stdout", 731 | "output_type": "stream", 732 | "text": [ 733 | "Il risultato di 10 diviso 3 è circa 3.33\n" 734 | ] 735 | } 736 | ], 737 | "source": [ 738 | "a = 10\n", 739 | "b = 3\n", 740 | "c = a/b\n", 741 | "print('Il risultato di {} diviso {} è circa {:.2f}'.format(a, b, c))" 742 | ] 743 | }, 744 | { 745 | "cell_type": "code", 746 | "execution_count": 43, 747 | "metadata": {}, 748 | "outputs": [], 749 | "source": [ 750 | "d = 'Il risultato di {} diviso {} è {:.2f}'.format(a, b, c)" 751 | ] 752 | }, 753 | { 754 | "cell_type": "code", 755 | "execution_count": 44, 756 | "metadata": {}, 757 | "outputs": [ 758 | { 759 | "data": { 760 | "text/plain": [ 761 | "'Il risultato di 10 diviso 3 è 3.33'" 762 | ] 763 | }, 764 | "execution_count": 44, 765 | "metadata": {}, 766 | "output_type": "execute_result" 767 | } 768 | ], 769 | "source": [ 770 | "d" 771 | ] 772 | }, 773 | { 774 | "cell_type": "markdown", 775 | "metadata": {}, 776 | "source": [ 777 | "***Esercizio***\n", 778 | "---\n", 779 | "- dichiarare due variabili numeriche\n", 780 | "- eseguire un'operazione qualsiasi che le coinvolga\n", 781 | "- salvare il risultato in un terza variabile\n", 782 | "- stampare il risultato nella forma *Il risultato è ... ed è di tipo ...*\n", 783 | "- se il risultato è un float, stampare solo le prime 3 cifre decimali\n", 784 | "- commentare le righe del codice con il significato delle azioni corrispondenti" 785 | ] 786 | }, 787 | { 788 | "cell_type": "code", 789 | "execution_count": 45, 790 | "metadata": {}, 791 | "outputs": [], 792 | "source": [ 793 | "#FILL ME" 794 | ] 795 | }, 796 | { 797 | "cell_type": "markdown", 798 | "metadata": {}, 799 | "source": [ 800 | "\n", 808 | "\n", 809 | "" 812 | ] 813 | } 814 | ], 815 | "metadata": { 816 | "kernelspec": { 817 | "display_name": "Python 3", 818 | "language": "python", 819 | "name": "python3" 820 | }, 821 | "language_info": { 822 | "codemirror_mode": { 823 | "name": "ipython", 824 | "version": 3 825 | }, 826 | "file_extension": ".py", 827 | "mimetype": "text/x-python", 828 | "name": "python", 829 | "nbconvert_exporter": "python", 830 | "pygments_lexer": "ipython3", 831 | "version": "3.8.5" 832 | } 833 | }, 834 | "nbformat": 4, 835 | "nbformat_minor": 2 836 | } 837 | -------------------------------------------------------------------------------- /2. Funzioni.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "*Contenuti*\n", 8 | "===\n", 9 | "- [Funzioni](#Funzioni)\n", 10 | " - [Sintassi](#Sintassi)\n", 11 | " - [Ordine delle chiamate](#Ordine-delle-chiamate)\n", 12 | " - [Valore di ritorno](#Valore-di-ritorno)" 13 | ] 14 | }, 15 | { 16 | "cell_type": "markdown", 17 | "metadata": {}, 18 | "source": [ 19 | "Funzioni\n", 20 | "===\n", 21 | "Spesso, quando si scrive codice, una certa sequenza di azioni viene utilizzata molte volte con piccole differenze di contesto.\n", 22 | "\n", 23 | "Una *funzione* è una sequenza di azioni a cui si dà un nome, e che si può invocare all'occorrenza. Abbiamo già visto ed usato alcune funzioni, sia generiche (come print) che definite sul tipo stringa (upper, lower, replace, format)." 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "Sintassi\n", 31 | "---" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": null, 37 | "metadata": {}, 38 | "outputs": [], 39 | "source": [ 40 | "def function_name(argument_1, argument_2):\n", 41 | " #fai qualcosa, utilizzando argument_1 e argument_2\n", 42 | " #volendo, restituisci un valore\n", 43 | " \n", 44 | "function_name(a, b)#chiamata" 45 | ] 46 | }, 47 | { 48 | "cell_type": "markdown", 49 | "metadata": {}, 50 | "source": [ 51 | "Il codice qui sopra è un esempio generale di *dichiarazione* di funzione.\n", 52 | "\n", 53 | "- **def** è una keyword del linguaggio, ne vedremo altre\n", 54 | "- *function_name* è il nome della funzione, da usare al momento della chiamata\n", 55 | "- *argument_1* e *argument_2* sono detti *argomenti*; sono ordinati e possono essere tanti a piacere" 56 | ] 57 | }, 58 | { 59 | "cell_type": "markdown", 60 | "metadata": {}, 61 | "source": [ 62 | "Ordine delle chiamate\n", 63 | "---\n", 64 | "\n", 65 | "Una funzione può chiamarne un'altra: è così che funzionano tutti i programmi complessi. L'ordine delle chiamate durante l'esecuzione è salvato nella [*stack trace*](https://en.wikipedia.org/wiki/Stack_trace)." 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "execution_count": 2, 71 | "metadata": {}, 72 | "outputs": [ 73 | { 74 | "name": "stdout", 75 | "output_type": "stream", 76 | "text": [ 77 | "fun_1: sto chiamando fun_2\n", 78 | "fun_2: ciao!\n" 79 | ] 80 | } 81 | ], 82 | "source": [ 83 | "def fun_1(arg):\n", 84 | " print('fun_1: sto chiamando fun_2')\n", 85 | " fun_2(arg)\n", 86 | "\n", 87 | "def fun_2(arg):\n", 88 | " print('fun_2:', arg)\n", 89 | "\n", 90 | "fun_1('ciao!')" 91 | ] 92 | }, 93 | { 94 | "cell_type": "markdown", 95 | "metadata": {}, 96 | "source": [ 97 | "Valore di ritorno\n", 98 | "---\n", 99 | "Oltre ad eseguire delle azioni, una funzione può restituire uno o più valori attraverso la keyword *return*." 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": 3, 105 | "metadata": {}, 106 | "outputs": [], 107 | "source": [ 108 | "def product(a, b):\n", 109 | " print('Eseguo e restituisco il prodotto di {} e {}.'.format(a, b))\n", 110 | " c = a*b\n", 111 | " return c#valore di ritorno" 112 | ] 113 | }, 114 | { 115 | "cell_type": "markdown", 116 | "metadata": {}, 117 | "source": [ 118 | "Come per le variabili, una funzione dichiarata in una cella può essere chiamata anche in qualsiasi altra cella del notebook." 119 | ] 120 | }, 121 | { 122 | "cell_type": "code", 123 | "execution_count": 4, 124 | "metadata": {}, 125 | "outputs": [ 126 | { 127 | "name": "stdout", 128 | "output_type": "stream", 129 | "text": [ 130 | "Eseguo e restituisco il prodotto di 10 e 5.\n" 131 | ] 132 | }, 133 | { 134 | "data": { 135 | "text/plain": [ 136 | "50" 137 | ] 138 | }, 139 | "execution_count": 4, 140 | "metadata": {}, 141 | "output_type": "execute_result" 142 | } 143 | ], 144 | "source": [ 145 | "product(10, 5)" 146 | ] 147 | }, 148 | { 149 | "cell_type": "markdown", 150 | "metadata": {}, 151 | "source": [ 152 | "Notare la doppia stampa qui sopra: una è eseguita dal print dentro il corpo della funzione, l'altra è il valore restituito.\n", 153 | "\n", 154 | "Quest'ultimo può essere assegnato ad una variabile." 155 | ] 156 | }, 157 | { 158 | "cell_type": "code", 159 | "execution_count": 5, 160 | "metadata": {}, 161 | "outputs": [ 162 | { 163 | "name": "stdout", 164 | "output_type": "stream", 165 | "text": [ 166 | "Eseguo e restituisco il prodotto di 20 e 50.\n" 167 | ] 168 | }, 169 | { 170 | "data": { 171 | "text/plain": [ 172 | "1000" 173 | ] 174 | }, 175 | "execution_count": 5, 176 | "metadata": {}, 177 | "output_type": "execute_result" 178 | } 179 | ], 180 | "source": [ 181 | "res = product(20, 50)\n", 182 | "\n", 183 | "res" 184 | ] 185 | }, 186 | { 187 | "cell_type": "markdown", 188 | "metadata": {}, 189 | "source": [ 190 | "\n", 198 | "\n", 199 | "" 202 | ] 203 | } 204 | ], 205 | "metadata": { 206 | "kernelspec": { 207 | "display_name": "Python 3", 208 | "language": "python", 209 | "name": "python3" 210 | }, 211 | "language_info": { 212 | "codemirror_mode": { 213 | "name": "ipython", 214 | "version": 3 215 | }, 216 | "file_extension": ".py", 217 | "mimetype": "text/x-python", 218 | "name": "python", 219 | "nbconvert_exporter": "python", 220 | "pygments_lexer": "ipython3", 221 | "version": "3.8.5" 222 | } 223 | }, 224 | "nbformat": 4, 225 | "nbformat_minor": 2 226 | } 227 | -------------------------------------------------------------------------------- /3. Liste, cicli e comprensioni.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "*Contenuti*\n", 8 | "===\n", 9 | "- [Liste](#Liste)\n", 10 | " - [Dimensione e accesso indicizzato](#Dimensione-e-accesso-indicizzato)\n", 11 | " - [Lista vuota e operazioni base](#Lista-vuota-e-operazioni-base)\n", 12 | " - [Estrazione](#Estrazione)\n", 13 | " - [*Esercizio 1*](#Esercizio-1)\n", 14 | " - [Ricerca](#Ricerca)\n", 15 | " - [Ordinamento](#Ordinamento)\n", 16 | " - [Operatori aggregati](#Operatori-aggregati)\n", 17 | " - [*Esercizio 2*](#Esercizio-2)\n", 18 | " - [Liste di tipo misto](#Liste-di-tipo-misto)\n", 19 | " - [*Slicing*](#Slicing)\n", 20 | " - [*Esercizio 3*](#Esercizio-3)\n", 21 | "- [Cicli *for*](#Cicli-for)\n", 22 | " - [Enumerazione](#Enumerazione)\n", 23 | " - [*Esercizio 4*](#Esercizio-4)\n", 24 | " - [Comprensioni di liste](#Comprensioni-di-liste)\n", 25 | " - [*Esercizio 5*](#Esercizio-5)\n", 26 | " - [*Esercizio 6*](#Esercizio-6)" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": {}, 32 | "source": [ 33 | "Liste\n", 34 | "===\n", 35 | "Una *lista* è una collezione ordinata di oggetti, contenuta in una variabile." 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": 1, 41 | "metadata": {}, 42 | "outputs": [ 43 | { 44 | "name": "stdout", 45 | "output_type": "stream", 46 | "text": [ 47 | "\n", 48 | "['triangle', 'square', 'pentagon']\n" 49 | ] 50 | } 51 | ], 52 | "source": [ 53 | "shapes = ['triangle', 'square', 'pentagon']\n", 54 | "print(type(shapes))\n", 55 | "print(shapes)" 56 | ] 57 | }, 58 | { 59 | "cell_type": "markdown", 60 | "metadata": {}, 61 | "source": [ 62 | "Dimensione e accesso indicizzato\n", 63 | "---\n", 64 | "La *dimensione* di una lista si ottiene attraverso la funzione *len* (da *length*, lunghezza in inglese)." 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": 2, 70 | "metadata": {}, 71 | "outputs": [ 72 | { 73 | "data": { 74 | "text/plain": [ 75 | "3" 76 | ] 77 | }, 78 | "execution_count": 2, 79 | "metadata": {}, 80 | "output_type": "execute_result" 81 | } 82 | ], 83 | "source": [ 84 | "len(shapes)" 85 | ] 86 | }, 87 | { 88 | "cell_type": "markdown", 89 | "metadata": {}, 90 | "source": [ 91 | "Si può accedere ad una lista attraverso un indice intero: la prima posizione ha indice \"0\", l'ultima \"len-1\"." 92 | ] 93 | }, 94 | { 95 | "cell_type": "code", 96 | "execution_count": 3, 97 | "metadata": {}, 98 | "outputs": [ 99 | { 100 | "name": "stdout", 101 | "output_type": "stream", 102 | "text": [ 103 | "triangle\n", 104 | "square\n", 105 | "pentagon\n" 106 | ] 107 | } 108 | ], 109 | "source": [ 110 | "print(shapes[0])\n", 111 | "print(shapes[1])\n", 112 | "print(shapes[len(shapes)-1])" 113 | ] 114 | }, 115 | { 116 | "cell_type": "markdown", 117 | "metadata": {}, 118 | "source": [ 119 | "Le liste Python sono *circolari*: si possono usare indici negativi per accedere comodamente agli ultimi elementi." 120 | ] 121 | }, 122 | { 123 | "cell_type": "code", 124 | "execution_count": 4, 125 | "metadata": {}, 126 | "outputs": [ 127 | { 128 | "name": "stdout", 129 | "output_type": "stream", 130 | "text": [ 131 | "pentagon\n", 132 | "square\n" 133 | ] 134 | } 135 | ], 136 | "source": [ 137 | "print(shapes[-1])#ultimo\n", 138 | "print(shapes[-2])#penultimo" 139 | ] 140 | }, 141 | { 142 | "cell_type": "markdown", 143 | "metadata": {}, 144 | "source": [ 145 | "Lista vuota e operazioni base\n", 146 | "---\n", 147 | "Si può creare una lista vuota e aggiungervi elementi successivamente." 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "execution_count": 5, 153 | "metadata": {}, 154 | "outputs": [ 155 | { 156 | "data": { 157 | "text/plain": [ 158 | "[]" 159 | ] 160 | }, 161 | "execution_count": 5, 162 | "metadata": {}, 163 | "output_type": "execute_result" 164 | } 165 | ], 166 | "source": [ 167 | "shapes = []#lista vuota\n", 168 | "\n", 169 | "shapes" 170 | ] 171 | }, 172 | { 173 | "cell_type": "markdown", 174 | "metadata": {}, 175 | "source": [ 176 | "Quando ha a che fare con liste, Python interpreta l'operatore + come una *concatenazione*." 177 | ] 178 | }, 179 | { 180 | "cell_type": "code", 181 | "execution_count": 6, 182 | "metadata": {}, 183 | "outputs": [ 184 | { 185 | "data": { 186 | "text/plain": [ 187 | "['triangle', 'square']" 188 | ] 189 | }, 190 | "execution_count": 6, 191 | "metadata": {}, 192 | "output_type": "execute_result" 193 | } 194 | ], 195 | "source": [ 196 | "shapes = shapes + ['triangle', 'square']\n", 197 | "\n", 198 | "shapes" 199 | ] 200 | }, 201 | { 202 | "cell_type": "code", 203 | "execution_count": 7, 204 | "metadata": {}, 205 | "outputs": [ 206 | { 207 | "data": { 208 | "text/plain": [ 209 | "['triangle', 'square', 'pentagon']" 210 | ] 211 | }, 212 | "execution_count": 7, 213 | "metadata": {}, 214 | "output_type": "execute_result" 215 | } 216 | ], 217 | "source": [ 218 | "shapes = shapes + ['pentagon']\n", 219 | "\n", 220 | "shapes" 221 | ] 222 | }, 223 | { 224 | "cell_type": "markdown", 225 | "metadata": {}, 226 | "source": [ 227 | "**Nota**: l'aggiunta di un unico elemento ad una lista è un caso particolare della concatenazione. Servono quindi le parentesi quadre: stiamo infatti concatenando una lista a un'altra che contiene solo un elemento." 228 | ] 229 | }, 230 | { 231 | "cell_type": "markdown", 232 | "metadata": {}, 233 | "source": [ 234 | "La concatenazione (in generale l'operazione generica +) può essere eseguita in modo compatto. " 235 | ] 236 | }, 237 | { 238 | "cell_type": "code", 239 | "execution_count": 8, 240 | "metadata": {}, 241 | "outputs": [ 242 | { 243 | "data": { 244 | "text/plain": [ 245 | "5" 246 | ] 247 | }, 248 | "execution_count": 8, 249 | "metadata": {}, 250 | "output_type": "execute_result" 251 | } 252 | ], 253 | "source": [ 254 | "a = 0\n", 255 | "a += 5#forma compatta per 'a = a + 5'\n", 256 | "\n", 257 | "a" 258 | ] 259 | }, 260 | { 261 | "cell_type": "code", 262 | "execution_count": 9, 263 | "metadata": {}, 264 | "outputs": [ 265 | { 266 | "data": { 267 | "text/plain": [ 268 | "'ciao mamma!'" 269 | ] 270 | }, 271 | "execution_count": 9, 272 | "metadata": {}, 273 | "output_type": "execute_result" 274 | } 275 | ], 276 | "source": [ 277 | "b = 'ciao'\n", 278 | "b += ' mamma!'#concatenazione compatta di stringhe\n", 279 | "\n", 280 | "b" 281 | ] 282 | }, 283 | { 284 | "cell_type": "code", 285 | "execution_count": 10, 286 | "metadata": {}, 287 | "outputs": [ 288 | { 289 | "data": { 290 | "text/plain": [ 291 | "['triangle', 'square', 'pentagon', 'hexagon']" 292 | ] 293 | }, 294 | "execution_count": 10, 295 | "metadata": {}, 296 | "output_type": "execute_result" 297 | } 298 | ], 299 | "source": [ 300 | "shapes += ['hexagon']#concatenazione compatta di liste\n", 301 | "\n", 302 | "shapes" 303 | ] 304 | }, 305 | { 306 | "cell_type": "markdown", 307 | "metadata": {}, 308 | "source": [ 309 | "Si può inserire un elemento in una posizione specifica della lista. Tutti quelli successivi saranno spostati sulla destra, e la dimensione della lista aumenterà di 1." 310 | ] 311 | }, 312 | { 313 | "cell_type": "code", 314 | "execution_count": 11, 315 | "metadata": {}, 316 | "outputs": [ 317 | { 318 | "data": { 319 | "text/plain": [ 320 | "['triangle', 'square', 'rectangle', 'pentagon', 'hexagon']" 321 | ] 322 | }, 323 | "execution_count": 11, 324 | "metadata": {}, 325 | "output_type": "execute_result" 326 | } 327 | ], 328 | "source": [ 329 | "shapes.insert(2, 'rectangle')#inserimento in posizione 2\n", 330 | "\n", 331 | "shapes" 332 | ] 333 | }, 334 | { 335 | "cell_type": "markdown", 336 | "metadata": {}, 337 | "source": [ 338 | "Gli elementi di una lista possono essere modificati in qualsiasi momento." 339 | ] 340 | }, 341 | { 342 | "cell_type": "code", 343 | "execution_count": 12, 344 | "metadata": {}, 345 | "outputs": [ 346 | { 347 | "data": { 348 | "text/plain": [ 349 | "['circle', 'square', 'rectangle', 'pentagon', 'hexagon']" 350 | ] 351 | }, 352 | "execution_count": 12, 353 | "metadata": {}, 354 | "output_type": "execute_result" 355 | } 356 | ], 357 | "source": [ 358 | "shapes[0] = 'circle'#modifica\n", 359 | "\n", 360 | "shapes" 361 | ] 362 | }, 363 | { 364 | "cell_type": "markdown", 365 | "metadata": {}, 366 | "source": [ 367 | "Per cancellare un elemento della lista si usa la funzione *remove*." 368 | ] 369 | }, 370 | { 371 | "cell_type": "code", 372 | "execution_count": 13, 373 | "metadata": {}, 374 | "outputs": [ 375 | { 376 | "data": { 377 | "text/plain": [ 378 | "['circle', 'square', 'rectangle', 'pentagon']" 379 | ] 380 | }, 381 | "execution_count": 13, 382 | "metadata": {}, 383 | "output_type": "execute_result" 384 | } 385 | ], 386 | "source": [ 387 | "shapes.remove('hexagon')#rimozione\n", 388 | "\n", 389 | "shapes" 390 | ] 391 | }, 392 | { 393 | "cell_type": "markdown", 394 | "metadata": {}, 395 | "source": [ 396 | "Estrazione\n", 397 | "---\n", 398 | "La funzione *pop* estrae un elemento da una lista (di default, l'ultimo), e lo restituisce." 399 | ] 400 | }, 401 | { 402 | "cell_type": "code", 403 | "execution_count": 14, 404 | "metadata": {}, 405 | "outputs": [ 406 | { 407 | "name": "stdout", 408 | "output_type": "stream", 409 | "text": [ 410 | "['circle', 'square', 'rectangle']\n", 411 | "Ultimo elemento: pentagon\n" 412 | ] 413 | } 414 | ], 415 | "source": [ 416 | "last_element = shapes.pop()\n", 417 | "print(shapes)\n", 418 | "print('Ultimo elemento:', last_element)" 419 | ] 420 | }, 421 | { 422 | "cell_type": "markdown", 423 | "metadata": {}, 424 | "source": [ 425 | "### *Esercizio 1* \n", 426 | "\n", 427 | "Che differenza c'è (oltre al diverso tipo su cui sono definite) tra le funzioni viste finora (come upper, lower, replace del tipo stringa) e insert, remove e pop?" 428 | ] 429 | }, 430 | { 431 | "cell_type": "markdown", 432 | "metadata": {}, 433 | "source": [ 434 | "Ricerca\n", 435 | "---\n", 436 | "Possiamo controllare se un certo oggetto è contenuto in una lista." 437 | ] 438 | }, 439 | { 440 | "cell_type": "code", 441 | "execution_count": 15, 442 | "metadata": {}, 443 | "outputs": [ 444 | { 445 | "data": { 446 | "text/plain": [ 447 | "True" 448 | ] 449 | }, 450 | "execution_count": 15, 451 | "metadata": {}, 452 | "output_type": "execute_result" 453 | } 454 | ], 455 | "source": [ 456 | "'square' in shapes" 457 | ] 458 | }, 459 | { 460 | "cell_type": "code", 461 | "execution_count": 16, 462 | "metadata": {}, 463 | "outputs": [ 464 | { 465 | "data": { 466 | "text/plain": [ 467 | "False" 468 | ] 469 | }, 470 | "execution_count": 16, 471 | "metadata": {}, 472 | "output_type": "execute_result" 473 | } 474 | ], 475 | "source": [ 476 | "'triangle' in shapes" 477 | ] 478 | }, 479 | { 480 | "cell_type": "markdown", 481 | "metadata": {}, 482 | "source": [ 483 | "Ordinamento\n", 484 | "---\n", 485 | "Una lista può essere ordinata attraverso la funzione *sorted*. Anche in questo caso, Python interpreta un'operazione in modo dinamico (quale?) in base al tipo di variabili contenute nella lista.\n", 486 | "\n", 487 | "Nel caso delle stringhe, l'ordinamento sarà alfabetico." 488 | ] 489 | }, 490 | { 491 | "cell_type": "code", 492 | "execution_count": 17, 493 | "metadata": {}, 494 | "outputs": [ 495 | { 496 | "data": { 497 | "text/plain": [ 498 | "['circle', 'hexagon', 'square', 'triangle']" 499 | ] 500 | }, 501 | "execution_count": 17, 502 | "metadata": {}, 503 | "output_type": "execute_result" 504 | } 505 | ], 506 | "source": [ 507 | "shapes = ['triangle', 'square', 'circle', 'hexagon']\n", 508 | "\n", 509 | "sorted(shapes)" 510 | ] 511 | }, 512 | { 513 | "cell_type": "markdown", 514 | "metadata": {}, 515 | "source": [ 516 | "La funzione sorted crea (e restituisce) una nuova lista: se ne alteriamo gli elementi, non otteniamo effetti su quella di partenza." 517 | ] 518 | }, 519 | { 520 | "cell_type": "code", 521 | "execution_count": 18, 522 | "metadata": {}, 523 | "outputs": [ 524 | { 525 | "name": "stdout", 526 | "output_type": "stream", 527 | "text": [ 528 | "lista ordinata: ['circle', 'hexagon', 'square', 'triangle']\n" 529 | ] 530 | } 531 | ], 532 | "source": [ 533 | "sorted_shapes = sorted(shapes)#assegno risultato ad una variabile\n", 534 | "print('lista ordinata:', sorted_shapes)" 535 | ] 536 | }, 537 | { 538 | "cell_type": "code", 539 | "execution_count": 19, 540 | "metadata": {}, 541 | "outputs": [ 542 | { 543 | "name": "stdout", 544 | "output_type": "stream", 545 | "text": [ 546 | "lista ordinata modificata: ['rhombus', 'hexagon', 'square', 'triangle']\n" 547 | ] 548 | } 549 | ], 550 | "source": [ 551 | "sorted_shapes[0] = 'rhombus'#modifica\n", 552 | "print('lista ordinata modificata:', sorted_shapes)" 553 | ] 554 | }, 555 | { 556 | "cell_type": "code", 557 | "execution_count": 20, 558 | "metadata": {}, 559 | "outputs": [ 560 | { 561 | "name": "stdout", 562 | "output_type": "stream", 563 | "text": [ 564 | "lista originale: ['triangle', 'square', 'circle', 'hexagon']\n" 565 | ] 566 | } 567 | ], 568 | "source": [ 569 | "print('lista originale:', shapes)" 570 | ] 571 | }, 572 | { 573 | "cell_type": "markdown", 574 | "metadata": {}, 575 | "source": [ 576 | "Quanto detto vale anche per le liste numeriche. Per convenzione, l'ordinamento è crescente." 577 | ] 578 | }, 579 | { 580 | "cell_type": "code", 581 | "execution_count": 21, 582 | "metadata": {}, 583 | "outputs": [ 584 | { 585 | "data": { 586 | "text/plain": [ 587 | "[1, 3, 5, 6, 7, 8]" 588 | ] 589 | }, 590 | "execution_count": 21, 591 | "metadata": {}, 592 | "output_type": "execute_result" 593 | } 594 | ], 595 | "source": [ 596 | "numbers = [3,6,1,7,8,5]\n", 597 | "\n", 598 | "sorted(numbers)" 599 | ] 600 | }, 601 | { 602 | "cell_type": "markdown", 603 | "metadata": {}, 604 | "source": [ 605 | "La funzione sorted permette l'ordinamento inverso, attraverso l'argomento *reverse*. Si tratta di un *argomento opzionale*: se non viene valorizzato (con '='), la funzione utilizza un valore di default (in questo caso, *False*).\n", 606 | "\n", 607 | "Vedremo a breve il significato di True e False." 608 | ] 609 | }, 610 | { 611 | "cell_type": "code", 612 | "execution_count": 22, 613 | "metadata": {}, 614 | "outputs": [ 615 | { 616 | "data": { 617 | "text/plain": [ 618 | "[8, 7, 6, 5, 3, 1]" 619 | ] 620 | }, 621 | "execution_count": 22, 622 | "metadata": {}, 623 | "output_type": "execute_result" 624 | } 625 | ], 626 | "source": [ 627 | "numbers = [3,6,1,7,8,5]\n", 628 | "\n", 629 | "sorted(numbers, reverse=True)#argomento opzionale" 630 | ] 631 | }, 632 | { 633 | "cell_type": "markdown", 634 | "metadata": {}, 635 | "source": [ 636 | "Operatori aggregati\n", 637 | "---\n", 638 | "E' possibile eseguire operazioni che coinvolgono tutti gli oggetti contenuti in una lista. Per quanto riguarda le liste numeriche, ad esempio, possiamo sommarli o identificare il minimo e il massimo." 639 | ] 640 | }, 641 | { 642 | "cell_type": "code", 643 | "execution_count": 23, 644 | "metadata": {}, 645 | "outputs": [ 646 | { 647 | "name": "stdout", 648 | "output_type": "stream", 649 | "text": [ 650 | "voto minimo: 22\n", 651 | "voto massimo: 30\n" 652 | ] 653 | } 654 | ], 655 | "source": [ 656 | "grades = [28, 25, 22, 30, 30, 28, 26]\n", 657 | "print('voto minimo:', min(grades))\n", 658 | "print('voto massimo:', max(grades))" 659 | ] 660 | }, 661 | { 662 | "cell_type": "markdown", 663 | "metadata": {}, 664 | "source": [ 665 | "### *Esercizio 2* \n", 666 | "\n", 667 | "Stampare il voto medio col formato qui sopra, usando (anche) la funzione *sum*." 668 | ] 669 | }, 670 | { 671 | "cell_type": "code", 672 | "execution_count": 24, 673 | "metadata": {}, 674 | "outputs": [ 675 | { 676 | "data": { 677 | "text/plain": [ 678 | "15" 679 | ] 680 | }, 681 | "execution_count": 24, 682 | "metadata": {}, 683 | "output_type": "execute_result" 684 | } 685 | ], 686 | "source": [ 687 | "#FILL ME\n", 688 | "sum([10, 5])" 689 | ] 690 | }, 691 | { 692 | "cell_type": "markdown", 693 | "metadata": {}, 694 | "source": [ 695 | "Liste di tipo misto\n", 696 | "---\n", 697 | "In Python, una lista può contenere qualsiasi cosa." 698 | ] 699 | }, 700 | { 701 | "cell_type": "code", 702 | "execution_count": 25, 703 | "metadata": {}, 704 | "outputs": [ 705 | { 706 | "data": { 707 | "text/plain": [ 708 | "['apples', 'oranges', 32, 17]" 709 | ] 710 | }, 711 | "execution_count": 25, 712 | "metadata": {}, 713 | "output_type": "execute_result" 714 | } 715 | ], 716 | "source": [ 717 | "stuff = []\n", 718 | "stuff += ['apples']\n", 719 | "stuff += ['oranges']\n", 720 | "stuff += [32]\n", 721 | "stuff += [17]\n", 722 | "\n", 723 | "stuff" 724 | ] 725 | }, 726 | { 727 | "cell_type": "markdown", 728 | "metadata": {}, 729 | "source": [ 730 | "Anche un'altra lista." 731 | ] 732 | }, 733 | { 734 | "cell_type": "code", 735 | "execution_count": 26, 736 | "metadata": {}, 737 | "outputs": [ 738 | { 739 | "data": { 740 | "text/plain": [ 741 | "['apples', 'oranges', 32, 17, [1, 2, 3, 4]]" 742 | ] 743 | }, 744 | "execution_count": 26, 745 | "metadata": {}, 746 | "output_type": "execute_result" 747 | } 748 | ], 749 | "source": [ 750 | "another_list = [1,2,3,4]\n", 751 | "stuff += [another_list]\n", 752 | "\n", 753 | "stuff" 754 | ] 755 | }, 756 | { 757 | "cell_type": "markdown", 758 | "metadata": {}, 759 | "source": [ 760 | "Attenzione, è diverso da:" 761 | ] 762 | }, 763 | { 764 | "cell_type": "code", 765 | "execution_count": 27, 766 | "metadata": {}, 767 | "outputs": [ 768 | { 769 | "data": { 770 | "text/plain": [ 771 | "['apples', 'oranges', 32, 17, 1, 2, 3, 4]" 772 | ] 773 | }, 774 | "execution_count": 27, 775 | "metadata": {}, 776 | "output_type": "execute_result" 777 | } 778 | ], 779 | "source": [ 780 | "stuff = ['apples', 'oranges', 32, 17]\n", 781 | "\n", 782 | "another_list = [1,2,3,4]\n", 783 | "stuff += another_list\n", 784 | "\n", 785 | "stuff" 786 | ] 787 | }, 788 | { 789 | "cell_type": "markdown", 790 | "metadata": {}, 791 | "source": [ 792 | "L'ordinamento usa in modo dinamico l'operatore \"<\", che non è definito su tutte le coppie di tipi." 793 | ] 794 | }, 795 | { 796 | "cell_type": "code", 797 | "execution_count": 28, 798 | "metadata": {}, 799 | "outputs": [ 800 | { 801 | "ename": "TypeError", 802 | "evalue": "'<' not supported between instances of 'int' and 'str'", 803 | "output_type": "error", 804 | "traceback": [ 805 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 806 | "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", 807 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msorted\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mstuff\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", 808 | "\u001b[0;31mTypeError\u001b[0m: '<' not supported between instances of 'int' and 'str'" 809 | ] 810 | } 811 | ], 812 | "source": [ 813 | "print(sorted(stuff))" 814 | ] 815 | }, 816 | { 817 | "cell_type": "markdown", 818 | "metadata": {}, 819 | "source": [ 820 | "*Slicing*\n", 821 | "---\n", 822 | "Python permette l'estrazione di sottoliste (slicing) in modo compatto. " 823 | ] 824 | }, 825 | { 826 | "cell_type": "code", 827 | "execution_count": 29, 828 | "metadata": {}, 829 | "outputs": [], 830 | "source": [ 831 | "letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']" 832 | ] 833 | }, 834 | { 835 | "cell_type": "code", 836 | "execution_count": 30, 837 | "metadata": {}, 838 | "outputs": [ 839 | { 840 | "data": { 841 | "text/plain": [ 842 | "['a', 'b', 'c']" 843 | ] 844 | }, 845 | "execution_count": 30, 846 | "metadata": {}, 847 | "output_type": "execute_result" 848 | } 849 | ], 850 | "source": [ 851 | "letters[:3]#'le prime 3' / 'fino alla terza (inclusa)'" 852 | ] 853 | }, 854 | { 855 | "cell_type": "code", 856 | "execution_count": 31, 857 | "metadata": {}, 858 | "outputs": [ 859 | { 860 | "data": { 861 | "text/plain": [ 862 | "['d', 'e', 'f', 'g', 'h']" 863 | ] 864 | }, 865 | "execution_count": 31, 866 | "metadata": {}, 867 | "output_type": "execute_result" 868 | } 869 | ], 870 | "source": [ 871 | "letters[3:]#'dalla terza (esclusa) in poi'" 872 | ] 873 | }, 874 | { 875 | "cell_type": "code", 876 | "execution_count": 32, 877 | "metadata": {}, 878 | "outputs": [ 879 | { 880 | "data": { 881 | "text/plain": [ 882 | "['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']" 883 | ] 884 | }, 885 | "execution_count": 32, 886 | "metadata": {}, 887 | "output_type": "execute_result" 888 | } 889 | ], 890 | "source": [ 891 | "letters[:3] + letters[3:]" 892 | ] 893 | }, 894 | { 895 | "cell_type": "code", 896 | "execution_count": 33, 897 | "metadata": {}, 898 | "outputs": [ 899 | { 900 | "data": { 901 | "text/plain": [ 902 | "['d', 'e', 'f']" 903 | ] 904 | }, 905 | "execution_count": 33, 906 | "metadata": {}, 907 | "output_type": "execute_result" 908 | } 909 | ], 910 | "source": [ 911 | "letters[3:6]" 912 | ] 913 | }, 914 | { 915 | "cell_type": "markdown", 916 | "metadata": {}, 917 | "source": [ 918 | "*Esercizio 3*\n", 919 | "---\n", 920 | "Giocare un po' con le liste e con le operazioni che abbiamo visto:\n", 921 | "\n", 922 | "- creare una lista vuota e riempirla\n", 923 | "- inserirci, modificarne e cancellarne elementi\n", 924 | "- concatenarla con un'altra lista\n", 925 | "- inserirle un'altra lista come nuovo elemento\n", 926 | "- ordinarla in modo naturale e inverso\n", 927 | "- estrarne delle porzioni e assegnarle a variabili differenti\n", 928 | "- ricombinare le porzioni ottenute\n", 929 | "- ..." 930 | ] 931 | }, 932 | { 933 | "cell_type": "code", 934 | "execution_count": 34, 935 | "metadata": {}, 936 | "outputs": [], 937 | "source": [ 938 | "#FILL ME" 939 | ] 940 | }, 941 | { 942 | "cell_type": "markdown", 943 | "metadata": {}, 944 | "source": [ 945 | "Cicli **for**\n", 946 | "===\n", 947 | "Nella programmazione, un *ciclo* è un costrutto in cui una o più operazioni sono eseguite più volte.\n", 948 | "\n", 949 | "L'accesso ordinato agli elementi di una lista attraverso un ciclo *for* è un esempio di questo costrutto." 950 | ] 951 | }, 952 | { 953 | "cell_type": "code", 954 | "execution_count": 35, 955 | "metadata": {}, 956 | "outputs": [ 957 | { 958 | "name": "stdout", 959 | "output_type": "stream", 960 | "text": [ 961 | "triangle\n", 962 | "square\n", 963 | "circle\n", 964 | "hexagon\n" 965 | ] 966 | } 967 | ], 968 | "source": [ 969 | "shapes = ['triangle', 'square', 'circle', 'hexagon']\n", 970 | "\n", 971 | "for shape in shapes:\n", 972 | " print(shape)#codice indentato" 973 | ] 974 | }, 975 | { 976 | "cell_type": "markdown", 977 | "metadata": {}, 978 | "source": [ 979 | "**Nota**: come per le funzioni, l'*indentazione* del codice è obbligatoria." 980 | ] 981 | }, 982 | { 983 | "cell_type": "markdown", 984 | "metadata": {}, 985 | "source": [ 986 | "Nel codice qui sopra, *shape* contiene, ad ogni iterazione del ciclo, un elemento della lista. E' una variabile, e può avere un nome qualsiasi." 987 | ] 988 | }, 989 | { 990 | "cell_type": "code", 991 | "execution_count": 36, 992 | "metadata": {}, 993 | "outputs": [ 994 | { 995 | "name": "stdout", 996 | "output_type": "stream", 997 | "text": [ 998 | "triangle\n", 999 | "square\n", 1000 | "circle\n", 1001 | "hexagon\n" 1002 | ] 1003 | } 1004 | ], 1005 | "source": [ 1006 | "shapes = ['triangle', 'square', 'circle', 'hexagon']\n", 1007 | "\n", 1008 | "for x in shapes:\n", 1009 | " print(x)" 1010 | ] 1011 | }, 1012 | { 1013 | "cell_type": "markdown", 1014 | "metadata": {}, 1015 | "source": [ 1016 | "Enumerazione\n", 1017 | "---\n", 1018 | "Supponiamo di voler conoscere l'indice dell'iterazione corrente. In altre parole, oltre all'elemento, vogliamo conoscere anche la sua posizione nella lista." 1019 | ] 1020 | }, 1021 | { 1022 | "cell_type": "code", 1023 | "execution_count": 37, 1024 | "metadata": {}, 1025 | "outputs": [ 1026 | { 1027 | "name": "stdout", 1028 | "output_type": "stream", 1029 | "text": [ 1030 | "L'elemento in posizione 0 è triangle\n", 1031 | "L'elemento in posizione 1 è square\n", 1032 | "L'elemento in posizione 2 è circle\n", 1033 | "L'elemento in posizione 3 è hexagon\n" 1034 | ] 1035 | } 1036 | ], 1037 | "source": [ 1038 | "shapes = ['triangle', 'square', 'circle', 'hexagon']\n", 1039 | "counter = 0\n", 1040 | "\n", 1041 | "for shape in shapes:\n", 1042 | " print(\"L'elemento in posizione {} è {}\".format(counter, shape))\n", 1043 | " counter += 1" 1044 | ] 1045 | }, 1046 | { 1047 | "cell_type": "markdown", 1048 | "metadata": {}, 1049 | "source": [ 1050 | "Quanto sopra si può ottenere in modo più compatto grazie alla funzione *enumerate*:\n", 1051 | "\n", 1052 | " for index, element in enumerate(list):\n", 1053 | " ..." 1054 | ] 1055 | }, 1056 | { 1057 | "cell_type": "code", 1058 | "execution_count": 38, 1059 | "metadata": {}, 1060 | "outputs": [ 1061 | { 1062 | "name": "stdout", 1063 | "output_type": "stream", 1064 | "text": [ 1065 | "L'elemento in posizione 0 è triangle\n", 1066 | "L'elemento in posizione 1 è square\n", 1067 | "L'elemento in posizione 2 è circle\n", 1068 | "L'elemento in posizione 3 è hexagon\n" 1069 | ] 1070 | } 1071 | ], 1072 | "source": [ 1073 | "shapes = ['triangle', 'square', 'circle', 'hexagon']\n", 1074 | "\n", 1075 | "for counter, shape in enumerate(shapes):#prima indice, poi elemento\n", 1076 | " print(\"L'elemento in posizione {} è {}\".format(counter, shape))" 1077 | ] 1078 | }, 1079 | { 1080 | "cell_type": "markdown", 1081 | "metadata": {}, 1082 | "source": [ 1083 | "Al solito, *counter* e *shape* sono solo nomi (qualsiasi) di variabile. Il loro ordine è invece obbligatorio." 1084 | ] 1085 | }, 1086 | { 1087 | "cell_type": "code", 1088 | "execution_count": 39, 1089 | "metadata": {}, 1090 | "outputs": [ 1091 | { 1092 | "name": "stdout", 1093 | "output_type": "stream", 1094 | "text": [ 1095 | "L'elemento in posizione 0 è triangle\n", 1096 | "L'elemento in posizione 1 è square\n", 1097 | "L'elemento in posizione 2 è circle\n", 1098 | "L'elemento in posizione 3 è hexagon\n" 1099 | ] 1100 | } 1101 | ], 1102 | "source": [ 1103 | "shapes = ['triangle', 'square', 'circle', 'hexagon']\n", 1104 | "\n", 1105 | "for i, x in enumerate(shapes):#prima indice, poi elemento\n", 1106 | " print(\"L'elemento in posizione {} è {}\".format(i, x))" 1107 | ] 1108 | }, 1109 | { 1110 | "cell_type": "markdown", 1111 | "metadata": {}, 1112 | "source": [ 1113 | "**Nota**: tutto quello che è indentato sotto il ciclo for viene eseguito ad ogni iterazione." 1114 | ] 1115 | }, 1116 | { 1117 | "cell_type": "code", 1118 | "execution_count": 40, 1119 | "metadata": {}, 1120 | "outputs": [ 1121 | { 1122 | "name": "stdout", 1123 | "output_type": "stream", 1124 | "text": [ 1125 | "L'elemento in posizione 0 è triangle\n", 1126 | "Ciao mamma!\n", 1127 | "L'elemento in posizione 1 è square\n", 1128 | "Ciao mamma!\n", 1129 | "L'elemento in posizione 2 è circle\n", 1130 | "Ciao mamma!\n", 1131 | "L'elemento in posizione 3 è hexagon\n", 1132 | "Ciao mamma!\n" 1133 | ] 1134 | } 1135 | ], 1136 | "source": [ 1137 | "a = 'Ciao mamma!'\n", 1138 | "shapes = ['triangle', 'square', 'circle', 'hexagon']\n", 1139 | "\n", 1140 | "for index, element in enumerate(shapes):\n", 1141 | " print(\"L'elemento in posizione {} è {}\".format(index, element))\n", 1142 | " print(a)#dentro il ciclo" 1143 | ] 1144 | }, 1145 | { 1146 | "cell_type": "code", 1147 | "execution_count": 41, 1148 | "metadata": {}, 1149 | "outputs": [ 1150 | { 1151 | "name": "stdout", 1152 | "output_type": "stream", 1153 | "text": [ 1154 | "L'elemento in posizione 0 è triangle\n", 1155 | "L'elemento in posizione 1 è square\n", 1156 | "L'elemento in posizione 2 è circle\n", 1157 | "L'elemento in posizione 3 è hexagon\n", 1158 | "Ciao mamma!\n" 1159 | ] 1160 | } 1161 | ], 1162 | "source": [ 1163 | "a = 'Ciao mamma!'\n", 1164 | "shapes = ['triangle', 'square', 'circle', 'hexagon']\n", 1165 | "\n", 1166 | "for index, element in enumerate(shapes):#prima indice, poi elemento\n", 1167 | " print(\"L'elemento in posizione {} è {}\".format(index, element))\n", 1168 | "\n", 1169 | "print(a)#fuori dal ciclo" 1170 | ] 1171 | }, 1172 | { 1173 | "cell_type": "markdown", 1174 | "metadata": {}, 1175 | "source": [ 1176 | "*Esercizio 4*\n", 1177 | "---\n", 1178 | "\n", 1179 | "- creare una lista di numeri interi, float o misti\n", 1180 | "- iterare sui numeri della lista, stampandoli insieme al loro indice\n", 1181 | "- inserire in una lista di appoggio i quadrati dei numeri della lista\n", 1182 | "- stampare la nuova lista per verificarne contenuto\n", 1183 | "- come buona pratica, commentare il codice" 1184 | ] 1185 | }, 1186 | { 1187 | "cell_type": "code", 1188 | "execution_count": 42, 1189 | "metadata": {}, 1190 | "outputs": [ 1191 | { 1192 | "name": "stdout", 1193 | "output_type": "stream", 1194 | "text": [ 1195 | "100\n" 1196 | ] 1197 | } 1198 | ], 1199 | "source": [ 1200 | "#FILL ME\n", 1201 | "print(10**2)#operatore 'al quadrato'" 1202 | ] 1203 | }, 1204 | { 1205 | "cell_type": "markdown", 1206 | "metadata": {}, 1207 | "source": [ 1208 | "Comprensioni di liste\n", 1209 | "---\n", 1210 | "Come abbiamo visto nell'esercizio precedente, utilizzare un ciclo per costruire una lista a partire da un'altra è un po' macchinoso." 1211 | ] 1212 | }, 1213 | { 1214 | "cell_type": "code", 1215 | "execution_count": 43, 1216 | "metadata": {}, 1217 | "outputs": [ 1218 | { 1219 | "name": "stdout", 1220 | "output_type": "stream", 1221 | "text": [ 1222 | "['Francesco', 'Elisa', 'Alessandro', 'Giovanni', 'Maria teresa']\n" 1223 | ] 1224 | } 1225 | ], 1226 | "source": [ 1227 | "names = ['francesco', 'elisa', 'alessandro', 'giovanni', 'maria teresa']\n", 1228 | "capitalized_names = []#lista di appoggio\n", 1229 | "\n", 1230 | "for n in names:\n", 1231 | " capitalized_names += [n.capitalize()]#riempio lista di appoggio\n", 1232 | " \n", 1233 | "print(capitalized_names)" 1234 | ] 1235 | }, 1236 | { 1237 | "cell_type": "markdown", 1238 | "metadata": {}, 1239 | "source": [ 1240 | "Una *comprensione* esegue il ciclo qui sopra in una riga:\n", 1241 | "\n", 1242 | " [f(x) for x in list] \n", 1243 | "\n", 1244 | "In questo modo è facile derivare nuove liste da una di partenza. La comprensione di lista è uno dei costrutti più eleganti di Python, ed è molto utilizzato." 1245 | ] 1246 | }, 1247 | { 1248 | "cell_type": "code", 1249 | "execution_count": 44, 1250 | "metadata": {}, 1251 | "outputs": [ 1252 | { 1253 | "data": { 1254 | "text/plain": [ 1255 | "['Francesco', 'Elisa', 'Alessandro', 'Giovanni', 'Maria teresa']" 1256 | ] 1257 | }, 1258 | "execution_count": 44, 1259 | "metadata": {}, 1260 | "output_type": "execute_result" 1261 | } 1262 | ], 1263 | "source": [ 1264 | "capitalized_names = [n.capitalize() for n in names]\n", 1265 | "\n", 1266 | "capitalized_names" 1267 | ] 1268 | }, 1269 | { 1270 | "cell_type": "code", 1271 | "execution_count": 45, 1272 | "metadata": {}, 1273 | "outputs": [ 1274 | { 1275 | "data": { 1276 | "text/plain": [ 1277 | "['F', 'E', 'A', 'G', 'M']" 1278 | ] 1279 | }, 1280 | "execution_count": 45, 1281 | "metadata": {}, 1282 | "output_type": "execute_result" 1283 | } 1284 | ], 1285 | "source": [ 1286 | "capitalized_initials = [n.capitalize()[0] for n in names]\n", 1287 | "\n", 1288 | "capitalized_initials" 1289 | ] 1290 | }, 1291 | { 1292 | "cell_type": "markdown", 1293 | "metadata": {}, 1294 | "source": [ 1295 | "*Esercizio 5*\n", 1296 | "--\n", 1297 | "La comprensione di lista può essere combinata all'enumerazione:\n", 1298 | "\n", 1299 | " [f(index, element) for index, element in enumerate(list)]" 1300 | ] 1301 | }, 1302 | { 1303 | "cell_type": "code", 1304 | "execution_count": 46, 1305 | "metadata": {}, 1306 | "outputs": [ 1307 | { 1308 | "data": { 1309 | "text/plain": [ 1310 | "[[0, 'francesco'],\n", 1311 | " [1, 'elisa'],\n", 1312 | " [2, 'alessandro'],\n", 1313 | " [3, 'giovanni'],\n", 1314 | " [4, 'maria teresa']]" 1315 | ] 1316 | }, 1317 | "execution_count": 46, 1318 | "metadata": {}, 1319 | "output_type": "execute_result" 1320 | } 1321 | ], 1322 | "source": [ 1323 | "indexed_names = [[i, n] for i, n in enumerate(names)]\n", 1324 | "\n", 1325 | "indexed_names" 1326 | ] 1327 | }, 1328 | { 1329 | "cell_type": "markdown", 1330 | "metadata": {}, 1331 | "source": [ 1332 | "Ripetere l'enumerazione della cella precedente stampando i nomi in ordine alfabetico. Suggerimento: è sufficiente una riga di codice." 1333 | ] 1334 | }, 1335 | { 1336 | "cell_type": "code", 1337 | "execution_count": null, 1338 | "metadata": {}, 1339 | "outputs": [], 1340 | "source": [ 1341 | "indexed_sorted_names = #FILL ME\n", 1342 | "indexed_sorted_names" 1343 | ] 1344 | }, 1345 | { 1346 | "cell_type": "markdown", 1347 | "metadata": {}, 1348 | "source": [ 1349 | "*Esercizio 6*\n", 1350 | "---\n", 1351 | "Ripetere l'esercizio 4 (senza la stampa) utilizzando una comprensione di lista." 1352 | ] 1353 | }, 1354 | { 1355 | "cell_type": "code", 1356 | "execution_count": 48, 1357 | "metadata": {}, 1358 | "outputs": [], 1359 | "source": [ 1360 | "#FILL ME" 1361 | ] 1362 | }, 1363 | { 1364 | "cell_type": "markdown", 1365 | "metadata": {}, 1366 | "source": [ 1367 | "\n", 1375 | "\n", 1376 | "
\n", 1377 | "Created with Jupyter.\n", 1378 | "
" 1379 | ] 1380 | } 1381 | ], 1382 | "metadata": { 1383 | "kernelspec": { 1384 | "display_name": "Python 3", 1385 | "language": "python", 1386 | "name": "python3" 1387 | }, 1388 | "language_info": { 1389 | "codemirror_mode": { 1390 | "name": "ipython", 1391 | "version": 3 1392 | }, 1393 | "file_extension": ".py", 1394 | "mimetype": "text/x-python", 1395 | "name": "python", 1396 | "nbconvert_exporter": "python", 1397 | "pygments_lexer": "ipython3", 1398 | "version": "3.8.5" 1399 | } 1400 | }, 1401 | "nbformat": 4, 1402 | "nbformat_minor": 2 1403 | } 1404 | -------------------------------------------------------------------------------- /4. Condizioni, valori e operatori booleani.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "*Contenuti*\n", 8 | "===\n", 9 | "- [Il costrutto if-elif-else](#Il-costrutto-if-elif-else)\n", 10 | " - [*if*](#if)\n", 11 | " - [*else*](#else)\n", 12 | " - [*elif*](#elif)\n", 13 | "- [if e comprensioni di liste](#if-e-comprensioni-di-liste)\n", 14 | "- [Test logici](#Test-logici)\n", 15 | "- [Operatori booleani](#Operatori-booleani)\n", 16 | "- [*Esercizio 1*](#Esercizio-1)\n", 17 | "- [*Esercizio 2*](#Esercizio-2)" 18 | ] 19 | }, 20 | { 21 | "cell_type": "markdown", 22 | "metadata": {}, 23 | "source": [ 24 | "Il costrutto *if-elif-else*\n", 25 | "===" 26 | ] 27 | }, 28 | { 29 | "cell_type": "markdown", 30 | "metadata": {}, 31 | "source": [ 32 | "*if*\n", 33 | "---\n", 34 | "Attraverso la keyword *if* si testano una o più condizioni." 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": 1, 40 | "metadata": {}, 41 | "outputs": [ 42 | { 43 | "name": "stdout", 44 | "output_type": "stream", 45 | "text": [ 46 | "8 è un numero pari\n" 47 | ] 48 | } 49 | ], 50 | "source": [ 51 | "number = 8\n", 52 | "\n", 53 | "if number % 2 == 0:#'%' è l'operatore 'modulo', il resto della divisione per un intero\n", 54 | " print(number, 'è un numero pari')" 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": 2, 60 | "metadata": {}, 61 | "outputs": [ 62 | { 63 | "name": "stdout", 64 | "output_type": "stream", 65 | "text": [ 66 | "18 è un numero pari ed è multiplo di 3\n" 67 | ] 68 | } 69 | ], 70 | "source": [ 71 | "number = 18\n", 72 | "\n", 73 | "if number % 2 == 0 and number % 3 == 0:#condizione multipla\n", 74 | " print(number, 'è un numero pari ed è multiplo di 3')" 75 | ] 76 | }, 77 | { 78 | "cell_type": "markdown", 79 | "metadata": {}, 80 | "source": [ 81 | "*else*\n", 82 | "---\n", 83 | "Attraverso la keyword *else*, possiamo associare un'azione all'evento di fallimento della condizione testata da if." 84 | ] 85 | }, 86 | { 87 | "cell_type": "code", 88 | "execution_count": 3, 89 | "metadata": {}, 90 | "outputs": [ 91 | { 92 | "name": "stdout", 93 | "output_type": "stream", 94 | "text": [ 95 | "7 è un numero dispari\n" 96 | ] 97 | } 98 | ], 99 | "source": [ 100 | "number = 7\n", 101 | "\n", 102 | "if number % 2 == 0:\n", 103 | " print(number, 'è un numero pari')\n", 104 | "else:\n", 105 | " print(number, 'è un numero dispari')" 106 | ] 107 | }, 108 | { 109 | "cell_type": "markdown", 110 | "metadata": {}, 111 | "source": [ 112 | "*elif*\n", 113 | "---\n", 114 | "Se vogliamo testare una serie di condizioni (piuttosto che una del tipo *A o non A*) utilizziamo *elif*, contrazione di \"else if\"." 115 | ] 116 | }, 117 | { 118 | "cell_type": "code", 119 | "execution_count": 4, 120 | "metadata": {}, 121 | "outputs": [ 122 | { 123 | "name": "stdout", 124 | "output_type": "stream", 125 | "text": [ 126 | "ciao è di tipo stringa\n", 127 | "5 è di tipo intero\n", 128 | "4.7 non è né stringa, né intero, né lista!\n", 129 | "mamma è di tipo stringa\n", 130 | "[4, 5, 6] è di tipo list\n" 131 | ] 132 | } 133 | ], 134 | "source": [ 135 | "mixed_list = ['ciao', 5, 4.7, 'mamma', [4,5,6]]\n", 136 | "\n", 137 | "for element in mixed_list:\n", 138 | " \n", 139 | " if type(element) == str:\n", 140 | " print(element, 'è di tipo stringa')\n", 141 | " \n", 142 | " elif type(element) == int:\n", 143 | " print(element, 'è di tipo intero')\n", 144 | " \n", 145 | " elif type(element) == list:\n", 146 | " print(element, 'è di tipo list')\n", 147 | " \n", 148 | " else:\n", 149 | " print(element, 'non è né stringa, né intero, né lista!')" 150 | ] 151 | }, 152 | { 153 | "cell_type": "markdown", 154 | "metadata": {}, 155 | "source": [ 156 | "Nel costrutto if-elif-else l'unico else viene eseguito solo quando tutte le altre condizioni (testate da if ed elif) falliscono. Se una della condizioni testate si verifica, quelle successive vengono ignorate." 157 | ] 158 | }, 159 | { 160 | "cell_type": "markdown", 161 | "metadata": {}, 162 | "source": [ 163 | "if e comprensioni di liste\n", 164 | "===\n", 165 | "Il test di una condizione è particolarmente comodo quando si vuole derivare una lista da un'altra attraverso una comprensione." 166 | ] 167 | }, 168 | { 169 | "cell_type": "code", 170 | "execution_count": 5, 171 | "metadata": {}, 172 | "outputs": [ 173 | { 174 | "data": { 175 | "text/plain": [ 176 | "['ciao', 5, 4.7, 'mamma', [4, 5, 6]]" 177 | ] 178 | }, 179 | "execution_count": 5, 180 | "metadata": {}, 181 | "output_type": "execute_result" 182 | } 183 | ], 184 | "source": [ 185 | "mixed_list = ['ciao', 5, 4.7, 'mamma', [4,5,6]]\n", 186 | "\n", 187 | "[x for x in mixed_list]#lista derivata da (e uguale a) una di partenza" 188 | ] 189 | }, 190 | { 191 | "cell_type": "code", 192 | "execution_count": 6, 193 | "metadata": {}, 194 | "outputs": [ 195 | { 196 | "data": { 197 | "text/plain": [ 198 | "['ciao', 'mamma']" 199 | ] 200 | }, 201 | "execution_count": 6, 202 | "metadata": {}, 203 | "output_type": "execute_result" 204 | } 205 | ], 206 | "source": [ 207 | "strings_only = [x for x in mixed_list if type(x) == str]#solo le stringhe\n", 208 | "\n", 209 | "strings_only" 210 | ] 211 | }, 212 | { 213 | "cell_type": "markdown", 214 | "metadata": {}, 215 | "source": [ 216 | "Test logici\n", 217 | "===\n", 218 | "Le condizioni testate da if ed elif possono essere vere (*True*) o false (*False*). In Python, la risposta al test di una condizione è di tipo *booleano*. Vediamo qualche esempio." 219 | ] 220 | }, 221 | { 222 | "cell_type": "code", 223 | "execution_count": 7, 224 | "metadata": {}, 225 | "outputs": [ 226 | { 227 | "data": { 228 | "text/plain": [ 229 | "False" 230 | ] 231 | }, 232 | "execution_count": 7, 233 | "metadata": {}, 234 | "output_type": "execute_result" 235 | } 236 | ], 237 | "source": [ 238 | "a = 5\n", 239 | "b = 7\n", 240 | "\n", 241 | "a == b#test di uguaglianza" 242 | ] 243 | }, 244 | { 245 | "cell_type": "code", 246 | "execution_count": 8, 247 | "metadata": {}, 248 | "outputs": [ 249 | { 250 | "data": { 251 | "text/plain": [ 252 | "bool" 253 | ] 254 | }, 255 | "execution_count": 8, 256 | "metadata": {}, 257 | "output_type": "execute_result" 258 | } 259 | ], 260 | "source": [ 261 | "type(a == b)" 262 | ] 263 | }, 264 | { 265 | "cell_type": "code", 266 | "execution_count": 9, 267 | "metadata": {}, 268 | "outputs": [ 269 | { 270 | "data": { 271 | "text/plain": [ 272 | "bool" 273 | ] 274 | }, 275 | "execution_count": 9, 276 | "metadata": {}, 277 | "output_type": "execute_result" 278 | } 279 | ], 280 | "source": [ 281 | "type(True)" 282 | ] 283 | }, 284 | { 285 | "cell_type": "code", 286 | "execution_count": 10, 287 | "metadata": {}, 288 | "outputs": [ 289 | { 290 | "data": { 291 | "text/plain": [ 292 | "bool" 293 | ] 294 | }, 295 | "execution_count": 10, 296 | "metadata": {}, 297 | "output_type": "execute_result" 298 | } 299 | ], 300 | "source": [ 301 | "type(False)" 302 | ] 303 | }, 304 | { 305 | "cell_type": "code", 306 | "execution_count": 11, 307 | "metadata": {}, 308 | "outputs": [ 309 | { 310 | "data": { 311 | "text/plain": [ 312 | "True" 313 | ] 314 | }, 315 | "execution_count": 11, 316 | "metadata": {}, 317 | "output_type": "execute_result" 318 | } 319 | ], 320 | "source": [ 321 | "c = 5\n", 322 | "\n", 323 | "a >= c" 324 | ] 325 | }, 326 | { 327 | "cell_type": "code", 328 | "execution_count": 12, 329 | "metadata": {}, 330 | "outputs": [ 331 | { 332 | "data": { 333 | "text/plain": [ 334 | "False" 335 | ] 336 | }, 337 | "execution_count": 12, 338 | "metadata": {}, 339 | "output_type": "execute_result" 340 | } 341 | ], 342 | "source": [ 343 | "a > c" 344 | ] 345 | }, 346 | { 347 | "cell_type": "code", 348 | "execution_count": 13, 349 | "metadata": {}, 350 | "outputs": [ 351 | { 352 | "data": { 353 | "text/plain": [ 354 | "True" 355 | ] 356 | }, 357 | "execution_count": 13, 358 | "metadata": {}, 359 | "output_type": "execute_result" 360 | } 361 | ], 362 | "source": [ 363 | "a != b#'diverso da' (test di non uguaglianza)" 364 | ] 365 | }, 366 | { 367 | "cell_type": "code", 368 | "execution_count": 14, 369 | "metadata": {}, 370 | "outputs": [ 371 | { 372 | "data": { 373 | "text/plain": [ 374 | "True" 375 | ] 376 | }, 377 | "execution_count": 14, 378 | "metadata": {}, 379 | "output_type": "execute_result" 380 | } 381 | ], 382 | "source": [ 383 | "lst = [3,6,2,10]\n", 384 | "\n", 385 | "3 in lst#test di inclusione" 386 | ] 387 | }, 388 | { 389 | "cell_type": "code", 390 | "execution_count": 15, 391 | "metadata": {}, 392 | "outputs": [ 393 | { 394 | "data": { 395 | "text/plain": [ 396 | "False" 397 | ] 398 | }, 399 | "execution_count": 15, 400 | "metadata": {}, 401 | "output_type": "execute_result" 402 | } 403 | ], 404 | "source": [ 405 | "7 in lst" 406 | ] 407 | }, 408 | { 409 | "cell_type": "markdown", 410 | "metadata": {}, 411 | "source": [ 412 | "Operatori booleani\n", 413 | "===\n", 414 | "Le condizioni booleane si possono combinare in vari modi attraverso gli *operatori booleani*.\n", 415 | "\n", 416 | "Come abbiamo visto all'[inizio](#if) della lezione, usiamo l'operatore *and* se vogliamo verificare CONTEMPORANEAMENTE due o più condizioni." 417 | ] 418 | }, 419 | { 420 | "cell_type": "code", 421 | "execution_count": 16, 422 | "metadata": {}, 423 | "outputs": [ 424 | { 425 | "data": { 426 | "text/plain": [ 427 | "True" 428 | ] 429 | }, 430 | "execution_count": 16, 431 | "metadata": {}, 432 | "output_type": "execute_result" 433 | } 434 | ], 435 | "source": [ 436 | "number = 7\n", 437 | "\n", 438 | "number > 5 and number < 10" 439 | ] 440 | }, 441 | { 442 | "cell_type": "code", 443 | "execution_count": 17, 444 | "metadata": {}, 445 | "outputs": [ 446 | { 447 | "data": { 448 | "text/plain": [ 449 | "False" 450 | ] 451 | }, 452 | "execution_count": 17, 453 | "metadata": {}, 454 | "output_type": "execute_result" 455 | } 456 | ], 457 | "source": [ 458 | "number = 4\n", 459 | "\n", 460 | "number > 5 and number < 10" 461 | ] 462 | }, 463 | { 464 | "cell_type": "code", 465 | "execution_count": 18, 466 | "metadata": {}, 467 | "outputs": [ 468 | { 469 | "data": { 470 | "text/plain": [ 471 | "False" 472 | ] 473 | }, 474 | "execution_count": 18, 475 | "metadata": {}, 476 | "output_type": "execute_result" 477 | } 478 | ], 479 | "source": [ 480 | "number = 12\n", 481 | "\n", 482 | "number > 5 and number < 10" 483 | ] 484 | }, 485 | { 486 | "cell_type": "markdown", 487 | "metadata": {}, 488 | "source": [ 489 | "Il test di due condizioni legate da *or*, invece, passerà se ALMENO UNA delle due si verifica." 490 | ] 491 | }, 492 | { 493 | "cell_type": "code", 494 | "execution_count": 19, 495 | "metadata": {}, 496 | "outputs": [ 497 | { 498 | "data": { 499 | "text/plain": [ 500 | "True" 501 | ] 502 | }, 503 | "execution_count": 19, 504 | "metadata": {}, 505 | "output_type": "execute_result" 506 | } 507 | ], 508 | "source": [ 509 | "number = 4\n", 510 | "\n", 511 | "number > 5 or number % 2 == 0" 512 | ] 513 | }, 514 | { 515 | "cell_type": "code", 516 | "execution_count": 20, 517 | "metadata": {}, 518 | "outputs": [ 519 | { 520 | "data": { 521 | "text/plain": [ 522 | "True" 523 | ] 524 | }, 525 | "execution_count": 20, 526 | "metadata": {}, 527 | "output_type": "execute_result" 528 | } 529 | ], 530 | "source": [ 531 | "number = 33\n", 532 | "\n", 533 | "number > 5 or number % 2 == 0" 534 | ] 535 | }, 536 | { 537 | "cell_type": "code", 538 | "execution_count": 21, 539 | "metadata": {}, 540 | "outputs": [ 541 | { 542 | "data": { 543 | "text/plain": [ 544 | "False" 545 | ] 546 | }, 547 | "execution_count": 21, 548 | "metadata": {}, 549 | "output_type": "execute_result" 550 | } 551 | ], 552 | "source": [ 553 | "number = 3\n", 554 | "\n", 555 | "number > 5 or number % 2 == 0" 556 | ] 557 | }, 558 | { 559 | "cell_type": "markdown", 560 | "metadata": {}, 561 | "source": [ 562 | "Infine, l'operatore *not* nega una condizione." 563 | ] 564 | }, 565 | { 566 | "cell_type": "code", 567 | "execution_count": 22, 568 | "metadata": {}, 569 | "outputs": [ 570 | { 571 | "data": { 572 | "text/plain": [ 573 | "True" 574 | ] 575 | }, 576 | "execution_count": 22, 577 | "metadata": {}, 578 | "output_type": "execute_result" 579 | } 580 | ], 581 | "source": [ 582 | "number = 10\n", 583 | "\n", 584 | "not type(number) == str" 585 | ] 586 | }, 587 | { 588 | "cell_type": "code", 589 | "execution_count": 23, 590 | "metadata": {}, 591 | "outputs": [ 592 | { 593 | "name": "stdout", 594 | "output_type": "stream", 595 | "text": [ 596 | "True\n", 597 | "False\n", 598 | "True\n", 599 | "False\n" 600 | ] 601 | } 602 | ], 603 | "source": [ 604 | "number = 5\n", 605 | "print(number > 2)\n", 606 | "print(not number > 2)\n", 607 | "print(not not number > 2)\n", 608 | "print(not not not number > 2)\n", 609 | "#..." 610 | ] 611 | }, 612 | { 613 | "cell_type": "code", 614 | "execution_count": 24, 615 | "metadata": {}, 616 | "outputs": [ 617 | { 618 | "data": { 619 | "text/plain": [ 620 | "True" 621 | ] 622 | }, 623 | "execution_count": 24, 624 | "metadata": {}, 625 | "output_type": "execute_result" 626 | } 627 | ], 628 | "source": [ 629 | "number = 5\n", 630 | "number < 10 and not number % 2 == 0" 631 | ] 632 | }, 633 | { 634 | "cell_type": "markdown", 635 | "metadata": {}, 636 | "source": [ 637 | "*Esercizio 1*\n", 638 | "===\n", 639 | "Iterando su una lista di numeri interi,\n", 640 | "- se il quadrato del numero corrente è multiplo sia di 2 che di 3, stampare\n", 641 | " Il quadrato di ... è ..., che è multiplo sia di 2 che di 3\n", 642 | "- se il quadrato del numero corrente è multiplo di 2 ma non di 3, stampare\n", 643 | " Il quadrato di ... è ..., che è multiplo di 2 ma non di 3\n", 644 | "- se il quadrato del numero corrente è multiplo di 3 ma non di 2, stampare\n", 645 | " Il quadrato di ... è ..., che è multiplo di 3 ma non di 2\n", 646 | "- se il quadrato del numero corrente non è multiplo né di 2 né di 3, stampare\n", 647 | " Il quadrato di ... è ..., che non è multiplo né di 2 né di 3" 648 | ] 649 | }, 650 | { 651 | "cell_type": "code", 652 | "execution_count": 25, 653 | "metadata": {}, 654 | "outputs": [], 655 | "source": [ 656 | "lst = [3,6,5,8,12]\n", 657 | "\n", 658 | "#FILL ME" 659 | ] 660 | }, 661 | { 662 | "cell_type": "markdown", 663 | "metadata": {}, 664 | "source": [ 665 | "*Esercizio 2*\n", 666 | "===\n", 667 | "A partire dalla lista di numeri dell'esercizio precedente,\n", 668 | "- derivare la lista dei quadrati che sono multipli di 2\n", 669 | "- derivare la lista dei quadrati che sono multipli di 3\n", 670 | "- derivare la lista dei quadrati che sono multipli di 2 e non di 3" 671 | ] 672 | }, 673 | { 674 | "cell_type": "code", 675 | "execution_count": 26, 676 | "metadata": {}, 677 | "outputs": [], 678 | "source": [ 679 | "lst = [3,6,5,8,12]\n", 680 | "\n", 681 | "#FILL ME" 682 | ] 683 | }, 684 | { 685 | "cell_type": "markdown", 686 | "metadata": {}, 687 | "source": [ 688 | "\n", 696 | "\n", 697 | "
\n", 698 | "Created with Jupyter.\n", 699 | "
" 700 | ] 701 | } 702 | ], 703 | "metadata": { 704 | "kernelspec": { 705 | "display_name": "Python 3", 706 | "language": "python", 707 | "name": "python3" 708 | }, 709 | "language_info": { 710 | "codemirror_mode": { 711 | "name": "ipython", 712 | "version": 3 713 | }, 714 | "file_extension": ".py", 715 | "mimetype": "text/x-python", 716 | "name": "python", 717 | "nbconvert_exporter": "python", 718 | "pygments_lexer": "ipython3", 719 | "version": "3.8.5" 720 | } 721 | }, 722 | "nbformat": 4, 723 | "nbformat_minor": 2 724 | } 725 | -------------------------------------------------------------------------------- /5. Dizionari.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "*Contenuti*\n", 8 | "===\n", 9 | "- [Un database di immobili](#Un-database-di-immobili)\n", 10 | "- [Dizionari: definizione e sintassi](#Dizionari:-definizione-e-sintassi)\n", 11 | "- [Accesso](#Accesso)\n", 12 | "- [Operazioni su dizionario](#Operazioni-su-dizionario)\n", 13 | "- [Ciclo sugli elementi di un dizionario](#Ciclo-sugli-elementi-di-un-dizionario)\n", 14 | "- [*Esercizio 1*](#Esercizio-1)\n", 15 | "- [*Esercizio 2*](#Esercizio-2)\n", 16 | "- [*Esercizio 3*](#Esercizio-3)" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "metadata": {}, 22 | "source": [ 23 | "Un database di immobili\n", 24 | "===\n", 25 | "Spesso gli elementi di una lista hanno un significato particolare. Immaginiamo ad esempio di costruire un database di immobili, definiti da:\n", 26 | "\n", 27 | "- coordinate, come coppia (lon,lat) in gradi decimali\n", 28 | "- estensione in mq\n", 29 | "- presenza di terreno\n", 30 | "- prezzo, in migliaia di Euro\n", 31 | "\n", 32 | "Possiamo realizzare il database come una lista. A sua volta, ogni immobile sarà una lista di informazioni. Immaginiamo anche che il database sia inizialmente vuoto, e che venga popolato di un nuovo record ogni volta che un immobile viene registrato (per esempio, attraverso il form di un applicativo)." 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": 1, 38 | "metadata": {}, 39 | "outputs": [ 40 | { 41 | "name": "stdout", 42 | "output_type": "stream", 43 | "text": [ 44 | "\n", 45 | "Immobile #0\n", 46 | "Coordinate: [12.3456, -56.789]\n", 47 | "Estensione (mq): 2000\n", 48 | "Terreno annesso?: No\n", 49 | "Prezzo: 10K Euro\n", 50 | "\n", 51 | "Immobile #1\n", 52 | "Coordinate: [-8.9101, 60.1234]\n", 53 | "Estensione (mq): 12000\n", 54 | "Terreno annesso?: No\n", 55 | "Prezzo: 125K Euro\n", 56 | "\n", 57 | "Immobile #2\n", 58 | "Coordinate: [45.6789, 10.3456]\n", 59 | "Estensione (mq): 100\n", 60 | "Terreno annesso?: Sì\n", 61 | "Prezzo: 350K Euro\n" 62 | ] 63 | } 64 | ], 65 | "source": [ 66 | "estates = []#database vuoto\n", 67 | "\n", 68 | "e1 = [[12.3456, -56.7890], 2000 , False, 10]#creazione immobile\n", 69 | "estates += [e1]#aggiunta immobile al db\n", 70 | "\n", 71 | "e2 = [[-8.9101, 60.1234], 12000, False, 125]\n", 72 | "estates += [e2]\n", 73 | "\n", 74 | "e3 = [[45.6789, 10.3456], 100 , True, 350]\n", 75 | "estates += [e3]\n", 76 | "\n", 77 | "for i, e in enumerate(estates):\n", 78 | " print('\\nImmobile #{}'.format(i))#'\\n' va a capo\n", 79 | " print('Coordinate: {}'.format(e[0]))\n", 80 | " print('Estensione (mq): {}'.format(e[1]))\n", 81 | " print('Terreno annesso?: {}'.format('Sì' if e[2] else 'No'))\n", 82 | " print('Prezzo: {}K Euro'.format(e[3]))" 83 | ] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "metadata": {}, 88 | "source": [ 89 | "Quando le informazioni di un immobile sono tante, però, gestirle in questo modo diventa scomodo. Per accedere ad una proprietà dell'immobile, infatti, dobbiamo conoscerne la posizione nella lista." 90 | ] 91 | }, 92 | { 93 | "cell_type": "markdown", 94 | "metadata": {}, 95 | "source": [ 96 | "Dizionari: definizione e sintassi\n", 97 | "===\n", 98 | "\n", 99 | "Un *dizionario* è un contenitore speciale in cui ogni elemento ha una *chiave* (cioè un identificatore univoco) e un *valore*. A differenza di una lista, associa quindi una semantica ai suoi elementi." 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": null, 105 | "metadata": {}, 106 | "outputs": [], 107 | "source": [ 108 | "dictionary_name = {key1:value1, key1:value2}" 109 | ] 110 | }, 111 | { 112 | "cell_type": "markdown", 113 | "metadata": {}, 114 | "source": [ 115 | "Il codice qui sopra è un esempio generale di come si dichiara un dizionario. \n", 116 | "\n", 117 | "- usiamo le parentesi graffe per dichiarare un dizionario\n", 118 | "- le coppie (chiave, valore) possono essere tante a piacere\n", 119 | "- una chiave non può essere ripetuta: per esempio, ciascun immobile avrà un solo prezzo, una sola metratura, ...\n", 120 | "- i valori possono essere qualsiasi cosa (inclusi liste e altri dizionari).\n", 121 | "\n", 122 | "Tornando al nostro esempio, possiamo gestire il database di utenti come una lista di dizionari." 123 | ] 124 | }, 125 | { 126 | "cell_type": "code", 127 | "execution_count": 3, 128 | "metadata": {}, 129 | "outputs": [], 130 | "source": [ 131 | "estates = []\n", 132 | "\n", 133 | "e1 = {'coordinates':[12.3456, -56.7890], 'extension':2000, 'has_land':False, 'price':10}\n", 134 | "estates += [e1]\n", 135 | "\n", 136 | "e2 = {'coordinates':[-8.9101, 60.1234], 'extension':12000, 'has_land':False, 'price':125}\n", 137 | "estates += [e2]\n", 138 | "\n", 139 | "e3 = {'coordinates':[45.6789, 10.3456], 'extension':100, 'has_land':True, 'price':350}\n", 140 | "estates += [e3]" 141 | ] 142 | }, 143 | { 144 | "cell_type": "code", 145 | "execution_count": 4, 146 | "metadata": {}, 147 | "outputs": [ 148 | { 149 | "data": { 150 | "text/plain": [ 151 | "{'coordinates': [12.3456, -56.789],\n", 152 | " 'extension': 2000,\n", 153 | " 'has_land': False,\n", 154 | " 'price': 10}" 155 | ] 156 | }, 157 | "execution_count": 4, 158 | "metadata": {}, 159 | "output_type": "execute_result" 160 | } 161 | ], 162 | "source": [ 163 | "e1" 164 | ] 165 | }, 166 | { 167 | "cell_type": "markdown", 168 | "metadata": {}, 169 | "source": [ 170 | "Accesso\n", 171 | "===\n", 172 | "Adesso possiamo accedere alle informazioni degli immobili in modo più compatto e leggibile, utilizzando una chiave per ottenere il valore corrispondente." 173 | ] 174 | }, 175 | { 176 | "cell_type": "code", 177 | "execution_count": 5, 178 | "metadata": {}, 179 | "outputs": [ 180 | { 181 | "data": { 182 | "text/plain": [ 183 | "10" 184 | ] 185 | }, 186 | "execution_count": 5, 187 | "metadata": {}, 188 | "output_type": "execute_result" 189 | } 190 | ], 191 | "source": [ 192 | "e1['price']" 193 | ] 194 | }, 195 | { 196 | "cell_type": "code", 197 | "execution_count": 6, 198 | "metadata": {}, 199 | "outputs": [ 200 | { 201 | "name": "stdout", 202 | "output_type": "stream", 203 | "text": [ 204 | "\n", 205 | "Immobile #0\n", 206 | "Coordinate: [12.3456, -56.789]\n", 207 | "Estensione (mq): 2000\n", 208 | "Terreno annesso?: No\n", 209 | "Prezzo: 10K Euro\n", 210 | "\n", 211 | "Immobile #1\n", 212 | "Coordinate: [-8.9101, 60.1234]\n", 213 | "Estensione (mq): 12000\n", 214 | "Terreno annesso?: No\n", 215 | "Prezzo: 125K Euro\n", 216 | "\n", 217 | "Immobile #2\n", 218 | "Coordinate: [45.6789, 10.3456]\n", 219 | "Estensione (mq): 100\n", 220 | "Terreno annesso?: Sì\n", 221 | "Prezzo: 350K Euro\n" 222 | ] 223 | } 224 | ], 225 | "source": [ 226 | "for i, e in enumerate(estates):\n", 227 | " print('\\nImmobile #{}'.format(i))\n", 228 | " print('Coordinate: {}'.format(e['coordinates']))\n", 229 | " print('Estensione (mq): {}'.format(e['extension']))\n", 230 | " print('Terreno annesso?: {}'.format('Sì' if e['has_land'] else 'No'))\n", 231 | " print('Prezzo: {}K Euro'.format(e['price']))" 232 | ] 233 | }, 234 | { 235 | "cell_type": "markdown", 236 | "metadata": {}, 237 | "source": [ 238 | "Questo tipo di accesso è utile in molti contesti. Ecco un esempio con comprensione di lista." 239 | ] 240 | }, 241 | { 242 | "cell_type": "code", 243 | "execution_count": 7, 244 | "metadata": {}, 245 | "outputs": [ 246 | { 247 | "data": { 248 | "text/plain": [ 249 | "[10, 125, 350]" 250 | ] 251 | }, 252 | "execution_count": 7, 253 | "metadata": {}, 254 | "output_type": "execute_result" 255 | } 256 | ], 257 | "source": [ 258 | "[h['price'] for h in estates]" 259 | ] 260 | }, 261 | { 262 | "cell_type": "markdown", 263 | "metadata": {}, 264 | "source": [ 265 | "Operazioni su dizionario\n", 266 | "===\n", 267 | "Come abbiamo fatto per le liste, vediamo le operazioni di base che si possono fare su un dizionario.\n", 268 | "\n", 269 | "Cambiamo contesto applicativo. Un'agenzia immobiliare affitta appartamenti in una località marittima. Ciascun appartamento ha un nome univoco e un prezzo settimanale, e l'agenzia desidera costruire un database che tenga traccia di queste due informazioni.\n", 270 | "\n", 271 | "Di quanti dizionari ho bisogno?" 272 | ] 273 | }, 274 | { 275 | "cell_type": "code", 276 | "execution_count": 18, 277 | "metadata": {}, 278 | "outputs": [ 279 | { 280 | "data": { 281 | "text/plain": [ 282 | "{'Villa Bianca': 500, 'Il pino marittimo': 250, 'La stamberga': 100}" 283 | ] 284 | }, 285 | "execution_count": 18, 286 | "metadata": {}, 287 | "output_type": "execute_result" 288 | } 289 | ], 290 | "source": [ 291 | "prices = {}#database: dizionario vuoto\n", 292 | "\n", 293 | "prices['Villa Bianca'] = 500#inserimento\n", 294 | "prices['Il pino marittimo'] = 250\n", 295 | "prices['La stamberga'] = 100\n", 296 | "\n", 297 | "prices" 298 | ] 299 | }, 300 | { 301 | "cell_type": "code", 302 | "execution_count": 9, 303 | "metadata": {}, 304 | "outputs": [ 305 | { 306 | "name": "stdout", 307 | "output_type": "stream", 308 | "text": [ 309 | "Il prezzo settimanale di Villa Bianca è 500 Euro\n" 310 | ] 311 | } 312 | ], 313 | "source": [ 314 | "print('Il prezzo settimanale di Villa Bianca è {} Euro'.format(prices['Villa Bianca']))" 315 | ] 316 | }, 317 | { 318 | "cell_type": "markdown", 319 | "metadata": {}, 320 | "source": [ 321 | "*La stamberga* non si riesce ad affittare..." 322 | ] 323 | }, 324 | { 325 | "cell_type": "code", 326 | "execution_count": 19, 327 | "metadata": {}, 328 | "outputs": [ 329 | { 330 | "name": "stdout", 331 | "output_type": "stream", 332 | "text": [ 333 | "Offerta! Il prezzo settimanale di La stamberga è 80 Euro\n" 334 | ] 335 | } 336 | ], 337 | "source": [ 338 | "prices['La stamberga'] = 80#modifica del valore di una chiave esistente\n", 339 | "\n", 340 | "print('Offerta! Il prezzo settimanale di La stamberga è {} Euro'.format(prices['La stamberga']))" 341 | ] 342 | }, 343 | { 344 | "cell_type": "markdown", 345 | "metadata": {}, 346 | "source": [ 347 | "Ciclo sugli elementi di un dizionario\n", 348 | "===\n", 349 | "Attraverso la funzione *items* si accede alle coppie (chiave, valore) di un dizionario." 350 | ] 351 | }, 352 | { 353 | "cell_type": "code", 354 | "execution_count": 20, 355 | "metadata": {}, 356 | "outputs": [ 357 | { 358 | "name": "stdout", 359 | "output_type": "stream", 360 | "text": [ 361 | "Il prezzo settimanale di Villa Bianca è 500 Euro\n", 362 | "Il prezzo settimanale di Il pino marittimo è 250 Euro\n", 363 | "Il prezzo settimanale di La stamberga è 80 Euro\n" 364 | ] 365 | } 366 | ], 367 | "source": [ 368 | "for apt, price in prices.items():#chiave/valore\n", 369 | " print('Il prezzo settimanale di {} è {} Euro'.format(apt, price))" 370 | ] 371 | }, 372 | { 373 | "cell_type": "markdown", 374 | "metadata": {}, 375 | "source": [ 376 | "Si può accedere separatamente sia alle chiavi che ai valori." 377 | ] 378 | }, 379 | { 380 | "cell_type": "code", 381 | "execution_count": 21, 382 | "metadata": {}, 383 | "outputs": [ 384 | { 385 | "name": "stdout", 386 | "output_type": "stream", 387 | "text": [ 388 | "Nome appartamento: Villa Bianca\n", 389 | "Nome appartamento: Il pino marittimo\n", 390 | "Nome appartamento: La stamberga\n" 391 | ] 392 | } 393 | ], 394 | "source": [ 395 | "for apt in prices.keys():#chiavi\n", 396 | " print('Nome appartamento:', apt)" 397 | ] 398 | }, 399 | { 400 | "cell_type": "code", 401 | "execution_count": 22, 402 | "metadata": {}, 403 | "outputs": [ 404 | { 405 | "name": "stdout", 406 | "output_type": "stream", 407 | "text": [ 408 | "Prezzo settimanale: 500\n", 409 | "Prezzo settimanale: 250\n", 410 | "Prezzo settimanale: 80\n" 411 | ] 412 | } 413 | ], 414 | "source": [ 415 | "for price in prices.values():#valori\n", 416 | " print('Prezzo settimanale:', price)" 417 | ] 418 | }, 419 | { 420 | "cell_type": "markdown", 421 | "metadata": {}, 422 | "source": [ 423 | "Per convenzione, l'ordinamento è (alfabetico) per chiave. E' comunque [possibile](https://stackoverflow.com/questions/613183/how-do-i-sort-a-dictionary-by-value) ordinare per valore." 424 | ] 425 | }, 426 | { 427 | "cell_type": "code", 428 | "execution_count": 23, 429 | "metadata": {}, 430 | "outputs": [ 431 | { 432 | "data": { 433 | "text/plain": [ 434 | "['Il pino marittimo', 'La stamberga', 'Villa Bianca']" 435 | ] 436 | }, 437 | "execution_count": 23, 438 | "metadata": {}, 439 | "output_type": "execute_result" 440 | } 441 | ], 442 | "source": [ 443 | "sorted(prices)" 444 | ] 445 | }, 446 | { 447 | "cell_type": "code", 448 | "execution_count": 24, 449 | "metadata": {}, 450 | "outputs": [ 451 | { 452 | "name": "stdout", 453 | "output_type": "stream", 454 | "text": [ 455 | "Il prezzo di Il pino marittimo è 250 Euro\n", 456 | "Il prezzo di La stamberga è 80 Euro\n", 457 | "Il prezzo di Villa Bianca è 500 Euro\n" 458 | ] 459 | } 460 | ], 461 | "source": [ 462 | "for apt in sorted(prices):\n", 463 | " print('Il prezzo di {} è {} Euro'.format(apt, prices[apt]))" 464 | ] 465 | }, 466 | { 467 | "cell_type": "markdown", 468 | "metadata": {}, 469 | "source": [ 470 | "*Esercizio 1*\n", 471 | "===\n", 472 | "Su https://en.wikipedia.org/wiki/List_of_mountains_by_elevation trovate l'elenco delle montagne più alte del mondo.\n", 473 | "\n", 474 | "- costruire una struttura dati *heights* che, per ognuna delle 5 montagne più alte, permetta di accedere all'altezza a partire dal nome\n", 475 | "- stampare le montagne in ordine alfabetico, riportandone nome, altezza e indice nell'ordinamento alfabetico\n", 476 | " La montagna numero 1 è Kangchenjunga ed è alta 8,586 metri\n", 477 | " La montagna numero 2 è K2 ed è alta 8,611 metri\n", 478 | " ...\n", 479 | " La montagna numero 5 è Mount Everest ed è alta 8,858 metri" 480 | ] 481 | }, 482 | { 483 | "cell_type": "code", 484 | "execution_count": 16, 485 | "metadata": {}, 486 | "outputs": [], 487 | "source": [ 488 | "#FILL ME" 489 | ] 490 | }, 491 | { 492 | "cell_type": "markdown", 493 | "metadata": {}, 494 | "source": [ 495 | "*Esercizio 2*\n", 496 | "===\n", 497 | "Utilizzando il link dell'esercizio precedente,\n", 498 | "\n", 499 | "- costruire un database *mountains* con le prime 5 montagne più alte\n", 500 | "- ogni record deve contenere nome, altezza e stato in cui si trova la montagna\n", 501 | "- stampare, in ordine di inserimento, tutte le informazioni di ogni montagna e l'indice di inserimento\n", 502 | " La montagna numero 1 è Mount Everest, è alta 8858 metri e si trova in Nepal\n", 503 | "- costruire due liste *mountain_names* e *mountain_heights*, rispettivamente con nomi e altezze delle montagne inserite nel database\n", 504 | "- utilizzando le due liste, costruire lo stesso dizionario dell'esercizio precedente (l'ordine delle coppie non è importante)" 505 | ] 506 | }, 507 | { 508 | "cell_type": "code", 509 | "execution_count": 17, 510 | "metadata": {}, 511 | "outputs": [], 512 | "source": [ 513 | "#FILL ME" 514 | ] 515 | }, 516 | { 517 | "cell_type": "markdown", 518 | "metadata": {}, 519 | "source": [ 520 | "*Esercizio 3*\n", 521 | "===\n", 522 | "Seguendo [quanto fatto in precedenza](#Dizionari:-definizione-e-sintassi), costruire un database di immobili con dati e proprietà a piacere.\n", 523 | "\n", 524 | "Definire una funzione che prenda in ingresso un singolo immobile e ne stampi le informazioni, come [visto qui sopra](#Accesso).\n", 525 | "\n", 526 | "Iterare sugli immobili attraverso una enumerazione. Per ognuno, stampare\n", 527 | "- l'indice di inserimento nel database\n", 528 | "- le sue informazioni, usando la funzione appena definita." 529 | ] 530 | }, 531 | { 532 | "cell_type": "markdown", 533 | "metadata": {}, 534 | "source": [ 535 | "\n", 543 | "\n", 544 | "
\n", 545 | "Created with Jupyter.\n", 546 | "
" 547 | ] 548 | } 549 | ], 550 | "metadata": { 551 | "kernelspec": { 552 | "display_name": "Python 3", 553 | "language": "python", 554 | "name": "python3" 555 | }, 556 | "language_info": { 557 | "codemirror_mode": { 558 | "name": "ipython", 559 | "version": 3 560 | }, 561 | "file_extension": ".py", 562 | "mimetype": "text/x-python", 563 | "name": "python", 564 | "nbconvert_exporter": "python", 565 | "pygments_lexer": "ipython3", 566 | "version": "3.8.5" 567 | } 568 | }, 569 | "nbformat": 4, 570 | "nbformat_minor": 2 571 | } 572 | -------------------------------------------------------------------------------- /7. Scikit-learn.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "*Contenuti*\n", 8 | "===\n", 9 | "- [Scikit-learn: machine learning con Python](#Scikit-learn:-machine-learning-con-Python)\n", 10 | " - [Il dataset *iris*](#Il-dataset-iris)\n", 11 | " - [*Esercizio 1*](#Esercizio-1)\n", 12 | " - [Feature scaling](#Feature-scaling)\n", 13 | " - [*Esercizio 2*](#Esercizio-2)\n", 14 | " - [Insiemi di addestramento e test](#Insiemi-di-addestramento-e-test) \n", 15 | " - [Un modello per la classificazione](#Un-modello-per-la-classificazione)\n", 16 | " - [Addestramento](#Addestramento)\n", 17 | " - [Predizione](#Predizione)\n", 18 | " - [Valutazione](#Valutazione)\n", 19 | " - [Dai dati alla predizione](#Dai-dati-alla-predizione)\n", 20 | " - [*Esercizio 3*](#Esercizio-3) \n", 21 | " - [Validazione](#Validazione)\n", 22 | " - [Alberi di decisione](#Alberi-di-decisione)\n", 23 | " - [*Esercizio 4*](#Esercizio-4)" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "Scikit-learn: machine learning con Python\n", 31 | "===" 32 | ] 33 | }, 34 | { 35 | "cell_type": "markdown", 36 | "metadata": {}, 37 | "source": [ 38 | "*Scikit-learn* (o *sklearn*) è uno dei principali strumenti Python per il machine learning, ed è una delle librerie open-source di data science più usate al mondo.\n", 39 | "\n", 40 | "Sul [sito](http://scikit-learn.org/stable/) si trovano svariati modelli di machine learning, insieme a strumenti di preprocessing, analisi e visualizzazione dei dati. \n", 41 | "\n", 42 | "Ciascuna implementazione fa riferimento ad una [guida utente](https://scikit-learn.org/stable/user_guide.html#user-guide) molto dettagliata, che associa al codice la teoria necessaria per capirlo e usarlo.\n", 43 | "\n", 44 | "Teoria e codice sono spesso supportati da [esempi pratici](http://scikit-learn.org/stable/auto_examples/)." 45 | ] 46 | }, 47 | { 48 | "cell_type": "markdown", 49 | "metadata": {}, 50 | "source": [ 51 | "Il dataset *iris*\n", 52 | "---\n", 53 | "\n", 54 | "Iniziamo sfruttando i *toy dataset* messi a disposizione dalla libreria. Il modulo *datasets* ne contiene diversi. Se, dopo averlo importato, scriviamo\n", 55 | "\n", 56 | " datasets.\n", 57 | " \n", 58 | "e premiamo il tasto di autocomplemento, possiamo dare un'occhiata a cosa offre." 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": 1, 64 | "metadata": {}, 65 | "outputs": [], 66 | "source": [ 67 | "from sklearn import datasets\n", 68 | "\n", 69 | "iris = datasets.load_iris()" 70 | ] 71 | }, 72 | { 73 | "cell_type": "markdown", 74 | "metadata": {}, 75 | "source": [ 76 | "Attraverso la funzione *load_iris* abbiamo caricato dentro una variabile un intero dataset. L'oggetto così creato sarà simile a un dizionario (Lezione 5), cioè a un insieme di coppie chiave/valore.\n", 77 | "\n", 78 | "Dati ed etichette sono associati rispettivamente alle chiavi *data* e *target*." 79 | ] 80 | }, 81 | { 82 | "cell_type": "code", 83 | "execution_count": 2, 84 | "metadata": {}, 85 | "outputs": [ 86 | { 87 | "name": "stdout", 88 | "output_type": "stream", 89 | "text": [ 90 | "(150, 4) (150,)\n" 91 | ] 92 | } 93 | ], 94 | "source": [ 95 | "X = iris['data']\n", 96 | "y = iris['target']\n", 97 | "\n", 98 | "print(X.shape, y.shape)" 99 | ] 100 | }, 101 | { 102 | "cell_type": "markdown", 103 | "metadata": {}, 104 | "source": [ 105 | "Dentro al dizionario ci sono altri oggetti utili. Alla chiave DESCR è associata una descrizione del dataset." 106 | ] 107 | }, 108 | { 109 | "cell_type": "code", 110 | "execution_count": 3, 111 | "metadata": {}, 112 | "outputs": [ 113 | { 114 | "name": "stdout", 115 | "output_type": "stream", 116 | "text": [ 117 | ".. _iris_dataset:\n", 118 | "\n", 119 | "Iris plants dataset\n", 120 | "--------------------\n", 121 | "\n", 122 | "**Data Set Characteristics:**\n", 123 | "\n", 124 | " :Number of Instances: 150 (50 in each of three classes)\n", 125 | " :Number of Attributes: 4 numeric, predictive attributes and the class\n", 126 | " :Attribute Information:\n", 127 | " - sepal length in cm\n", 128 | " - sepal width in cm\n", 129 | " - petal length in cm\n", 130 | " - petal width in cm\n", 131 | " - class:\n", 132 | " - Iris-Setosa\n", 133 | " - Iris-Versicolour\n", 134 | " - Iris-Virginica\n", 135 | " \n", 136 | " :Summary Statistics:\n", 137 | "\n", 138 | " ============== ==== ==== ======= ===== ====================\n", 139 | " Min Max Mean SD Class Correlation\n", 140 | " ============== ==== ==== ======= ===== ====================\n", 141 | " sepal length: 4.3 7.9 5.84 0.83 0.7826\n", 142 | " sepal width: 2.0 4.4 3.05 0.43 -0.4194\n", 143 | " petal length: 1.0 6.9 3.76 1.76 0.9490 (high!)\n", 144 | " petal width: 0.1 2.5 1.20 0.76 0.9565 (high!)\n", 145 | " ============== ==== ==== ======= ===== ====================\n", 146 | "\n", 147 | " :Missing Attribute Values: None\n", 148 | " :Class Distribution: 33.3% for each of 3 classes.\n", 149 | " :Creator: R.A. Fisher\n", 150 | " :Donor: Michael Marshall (MARSHALL%PLU@io.arc.nasa.gov)\n", 151 | " :Date: July, 1988\n", 152 | "\n", 153 | "The famous Iris database, first used by Sir R.A. Fisher. The dataset is taken\n", 154 | "from Fisher's paper. Note that it's the same as in R, but not as in the UCI\n", 155 | "Machine Learning Repository, which has two wrong data points.\n", 156 | "\n", 157 | "This is perhaps the best known database to be found in the\n", 158 | "pattern recognition literature. Fisher's paper is a classic in the field and\n", 159 | "is referenced frequently to this day. (See Duda & Hart, for example.) The\n", 160 | "data set contains 3 classes of 50 instances each, where each class refers to a\n", 161 | "type of iris plant. One class is linearly separable from the other 2; the\n", 162 | "latter are NOT linearly separable from each other.\n", 163 | "\n", 164 | ".. topic:: References\n", 165 | "\n", 166 | " - Fisher, R.A. \"The use of multiple measurements in taxonomic problems\"\n", 167 | " Annual Eugenics, 7, Part II, 179-188 (1936); also in \"Contributions to\n", 168 | " Mathematical Statistics\" (John Wiley, NY, 1950).\n", 169 | " - Duda, R.O., & Hart, P.E. (1973) Pattern Classification and Scene Analysis.\n", 170 | " (Q327.D83) John Wiley & Sons. ISBN 0-471-22361-1. See page 218.\n", 171 | " - Dasarathy, B.V. (1980) \"Nosing Around the Neighborhood: A New System\n", 172 | " Structure and Classification Rule for Recognition in Partially Exposed\n", 173 | " Environments\". IEEE Transactions on Pattern Analysis and Machine\n", 174 | " Intelligence, Vol. PAMI-2, No. 1, 67-71.\n", 175 | " - Gates, G.W. (1972) \"The Reduced Nearest Neighbor Rule\". IEEE Transactions\n", 176 | " on Information Theory, May 1972, 431-433.\n", 177 | " - See also: 1988 MLC Proceedings, 54-64. Cheeseman et al\"s AUTOCLASS II\n", 178 | " conceptual clustering system finds 3 classes in the data.\n", 179 | " - Many, many more ...\n" 180 | ] 181 | } 182 | ], 183 | "source": [ 184 | "print(iris['DESCR'])" 185 | ] 186 | }, 187 | { 188 | "cell_type": "markdown", 189 | "metadata": {}, 190 | "source": [ 191 | "Vediamo come sono fatti i dati, stampando i primi dieci esempi etichettati." 192 | ] 193 | }, 194 | { 195 | "cell_type": "code", 196 | "execution_count": 4, 197 | "metadata": {}, 198 | "outputs": [ 199 | { 200 | "name": "stdout", 201 | "output_type": "stream", 202 | "text": [ 203 | "feature: [5.1 3.5 1.4 0.2] label: 0\n", 204 | "feature: [4.9 3. 1.4 0.2] label: 0\n", 205 | "feature: [4.7 3.2 1.3 0.2] label: 0\n", 206 | "feature: [4.6 3.1 1.5 0.2] label: 0\n", 207 | "feature: [5. 3.6 1.4 0.2] label: 0\n", 208 | "feature: [5.4 3.9 1.7 0.4] label: 0\n", 209 | "feature: [4.6 3.4 1.4 0.3] label: 0\n", 210 | "feature: [5. 3.4 1.5 0.2] label: 0\n", 211 | "feature: [4.4 2.9 1.4 0.2] label: 0\n", 212 | "feature: [4.9 3.1 1.5 0.1] label: 0\n" 213 | ] 214 | } 215 | ], 216 | "source": [ 217 | "for i, x in enumerate(X[:10]):\n", 218 | " print('feature: {} label: {}'.format(x, y[i]))" 219 | ] 220 | }, 221 | { 222 | "cell_type": "markdown", 223 | "metadata": {}, 224 | "source": [ 225 | "### *Esercizio 1*\n", 226 | "Esplorare il contenuto di iris e di altri dataset." 227 | ] 228 | }, 229 | { 230 | "cell_type": "markdown", 231 | "metadata": {}, 232 | "source": [ 233 | "Feature scaling\n", 234 | "---\n", 235 | "Come si vede dalla descrizione di iris, le feature hanno ordini di grandezza diversi." 236 | ] 237 | }, 238 | { 239 | "cell_type": "markdown", 240 | "metadata": {}, 241 | "source": [ 242 | "### *Esercizio 2*\n", 243 | "Estrarre, per ogni feature del dataset iris, i valori minimo e massimo osservati sul training set (e controllare che siano uguali a quelli della descrizione)." 244 | ] 245 | }, 246 | { 247 | "cell_type": "code", 248 | "execution_count": 5, 249 | "metadata": {}, 250 | "outputs": [], 251 | "source": [ 252 | "import numpy as np\n", 253 | "\n", 254 | "#FILL ME" 255 | ] 256 | }, 257 | { 258 | "cell_type": "markdown", 259 | "metadata": {}, 260 | "source": [ 261 | "Tra gli strumenti di preprocessing di sklearn, troviamo alcune utilità per normalizzare i dati. Usiamo *MinMaxScaler* per scalare tutte le feature tra 0 e 1. " 262 | ] 263 | }, 264 | { 265 | "cell_type": "code", 266 | "execution_count": 7, 267 | "metadata": {}, 268 | "outputs": [ 269 | { 270 | "data": { 271 | "text/plain": [ 272 | "(0, 1)" 273 | ] 274 | }, 275 | "execution_count": 7, 276 | "metadata": {}, 277 | "output_type": "execute_result" 278 | } 279 | ], 280 | "source": [ 281 | "from sklearn.preprocessing import MinMaxScaler\n", 282 | "\n", 283 | "scaler = MinMaxScaler()\n", 284 | "\n", 285 | "scaler.feature_range" 286 | ] 287 | }, 288 | { 289 | "cell_type": "code", 290 | "execution_count": 8, 291 | "metadata": {}, 292 | "outputs": [ 293 | { 294 | "name": "stdout", 295 | "output_type": "stream", 296 | "text": [ 297 | "[0. 0. 0. 0.]\n", 298 | "[1. 1. 1. 1.]\n" 299 | ] 300 | } 301 | ], 302 | "source": [ 303 | "X = scaler.fit_transform(X)\n", 304 | "\n", 305 | "print(np.min(X, axis=0))\n", 306 | "print(np.max(X, axis=0))" 307 | ] 308 | }, 309 | { 310 | "cell_type": "markdown", 311 | "metadata": {}, 312 | "source": [ 313 | "Insiemi di addestramento e test\n", 314 | "---\n", 315 | "Prima di passare all'addestramento, dividiamo i dati in training e test set. " 316 | ] 317 | }, 318 | { 319 | "cell_type": "markdown", 320 | "metadata": {}, 321 | "source": [ 322 | "Come sono stati ordinati gli esempi del dataset?" 323 | ] 324 | }, 325 | { 326 | "cell_type": "code", 327 | "execution_count": 9, 328 | "metadata": {}, 329 | "outputs": [ 330 | { 331 | "data": { 332 | "text/plain": [ 333 | "array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", 334 | " 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n", 335 | " 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n", 336 | " 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n", 337 | " 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n", 338 | " 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n", 339 | " 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2])" 340 | ] 341 | }, 342 | "execution_count": 9, 343 | "metadata": {}, 344 | "output_type": "execute_result" 345 | } 346 | ], 347 | "source": [ 348 | "y" 349 | ] 350 | }, 351 | { 352 | "cell_type": "markdown", 353 | "metadata": {}, 354 | "source": [ 355 | "Mescoliamo (coerentemente!) i dati con la funzione *shuffle*." 356 | ] 357 | }, 358 | { 359 | "cell_type": "code", 360 | "execution_count": 10, 361 | "metadata": {}, 362 | "outputs": [ 363 | { 364 | "name": "stdout", 365 | "output_type": "stream", 366 | "text": [ 367 | "feature: [0.41666667 0.33333333 0.69491525 0.95833333] label: 2\n", 368 | "feature: [0.47222222 0.08333333 0.50847458 0.375 ] label: 1\n", 369 | "feature: [0.33333333 0.91666667 0.06779661 0.04166667] label: 0\n", 370 | "feature: [0.83333333 0.375 0.89830508 0.70833333] label: 2\n", 371 | "feature: [0.19444444 0.58333333 0.08474576 0.04166667] label: 0\n", 372 | "feature: [0.55555556 0.54166667 0.84745763 1. ] label: 2\n", 373 | "feature: [0.19444444 0.625 0.05084746 0.08333333] label: 0\n", 374 | "feature: [0.66666667 0.45833333 0.62711864 0.58333333] label: 1\n", 375 | "feature: [0.69444444 0.33333333 0.6440678 0.54166667] label: 1\n", 376 | "feature: [0.5 0.33333333 0.50847458 0.5 ] label: 1\n" 377 | ] 378 | } 379 | ], 380 | "source": [ 381 | "from sklearn.utils import shuffle#importo singola funzione dal modulo\n", 382 | "\n", 383 | "X, y = shuffle(X, y, random_state=0)#controllo del generatore random\n", 384 | "\n", 385 | "for i, x in enumerate(X[:10]):\n", 386 | " print('feature: {} label: {}'.format(x, y[i]))" 387 | ] 388 | }, 389 | { 390 | "cell_type": "markdown", 391 | "metadata": {}, 392 | "source": [ 393 | "Prendiamo i primi due terzi dei dati mescolati (100) per l'addestramento e i restanti (50) per il test." 394 | ] 395 | }, 396 | { 397 | "cell_type": "code", 398 | "execution_count": 11, 399 | "metadata": {}, 400 | "outputs": [ 401 | { 402 | "name": "stdout", 403 | "output_type": "stream", 404 | "text": [ 405 | "(100, 4) (50, 4)\n" 406 | ] 407 | } 408 | ], 409 | "source": [ 410 | "X_train = X[:100]#i primi 100 esempi (righe)\n", 411 | "X_test = X[100:]#gli altri\n", 412 | "\n", 413 | "print(X_train.shape, X_test.shape)" 414 | ] 415 | }, 416 | { 417 | "cell_type": "markdown", 418 | "metadata": {}, 419 | "source": [ 420 | "Stesso discorso per le etichette." 421 | ] 422 | }, 423 | { 424 | "cell_type": "code", 425 | "execution_count": 12, 426 | "metadata": {}, 427 | "outputs": [ 428 | { 429 | "name": "stdout", 430 | "output_type": "stream", 431 | "text": [ 432 | "(100,) (50,)\n" 433 | ] 434 | } 435 | ], 436 | "source": [ 437 | "y_train = y[:100]\n", 438 | "y_test = y[100:]\n", 439 | "\n", 440 | "print(y_train.shape, y_test.shape)" 441 | ] 442 | }, 443 | { 444 | "cell_type": "markdown", 445 | "metadata": {}, 446 | "source": [ 447 | "Un modello per la classificazione\n", 448 | "---\n", 449 | "Siamo pronti per l'addestramento. Costruiamo un modello $k$*-nearest neighbors* (KNN) per la classificazione." 450 | ] 451 | }, 452 | { 453 | "cell_type": "code", 454 | "execution_count": 2, 455 | "metadata": {}, 456 | "outputs": [ 457 | { 458 | "name": "stdout", 459 | "output_type": "stream", 460 | "text": [ 461 | "KNeighborsClassifier()\n" 462 | ] 463 | } 464 | ], 465 | "source": [ 466 | "from sklearn.neighbors import KNeighborsClassifier as KNN\n", 467 | "\n", 468 | "model = KNN()" 469 | ] 470 | }, 471 | { 472 | "cell_type": "markdown", 473 | "metadata": {}, 474 | "source": [ 475 | "Abbiamo invocato una funzione speciale, chiamata *costrutture*, che inizializza (in questo caso senza parametri) un classificatore KNN. Possiamo vedere\n", 476 | "\n", 477 | "- dalla [documentazione](http://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html)\n", 478 | "- oppure posizionando il puntatore del mouse dentro le parentesi del costruttore e premendo Shift e due volte Tab,\n", 479 | "\n", 480 | "che questa funzione prende in ingresso diversi parametri, nessuno dei quali obbligatorio. Per esempio, il numero di vicini $k$ (chiamato *n_neighbors*) vale di default 5.\n", 481 | "\n", 482 | "Ciascuna proprietà può essere indicata in fase di costruzione." 483 | ] 484 | }, 485 | { 486 | "cell_type": "code", 487 | "execution_count": 14, 488 | "metadata": {}, 489 | "outputs": [ 490 | { 491 | "data": { 492 | "text/plain": [ 493 | "5" 494 | ] 495 | }, 496 | "execution_count": 14, 497 | "metadata": {}, 498 | "output_type": "execute_result" 499 | } 500 | ], 501 | "source": [ 502 | "model.n_neighbors" 503 | ] 504 | }, 505 | { 506 | "cell_type": "code", 507 | "execution_count": 15, 508 | "metadata": {}, 509 | "outputs": [ 510 | { 511 | "data": { 512 | "text/plain": [ 513 | "3" 514 | ] 515 | }, 516 | "execution_count": 15, 517 | "metadata": {}, 518 | "output_type": "execute_result" 519 | } 520 | ], 521 | "source": [ 522 | "model = KNN(n_neighbors=3)\n", 523 | "\n", 524 | "model.n_neighbors" 525 | ] 526 | }, 527 | { 528 | "cell_type": "markdown", 529 | "metadata": {}, 530 | "source": [ 531 | "### Addestramento\n", 532 | "\n", 533 | "Tramite la funzione *fit* addestriamo il modello sui dati di apprendimento." 534 | ] 535 | }, 536 | { 537 | "cell_type": "code", 538 | "execution_count": 17, 539 | "metadata": {}, 540 | "outputs": [ 541 | { 542 | "data": { 543 | "text/plain": [ 544 | "KNeighborsClassifier(algorithm='auto', leaf_size=30, metric='minkowski',\n", 545 | " metric_params=None, n_jobs=None, n_neighbors=3, p=2,\n", 546 | " weights='uniform')" 547 | ] 548 | }, 549 | "execution_count": 17, 550 | "metadata": {}, 551 | "output_type": "execute_result" 552 | } 553 | ], 554 | "source": [ 555 | "model.fit(X_train, y_train)" 556 | ] 557 | }, 558 | { 559 | "cell_type": "markdown", 560 | "metadata": {}, 561 | "source": [ 562 | "### Predizione\n", 563 | "\n", 564 | "Una volta addestrato, usiamo il modello per predire la classe degli esempi del test set." 565 | ] 566 | }, 567 | { 568 | "cell_type": "code", 569 | "execution_count": 18, 570 | "metadata": {}, 571 | "outputs": [ 572 | { 573 | "data": { 574 | "text/plain": [ 575 | "(50,)" 576 | ] 577 | }, 578 | "execution_count": 18, 579 | "metadata": {}, 580 | "output_type": "execute_result" 581 | } 582 | ], 583 | "source": [ 584 | "predictions = model.predict(X_test)\n", 585 | "\n", 586 | "predictions.shape" 587 | ] 588 | }, 589 | { 590 | "cell_type": "code", 591 | "execution_count": 19, 592 | "metadata": {}, 593 | "outputs": [ 594 | { 595 | "data": { 596 | "text/plain": [ 597 | "array([0, 0, 1, 2, 2, 0, 0, 0, 1, 1, 0, 0, 1, 0, 2, 1, 2, 1, 0, 2, 0, 2,\n", 598 | " 0, 0, 2, 0, 2, 1, 1, 1, 2, 2, 2, 1, 0, 1, 2, 2, 0, 1, 1, 2, 1, 0,\n", 599 | " 0, 0, 2, 1, 2, 0])" 600 | ] 601 | }, 602 | "execution_count": 19, 603 | "metadata": {}, 604 | "output_type": "execute_result" 605 | } 606 | ], 607 | "source": [ 608 | "predictions" 609 | ] 610 | }, 611 | { 612 | "cell_type": "markdown", 613 | "metadata": {}, 614 | "source": [ 615 | "### Valutazione\n", 616 | "\n", 617 | "Infine, valutiamo le prestazioni del modello addestrato sull'insieme di test, confrontando le predizioni con le (vere) etichette." 618 | ] 619 | }, 620 | { 621 | "cell_type": "code", 622 | "execution_count": 17, 623 | "metadata": {}, 624 | "outputs": [ 625 | { 626 | "name": "stdout", 627 | "output_type": "stream", 628 | "text": [ 629 | "Model accuracy on test set: 0.96\n" 630 | ] 631 | } 632 | ], 633 | "source": [ 634 | "from sklearn.metrics import accuracy_score\n", 635 | "\n", 636 | "acc = accuracy_score(y_test, predictions)\n", 637 | "print('Model accuracy on test set:', acc)" 638 | ] 639 | }, 640 | { 641 | "cell_type": "markdown", 642 | "metadata": {}, 643 | "source": [ 644 | "Dai dati alla predizione\n", 645 | "---" 646 | ] 647 | }, 648 | { 649 | "cell_type": "markdown", 650 | "metadata": {}, 651 | "source": [ 652 | "Ecco tutto quello che ci serve, con sklearn, per costruire un modello di classificazione a partire da un dataset." 653 | ] 654 | }, 655 | { 656 | "cell_type": "code", 657 | "execution_count": 22, 658 | "metadata": {}, 659 | "outputs": [ 660 | { 661 | "name": "stdout", 662 | "output_type": "stream", 663 | "text": [ 664 | "Model accuracy on test set: 0.96\n" 665 | ] 666 | } 667 | ], 668 | "source": [ 669 | "#Importo librerie\n", 670 | "from sklearn import datasets\n", 671 | "from sklearn.preprocessing import MinMaxScaler\n", 672 | "from sklearn.utils import shuffle\n", 673 | "from sklearn.neighbors import KNeighborsClassifier as KNN\n", 674 | "from sklearn.metrics import accuracy_score\n", 675 | "\n", 676 | "#Carico il dataset\n", 677 | "iris = datasets.load_iris()\n", 678 | "X, y = iris['data'], iris['target']\n", 679 | "\n", 680 | "#Scalo le feature tra 0 e 1\n", 681 | "scaler = MinMaxScaler()\n", 682 | "X = scaler.fit_transform(X)\n", 683 | "\n", 684 | "#Separo train e test\n", 685 | "X, y = shuffle(X, y, random_state=0)\n", 686 | "X_train, X_test = X[:100], X[100:]\n", 687 | "y_train, y_test = y[:100], y[100:]\n", 688 | "\n", 689 | "#Addestro il modello\n", 690 | "model = KNN(n_neighbors=3).fit(X_train, y_train)\n", 691 | "\n", 692 | "#Ottengo predizioni e valuto l'accuratezza del modello\n", 693 | "predictions = model.predict(X_test)\n", 694 | "print('Model accuracy on test set:', accuracy_score(y_test, predictions))" 695 | ] 696 | }, 697 | { 698 | "cell_type": "markdown", 699 | "metadata": {}, 700 | "source": [ 701 | "### *Esercizio 3*\n", 702 | "Ripetere quanto visto fin qui lavorando sul dataset *diabetes*. Utilizzare KNN per la regressione (*KNeighborsRegressor*) e il *mean absolute error* come metrica di valutazione." 703 | ] 704 | }, 705 | { 706 | "cell_type": "code", 707 | "execution_count": 23, 708 | "metadata": {}, 709 | "outputs": [], 710 | "source": [ 711 | "from sklearn.neighbors import KNeighborsRegressor as KNN\n", 712 | "from sklearn.metrics import mean_absolute_error\n", 713 | "\n", 714 | "diabetes = datasets.load_diabetes()\n", 715 | "\n", 716 | "#FILL ME" 717 | ] 718 | }, 719 | { 720 | "cell_type": "markdown", 721 | "metadata": {}, 722 | "source": [ 723 | "Validazione\n", 724 | "---\n", 725 | "Torniamo alla classificazione di iris e calibriamo il valore di $k$. Abbiamo bisogno di un insieme di validazione." 726 | ] 727 | }, 728 | { 729 | "cell_type": "code", 730 | "execution_count": 26, 731 | "metadata": {}, 732 | "outputs": [ 733 | { 734 | "name": "stdout", 735 | "output_type": "stream", 736 | "text": [ 737 | "(75, 4) (25, 4) (50, 4)\n" 738 | ] 739 | } 740 | ], 741 | "source": [ 742 | "from sklearn.neighbors import KNeighborsClassifier as KNN\n", 743 | "\n", 744 | "#Carico il dataset\n", 745 | "iris = datasets.load_iris()\n", 746 | "X, y = iris['data'], iris['target']\n", 747 | "\n", 748 | "#Scalo le feature tra 0 e 1\n", 749 | "scaler = MinMaxScaler()\n", 750 | "X = scaler.fit_transform(X)\n", 751 | "\n", 752 | "#Separo train , validation e test\n", 753 | "X, y = shuffle(X, y, random_state=123)\n", 754 | "X_tr, X_val, X_test = X[:75], X[75:100], X[100:]\n", 755 | "y_tr, y_val, y_test = y[:75], y[75:100], y[100:]\n", 756 | "\n", 757 | "print(X_tr.shape, X_val.shape, X_test.shape)" 758 | ] 759 | }, 760 | { 761 | "cell_type": "markdown", 762 | "metadata": {}, 763 | "source": [ 764 | "Ipotizziamo dei valori per $k$ e scegliamo quello che dà un risultato migliore sull'insieme di validazione." 765 | ] 766 | }, 767 | { 768 | "cell_type": "code", 769 | "execution_count": 27, 770 | "metadata": {}, 771 | "outputs": [ 772 | { 773 | "name": "stdout", 774 | "output_type": "stream", 775 | "text": [ 776 | "Validation accuracy with k 1: 0.92\n", 777 | "Validation accuracy with k 2: 0.96\n", 778 | "Validation accuracy with k 3: 0.92\n", 779 | "Validation accuracy with k 5: 0.92\n", 780 | "Validation accuracy with k 10: 0.92\n" 781 | ] 782 | } 783 | ], 784 | "source": [ 785 | "for k in [1,2,3,5,10]:\n", 786 | " model = KNN(n_neighbors=k)\n", 787 | " model.fit(X_tr, y_tr)\n", 788 | " predictions = model.predict(X_val)\n", 789 | " validation_accuracy = accuracy_score(y_val, predictions)\n", 790 | " print('Validation accuracy with k {}: {:.2f}'.format(k, validation_accuracy)) " 791 | ] 792 | }, 793 | { 794 | "cell_type": "markdown", 795 | "metadata": {}, 796 | "source": [ 797 | "Costruiamo un modello con il miglior $k$ e otteniamo le predizioni sul test." 798 | ] 799 | }, 800 | { 801 | "cell_type": "code", 802 | "execution_count": 29, 803 | "metadata": {}, 804 | "outputs": [ 805 | { 806 | "name": "stdout", 807 | "output_type": "stream", 808 | "text": [ 809 | "Test accuracy: 0.96\n" 810 | ] 811 | } 812 | ], 813 | "source": [ 814 | "best_model = KNN(n_neighbors=2)\n", 815 | "best_model.fit(X_tr, y_tr)\n", 816 | "predictions = best_model.predict(X_test)\n", 817 | "\n", 818 | "print('Test accuracy:', accuracy_score(y_test, predictions))" 819 | ] 820 | }, 821 | { 822 | "cell_type": "markdown", 823 | "metadata": {}, 824 | "source": [ 825 | "Alberi di decisione\n", 826 | "---\n", 827 | "Costruiamo adesso un *albero di decisione* (DT) ed utilizziamolo per la classificazione." 828 | ] 829 | }, 830 | { 831 | "cell_type": "code", 832 | "execution_count": 3, 833 | "metadata": {}, 834 | "outputs": [ 835 | { 836 | "data": { 837 | "text/plain": [ 838 | "DecisionTreeClassifier()" 839 | ] 840 | }, 841 | "execution_count": 3, 842 | "metadata": {}, 843 | "output_type": "execute_result" 844 | } 845 | ], 846 | "source": [ 847 | "from sklearn.tree import DecisionTreeClassifier as DT\n", 848 | "\n", 849 | "model = DT()" 850 | ] 851 | }, 852 | { 853 | "cell_type": "code", 854 | "execution_count": 37, 855 | "metadata": {}, 856 | "outputs": [ 857 | { 858 | "name": "stdout", 859 | "output_type": "stream", 860 | "text": [ 861 | "Accuracy on test set: 1.00\n" 862 | ] 863 | } 864 | ], 865 | "source": [ 866 | "predictions = model.fit(X_train, y_train).predict(X_test)\n", 867 | "accuracy = accuracy_score(y_test, predictions)\n", 868 | "\n", 869 | "print('Accuracy on test set: {:.2f}'.format(accuracy))" 870 | ] 871 | }, 872 | { 873 | "cell_type": "markdown", 874 | "metadata": {}, 875 | "source": [ 876 | "Notare come tutti i modelli di sklearn espongano le stesse funzioni." 877 | ] 878 | }, 879 | { 880 | "cell_type": "markdown", 881 | "metadata": {}, 882 | "source": [ 883 | "### *Esercizio 4*\n", 884 | "\n", 885 | "Provare a ripetere quanto visto per KNN, validando la profondità massima (*max_depth*) di un albero di decisione." 886 | ] 887 | }, 888 | { 889 | "cell_type": "markdown", 890 | "metadata": {}, 891 | "source": [ 892 | "\n", 900 | "\n", 901 | "" 904 | ] 905 | } 906 | ], 907 | "metadata": { 908 | "kernelspec": { 909 | "display_name": "Python 3", 910 | "language": "python", 911 | "name": "python3" 912 | }, 913 | "language_info": { 914 | "codemirror_mode": { 915 | "name": "ipython", 916 | "version": 3 917 | }, 918 | "file_extension": ".py", 919 | "mimetype": "text/x-python", 920 | "name": "python", 921 | "nbconvert_exporter": "python", 922 | "pygments_lexer": "ipython3", 923 | "version": "3.8.5" 924 | } 925 | }, 926 | "nbformat": 4, 927 | "nbformat_minor": 2 928 | } 929 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 francesco bagattini 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Corso introduttivo a Python e al suo ecosistema di strumenti per la Data Science: 2 | 3 | - jupyter 4 | - numpy 5 | - scipy 6 | - matplotlib 7 | - seaborn 8 | - sklearn 9 | - pandas 10 | -------------------------------------------------------------------------------- /data/parrot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fbagattini/An-introduction-to-Data-Science-with-Python/722fe35c1c5752bc24efa7d023e659b0ed815677/data/parrot.jpg -------------------------------------------------------------------------------- /data/titanic.csv: -------------------------------------------------------------------------------- 1 | PassengerId,Survived,Pclass,Name,Sex,Age,SibSp,Parch,Ticket,Fare,Cabin,Embarked 2 | 1,0,3,"Braund, Mr. Owen Harris",male,22,1,0,A/5 21171,7.25,,S 3 | 2,1,1,"Cumings, Mrs. John Bradley (Florence Briggs Thayer)",female,38,1,0,PC 17599,71.2833,C85,C 4 | 3,1,3,"Heikkinen, Miss. Laina",female,26,0,0,STON/O2. 3101282,7.925,,S 5 | 4,1,1,"Futrelle, Mrs. Jacques Heath (Lily May Peel)",female,35,1,0,113803,53.1,C123,S 6 | 5,0,3,"Allen, Mr. William Henry",male,35,0,0,373450,8.05,,S 7 | 6,0,3,"Moran, Mr. James",male,,0,0,330877,8.4583,,Q 8 | 7,0,1,"McCarthy, Mr. Timothy J",male,54,0,0,17463,51.8625,E46,S 9 | 8,0,3,"Palsson, Master. Gosta Leonard",male,2,3,1,349909,21.075,,S 10 | 9,1,3,"Johnson, Mrs. Oscar W (Elisabeth Vilhelmina Berg)",female,27,0,2,347742,11.1333,,S 11 | 10,1,2,"Nasser, Mrs. Nicholas (Adele Achem)",female,14,1,0,237736,30.0708,,C 12 | 11,1,3,"Sandstrom, Miss. Marguerite Rut",female,4,1,1,PP 9549,16.7,G6,S 13 | 12,1,1,"Bonnell, Miss. Elizabeth",female,58,0,0,113783,26.55,C103,S 14 | 13,0,3,"Saundercock, Mr. William Henry",male,20,0,0,A/5. 2151,8.05,,S 15 | 14,0,3,"Andersson, Mr. Anders Johan",male,39,1,5,347082,31.275,,S 16 | 15,0,3,"Vestrom, Miss. Hulda Amanda Adolfina",female,14,0,0,350406,7.8542,,S 17 | 16,1,2,"Hewlett, Mrs. (Mary D Kingcome) ",female,55,0,0,248706,16,,S 18 | 17,0,3,"Rice, Master. Eugene",male,2,4,1,382652,29.125,,Q 19 | 18,1,2,"Williams, Mr. Charles Eugene",male,,0,0,244373,13,,S 20 | 19,0,3,"Vander Planke, Mrs. Julius (Emelia Maria Vandemoortele)",female,31,1,0,345763,18,,S 21 | 20,1,3,"Masselmani, Mrs. Fatima",female,,0,0,2649,7.225,,C 22 | 21,0,2,"Fynney, Mr. Joseph J",male,35,0,0,239865,26,,S 23 | 22,1,2,"Beesley, Mr. Lawrence",male,34,0,0,248698,13,D56,S 24 | 23,1,3,"McGowan, Miss. Anna ""Annie""",female,15,0,0,330923,8.0292,,Q 25 | 24,1,1,"Sloper, Mr. William Thompson",male,28,0,0,113788,35.5,A6,S 26 | 25,0,3,"Palsson, Miss. Torborg Danira",female,8,3,1,349909,21.075,,S 27 | 26,1,3,"Asplund, Mrs. Carl Oscar (Selma Augusta Emilia Johansson)",female,38,1,5,347077,31.3875,,S 28 | 27,0,3,"Emir, Mr. Farred Chehab",male,,0,0,2631,7.225,,C 29 | 28,0,1,"Fortune, Mr. Charles Alexander",male,19,3,2,19950,263,C23 C25 C27,S 30 | 29,1,3,"O'Dwyer, Miss. Ellen ""Nellie""",female,,0,0,330959,7.8792,,Q 31 | 30,0,3,"Todoroff, Mr. Lalio",male,,0,0,349216,7.8958,,S 32 | 31,0,1,"Uruchurtu, Don. Manuel E",male,40,0,0,PC 17601,27.7208,,C 33 | 32,1,1,"Spencer, Mrs. William Augustus (Marie Eugenie)",female,,1,0,PC 17569,146.5208,B78,C 34 | 33,1,3,"Glynn, Miss. Mary Agatha",female,,0,0,335677,7.75,,Q 35 | 34,0,2,"Wheadon, Mr. Edward H",male,66,0,0,C.A. 24579,10.5,,S 36 | 35,0,1,"Meyer, Mr. Edgar Joseph",male,28,1,0,PC 17604,82.1708,,C 37 | 36,0,1,"Holverson, Mr. Alexander Oskar",male,42,1,0,113789,52,,S 38 | 37,1,3,"Mamee, Mr. Hanna",male,,0,0,2677,7.2292,,C 39 | 38,0,3,"Cann, Mr. Ernest Charles",male,21,0,0,A./5. 2152,8.05,,S 40 | 39,0,3,"Vander Planke, Miss. Augusta Maria",female,18,2,0,345764,18,,S 41 | 40,1,3,"Nicola-Yarred, Miss. Jamila",female,14,1,0,2651,11.2417,,C 42 | 41,0,3,"Ahlin, Mrs. Johan (Johanna Persdotter Larsson)",female,40,1,0,7546,9.475,,S 43 | 42,0,2,"Turpin, Mrs. William John Robert (Dorothy Ann Wonnacott)",female,27,1,0,11668,21,,S 44 | 43,0,3,"Kraeff, Mr. Theodor",male,,0,0,349253,7.8958,,C 45 | 44,1,2,"Laroche, Miss. Simonne Marie Anne Andree",female,3,1,2,SC/Paris 2123,41.5792,,C 46 | 45,1,3,"Devaney, Miss. Margaret Delia",female,19,0,0,330958,7.8792,,Q 47 | 46,0,3,"Rogers, Mr. William John",male,,0,0,S.C./A.4. 23567,8.05,,S 48 | 47,0,3,"Lennon, Mr. Denis",male,,1,0,370371,15.5,,Q 49 | 48,1,3,"O'Driscoll, Miss. Bridget",female,,0,0,14311,7.75,,Q 50 | 49,0,3,"Samaan, Mr. Youssef",male,,2,0,2662,21.6792,,C 51 | 50,0,3,"Arnold-Franchi, Mrs. Josef (Josefine Franchi)",female,18,1,0,349237,17.8,,S 52 | 51,0,3,"Panula, Master. Juha Niilo",male,7,4,1,3101295,39.6875,,S 53 | 52,0,3,"Nosworthy, Mr. Richard Cater",male,21,0,0,A/4. 39886,7.8,,S 54 | 53,1,1,"Harper, Mrs. Henry Sleeper (Myna Haxtun)",female,49,1,0,PC 17572,76.7292,D33,C 55 | 54,1,2,"Faunthorpe, Mrs. Lizzie (Elizabeth Anne Wilkinson)",female,29,1,0,2926,26,,S 56 | 55,0,1,"Ostby, Mr. Engelhart Cornelius",male,65,0,1,113509,61.9792,B30,C 57 | 56,1,1,"Woolner, Mr. Hugh",male,,0,0,19947,35.5,C52,S 58 | 57,1,2,"Rugg, Miss. Emily",female,21,0,0,C.A. 31026,10.5,,S 59 | 58,0,3,"Novel, Mr. Mansouer",male,28.5,0,0,2697,7.2292,,C 60 | 59,1,2,"West, Miss. Constance Mirium",female,5,1,2,C.A. 34651,27.75,,S 61 | 60,0,3,"Goodwin, Master. William Frederick",male,11,5,2,CA 2144,46.9,,S 62 | 61,0,3,"Sirayanian, Mr. Orsen",male,22,0,0,2669,7.2292,,C 63 | 62,1,1,"Icard, Miss. Amelie",female,38,0,0,113572,80,B28, 64 | 63,0,1,"Harris, Mr. Henry Birkhardt",male,45,1,0,36973,83.475,C83,S 65 | 64,0,3,"Skoog, Master. Harald",male,4,3,2,347088,27.9,,S 66 | 65,0,1,"Stewart, Mr. Albert A",male,,0,0,PC 17605,27.7208,,C 67 | 66,1,3,"Moubarek, Master. Gerios",male,,1,1,2661,15.2458,,C 68 | 67,1,2,"Nye, Mrs. (Elizabeth Ramell)",female,29,0,0,C.A. 29395,10.5,F33,S 69 | 68,0,3,"Crease, Mr. Ernest James",male,19,0,0,S.P. 3464,8.1583,,S 70 | 69,1,3,"Andersson, Miss. Erna Alexandra",female,17,4,2,3101281,7.925,,S 71 | 70,0,3,"Kink, Mr. Vincenz",male,26,2,0,315151,8.6625,,S 72 | 71,0,2,"Jenkin, Mr. Stephen Curnow",male,32,0,0,C.A. 33111,10.5,,S 73 | 72,0,3,"Goodwin, Miss. Lillian Amy",female,16,5,2,CA 2144,46.9,,S 74 | 73,0,2,"Hood, Mr. Ambrose Jr",male,21,0,0,S.O.C. 14879,73.5,,S 75 | 74,0,3,"Chronopoulos, Mr. Apostolos",male,26,1,0,2680,14.4542,,C 76 | 75,1,3,"Bing, Mr. Lee",male,32,0,0,1601,56.4958,,S 77 | 76,0,3,"Moen, Mr. Sigurd Hansen",male,25,0,0,348123,7.65,F G73,S 78 | 77,0,3,"Staneff, Mr. Ivan",male,,0,0,349208,7.8958,,S 79 | 78,0,3,"Moutal, Mr. Rahamin Haim",male,,0,0,374746,8.05,,S 80 | 79,1,2,"Caldwell, Master. Alden Gates",male,0.83,0,2,248738,29,,S 81 | 80,1,3,"Dowdell, Miss. Elizabeth",female,30,0,0,364516,12.475,,S 82 | 81,0,3,"Waelens, Mr. Achille",male,22,0,0,345767,9,,S 83 | 82,1,3,"Sheerlinck, Mr. Jan Baptist",male,29,0,0,345779,9.5,,S 84 | 83,1,3,"McDermott, Miss. Brigdet Delia",female,,0,0,330932,7.7875,,Q 85 | 84,0,1,"Carrau, Mr. Francisco M",male,28,0,0,113059,47.1,,S 86 | 85,1,2,"Ilett, Miss. Bertha",female,17,0,0,SO/C 14885,10.5,,S 87 | 86,1,3,"Backstrom, Mrs. Karl Alfred (Maria Mathilda Gustafsson)",female,33,3,0,3101278,15.85,,S 88 | 87,0,3,"Ford, Mr. William Neal",male,16,1,3,W./C. 6608,34.375,,S 89 | 88,0,3,"Slocovski, Mr. Selman Francis",male,,0,0,SOTON/OQ 392086,8.05,,S 90 | 89,1,1,"Fortune, Miss. Mabel Helen",female,23,3,2,19950,263,C23 C25 C27,S 91 | 90,0,3,"Celotti, Mr. Francesco",male,24,0,0,343275,8.05,,S 92 | 91,0,3,"Christmann, Mr. Emil",male,29,0,0,343276,8.05,,S 93 | 92,0,3,"Andreasson, Mr. Paul Edvin",male,20,0,0,347466,7.8542,,S 94 | 93,0,1,"Chaffee, Mr. Herbert Fuller",male,46,1,0,W.E.P. 5734,61.175,E31,S 95 | 94,0,3,"Dean, Mr. Bertram Frank",male,26,1,2,C.A. 2315,20.575,,S 96 | 95,0,3,"Coxon, Mr. Daniel",male,59,0,0,364500,7.25,,S 97 | 96,0,3,"Shorney, Mr. Charles Joseph",male,,0,0,374910,8.05,,S 98 | 97,0,1,"Goldschmidt, Mr. George B",male,71,0,0,PC 17754,34.6542,A5,C 99 | 98,1,1,"Greenfield, Mr. William Bertram",male,23,0,1,PC 17759,63.3583,D10 D12,C 100 | 99,1,2,"Doling, Mrs. John T (Ada Julia Bone)",female,34,0,1,231919,23,,S 101 | 100,0,2,"Kantor, Mr. Sinai",male,34,1,0,244367,26,,S 102 | 101,0,3,"Petranec, Miss. Matilda",female,28,0,0,349245,7.8958,,S 103 | 102,0,3,"Petroff, Mr. Pastcho (""Pentcho"")",male,,0,0,349215,7.8958,,S 104 | 103,0,1,"White, Mr. Richard Frasar",male,21,0,1,35281,77.2875,D26,S 105 | 104,0,3,"Johansson, Mr. Gustaf Joel",male,33,0,0,7540,8.6542,,S 106 | 105,0,3,"Gustafsson, Mr. Anders Vilhelm",male,37,2,0,3101276,7.925,,S 107 | 106,0,3,"Mionoff, Mr. Stoytcho",male,28,0,0,349207,7.8958,,S 108 | 107,1,3,"Salkjelsvik, Miss. Anna Kristine",female,21,0,0,343120,7.65,,S 109 | 108,1,3,"Moss, Mr. Albert Johan",male,,0,0,312991,7.775,,S 110 | 109,0,3,"Rekic, Mr. Tido",male,38,0,0,349249,7.8958,,S 111 | 110,1,3,"Moran, Miss. Bertha",female,,1,0,371110,24.15,,Q 112 | 111,0,1,"Porter, Mr. Walter Chamberlain",male,47,0,0,110465,52,C110,S 113 | 112,0,3,"Zabour, Miss. Hileni",female,14.5,1,0,2665,14.4542,,C 114 | 113,0,3,"Barton, Mr. David John",male,22,0,0,324669,8.05,,S 115 | 114,0,3,"Jussila, Miss. Katriina",female,20,1,0,4136,9.825,,S 116 | 115,0,3,"Attalah, Miss. Malake",female,17,0,0,2627,14.4583,,C 117 | 116,0,3,"Pekoniemi, Mr. Edvard",male,21,0,0,STON/O 2. 3101294,7.925,,S 118 | 117,0,3,"Connors, Mr. Patrick",male,70.5,0,0,370369,7.75,,Q 119 | 118,0,2,"Turpin, Mr. William John Robert",male,29,1,0,11668,21,,S 120 | 119,0,1,"Baxter, Mr. Quigg Edmond",male,24,0,1,PC 17558,247.5208,B58 B60,C 121 | 120,0,3,"Andersson, Miss. Ellis Anna Maria",female,2,4,2,347082,31.275,,S 122 | 121,0,2,"Hickman, Mr. Stanley George",male,21,2,0,S.O.C. 14879,73.5,,S 123 | 122,0,3,"Moore, Mr. Leonard Charles",male,,0,0,A4. 54510,8.05,,S 124 | 123,0,2,"Nasser, Mr. Nicholas",male,32.5,1,0,237736,30.0708,,C 125 | 124,1,2,"Webber, Miss. Susan",female,32.5,0,0,27267,13,E101,S 126 | 125,0,1,"White, Mr. Percival Wayland",male,54,0,1,35281,77.2875,D26,S 127 | 126,1,3,"Nicola-Yarred, Master. Elias",male,12,1,0,2651,11.2417,,C 128 | 127,0,3,"McMahon, Mr. Martin",male,,0,0,370372,7.75,,Q 129 | 128,1,3,"Madsen, Mr. Fridtjof Arne",male,24,0,0,C 17369,7.1417,,S 130 | 129,1,3,"Peter, Miss. Anna",female,,1,1,2668,22.3583,F E69,C 131 | 130,0,3,"Ekstrom, Mr. Johan",male,45,0,0,347061,6.975,,S 132 | 131,0,3,"Drazenoic, Mr. Jozef",male,33,0,0,349241,7.8958,,C 133 | 132,0,3,"Coelho, Mr. Domingos Fernandeo",male,20,0,0,SOTON/O.Q. 3101307,7.05,,S 134 | 133,0,3,"Robins, Mrs. Alexander A (Grace Charity Laury)",female,47,1,0,A/5. 3337,14.5,,S 135 | 134,1,2,"Weisz, Mrs. Leopold (Mathilde Francoise Pede)",female,29,1,0,228414,26,,S 136 | 135,0,2,"Sobey, Mr. Samuel James Hayden",male,25,0,0,C.A. 29178,13,,S 137 | 136,0,2,"Richard, Mr. Emile",male,23,0,0,SC/PARIS 2133,15.0458,,C 138 | 137,1,1,"Newsom, Miss. Helen Monypeny",female,19,0,2,11752,26.2833,D47,S 139 | 138,0,1,"Futrelle, Mr. Jacques Heath",male,37,1,0,113803,53.1,C123,S 140 | 139,0,3,"Osen, Mr. Olaf Elon",male,16,0,0,7534,9.2167,,S 141 | 140,0,1,"Giglio, Mr. Victor",male,24,0,0,PC 17593,79.2,B86,C 142 | 141,0,3,"Boulos, Mrs. Joseph (Sultana)",female,,0,2,2678,15.2458,,C 143 | 142,1,3,"Nysten, Miss. Anna Sofia",female,22,0,0,347081,7.75,,S 144 | 143,1,3,"Hakkarainen, Mrs. Pekka Pietari (Elin Matilda Dolck)",female,24,1,0,STON/O2. 3101279,15.85,,S 145 | 144,0,3,"Burke, Mr. Jeremiah",male,19,0,0,365222,6.75,,Q 146 | 145,0,2,"Andrew, Mr. Edgardo Samuel",male,18,0,0,231945,11.5,,S 147 | 146,0,2,"Nicholls, Mr. Joseph Charles",male,19,1,1,C.A. 33112,36.75,,S 148 | 147,1,3,"Andersson, Mr. August Edvard (""Wennerstrom"")",male,27,0,0,350043,7.7958,,S 149 | 148,0,3,"Ford, Miss. Robina Maggie ""Ruby""",female,9,2,2,W./C. 6608,34.375,,S 150 | 149,0,2,"Navratil, Mr. Michel (""Louis M Hoffman"")",male,36.5,0,2,230080,26,F2,S 151 | 150,0,2,"Byles, Rev. Thomas Roussel Davids",male,42,0,0,244310,13,,S 152 | 151,0,2,"Bateman, Rev. Robert James",male,51,0,0,S.O.P. 1166,12.525,,S 153 | 152,1,1,"Pears, Mrs. Thomas (Edith Wearne)",female,22,1,0,113776,66.6,C2,S 154 | 153,0,3,"Meo, Mr. Alfonzo",male,55.5,0,0,A.5. 11206,8.05,,S 155 | 154,0,3,"van Billiard, Mr. Austin Blyler",male,40.5,0,2,A/5. 851,14.5,,S 156 | 155,0,3,"Olsen, Mr. Ole Martin",male,,0,0,Fa 265302,7.3125,,S 157 | 156,0,1,"Williams, Mr. Charles Duane",male,51,0,1,PC 17597,61.3792,,C 158 | 157,1,3,"Gilnagh, Miss. Katherine ""Katie""",female,16,0,0,35851,7.7333,,Q 159 | 158,0,3,"Corn, Mr. Harry",male,30,0,0,SOTON/OQ 392090,8.05,,S 160 | 159,0,3,"Smiljanic, Mr. Mile",male,,0,0,315037,8.6625,,S 161 | 160,0,3,"Sage, Master. Thomas Henry",male,,8,2,CA. 2343,69.55,,S 162 | 161,0,3,"Cribb, Mr. John Hatfield",male,44,0,1,371362,16.1,,S 163 | 162,1,2,"Watt, Mrs. James (Elizabeth ""Bessie"" Inglis Milne)",female,40,0,0,C.A. 33595,15.75,,S 164 | 163,0,3,"Bengtsson, Mr. John Viktor",male,26,0,0,347068,7.775,,S 165 | 164,0,3,"Calic, Mr. Jovo",male,17,0,0,315093,8.6625,,S 166 | 165,0,3,"Panula, Master. Eino Viljami",male,1,4,1,3101295,39.6875,,S 167 | 166,1,3,"Goldsmith, Master. Frank John William ""Frankie""",male,9,0,2,363291,20.525,,S 168 | 167,1,1,"Chibnall, Mrs. (Edith Martha Bowerman)",female,,0,1,113505,55,E33,S 169 | 168,0,3,"Skoog, Mrs. William (Anna Bernhardina Karlsson)",female,45,1,4,347088,27.9,,S 170 | 169,0,1,"Baumann, Mr. John D",male,,0,0,PC 17318,25.925,,S 171 | 170,0,3,"Ling, Mr. Lee",male,28,0,0,1601,56.4958,,S 172 | 171,0,1,"Van der hoef, Mr. Wyckoff",male,61,0,0,111240,33.5,B19,S 173 | 172,0,3,"Rice, Master. Arthur",male,4,4,1,382652,29.125,,Q 174 | 173,1,3,"Johnson, Miss. Eleanor Ileen",female,1,1,1,347742,11.1333,,S 175 | 174,0,3,"Sivola, Mr. Antti Wilhelm",male,21,0,0,STON/O 2. 3101280,7.925,,S 176 | 175,0,1,"Smith, Mr. James Clinch",male,56,0,0,17764,30.6958,A7,C 177 | 176,0,3,"Klasen, Mr. Klas Albin",male,18,1,1,350404,7.8542,,S 178 | 177,0,3,"Lefebre, Master. Henry Forbes",male,,3,1,4133,25.4667,,S 179 | 178,0,1,"Isham, Miss. Ann Elizabeth",female,50,0,0,PC 17595,28.7125,C49,C 180 | 179,0,2,"Hale, Mr. Reginald",male,30,0,0,250653,13,,S 181 | 180,0,3,"Leonard, Mr. Lionel",male,36,0,0,LINE,0,,S 182 | 181,0,3,"Sage, Miss. Constance Gladys",female,,8,2,CA. 2343,69.55,,S 183 | 182,0,2,"Pernot, Mr. Rene",male,,0,0,SC/PARIS 2131,15.05,,C 184 | 183,0,3,"Asplund, Master. Clarence Gustaf Hugo",male,9,4,2,347077,31.3875,,S 185 | 184,1,2,"Becker, Master. Richard F",male,1,2,1,230136,39,F4,S 186 | 185,1,3,"Kink-Heilmann, Miss. Luise Gretchen",female,4,0,2,315153,22.025,,S 187 | 186,0,1,"Rood, Mr. Hugh Roscoe",male,,0,0,113767,50,A32,S 188 | 187,1,3,"O'Brien, Mrs. Thomas (Johanna ""Hannah"" Godfrey)",female,,1,0,370365,15.5,,Q 189 | 188,1,1,"Romaine, Mr. Charles Hallace (""Mr C Rolmane"")",male,45,0,0,111428,26.55,,S 190 | 189,0,3,"Bourke, Mr. John",male,40,1,1,364849,15.5,,Q 191 | 190,0,3,"Turcin, Mr. Stjepan",male,36,0,0,349247,7.8958,,S 192 | 191,1,2,"Pinsky, Mrs. (Rosa)",female,32,0,0,234604,13,,S 193 | 192,0,2,"Carbines, Mr. William",male,19,0,0,28424,13,,S 194 | 193,1,3,"Andersen-Jensen, Miss. Carla Christine Nielsine",female,19,1,0,350046,7.8542,,S 195 | 194,1,2,"Navratil, Master. Michel M",male,3,1,1,230080,26,F2,S 196 | 195,1,1,"Brown, Mrs. James Joseph (Margaret Tobin)",female,44,0,0,PC 17610,27.7208,B4,C 197 | 196,1,1,"Lurette, Miss. Elise",female,58,0,0,PC 17569,146.5208,B80,C 198 | 197,0,3,"Mernagh, Mr. Robert",male,,0,0,368703,7.75,,Q 199 | 198,0,3,"Olsen, Mr. Karl Siegwart Andreas",male,42,0,1,4579,8.4042,,S 200 | 199,1,3,"Madigan, Miss. Margaret ""Maggie""",female,,0,0,370370,7.75,,Q 201 | 200,0,2,"Yrois, Miss. Henriette (""Mrs Harbeck"")",female,24,0,0,248747,13,,S 202 | 201,0,3,"Vande Walle, Mr. Nestor Cyriel",male,28,0,0,345770,9.5,,S 203 | 202,0,3,"Sage, Mr. Frederick",male,,8,2,CA. 2343,69.55,,S 204 | 203,0,3,"Johanson, Mr. Jakob Alfred",male,34,0,0,3101264,6.4958,,S 205 | 204,0,3,"Youseff, Mr. Gerious",male,45.5,0,0,2628,7.225,,C 206 | 205,1,3,"Cohen, Mr. Gurshon ""Gus""",male,18,0,0,A/5 3540,8.05,,S 207 | 206,0,3,"Strom, Miss. Telma Matilda",female,2,0,1,347054,10.4625,G6,S 208 | 207,0,3,"Backstrom, Mr. Karl Alfred",male,32,1,0,3101278,15.85,,S 209 | 208,1,3,"Albimona, Mr. Nassef Cassem",male,26,0,0,2699,18.7875,,C 210 | 209,1,3,"Carr, Miss. Helen ""Ellen""",female,16,0,0,367231,7.75,,Q 211 | 210,1,1,"Blank, Mr. Henry",male,40,0,0,112277,31,A31,C 212 | 211,0,3,"Ali, Mr. Ahmed",male,24,0,0,SOTON/O.Q. 3101311,7.05,,S 213 | 212,1,2,"Cameron, Miss. Clear Annie",female,35,0,0,F.C.C. 13528,21,,S 214 | 213,0,3,"Perkin, Mr. John Henry",male,22,0,0,A/5 21174,7.25,,S 215 | 214,0,2,"Givard, Mr. Hans Kristensen",male,30,0,0,250646,13,,S 216 | 215,0,3,"Kiernan, Mr. Philip",male,,1,0,367229,7.75,,Q 217 | 216,1,1,"Newell, Miss. Madeleine",female,31,1,0,35273,113.275,D36,C 218 | 217,1,3,"Honkanen, Miss. Eliina",female,27,0,0,STON/O2. 3101283,7.925,,S 219 | 218,0,2,"Jacobsohn, Mr. Sidney Samuel",male,42,1,0,243847,27,,S 220 | 219,1,1,"Bazzani, Miss. Albina",female,32,0,0,11813,76.2917,D15,C 221 | 220,0,2,"Harris, Mr. Walter",male,30,0,0,W/C 14208,10.5,,S 222 | 221,1,3,"Sunderland, Mr. Victor Francis",male,16,0,0,SOTON/OQ 392089,8.05,,S 223 | 222,0,2,"Bracken, Mr. James H",male,27,0,0,220367,13,,S 224 | 223,0,3,"Green, Mr. George Henry",male,51,0,0,21440,8.05,,S 225 | 224,0,3,"Nenkoff, Mr. Christo",male,,0,0,349234,7.8958,,S 226 | 225,1,1,"Hoyt, Mr. Frederick Maxfield",male,38,1,0,19943,90,C93,S 227 | 226,0,3,"Berglund, Mr. Karl Ivar Sven",male,22,0,0,PP 4348,9.35,,S 228 | 227,1,2,"Mellors, Mr. William John",male,19,0,0,SW/PP 751,10.5,,S 229 | 228,0,3,"Lovell, Mr. John Hall (""Henry"")",male,20.5,0,0,A/5 21173,7.25,,S 230 | 229,0,2,"Fahlstrom, Mr. Arne Jonas",male,18,0,0,236171,13,,S 231 | 230,0,3,"Lefebre, Miss. Mathilde",female,,3,1,4133,25.4667,,S 232 | 231,1,1,"Harris, Mrs. Henry Birkhardt (Irene Wallach)",female,35,1,0,36973,83.475,C83,S 233 | 232,0,3,"Larsson, Mr. Bengt Edvin",male,29,0,0,347067,7.775,,S 234 | 233,0,2,"Sjostedt, Mr. Ernst Adolf",male,59,0,0,237442,13.5,,S 235 | 234,1,3,"Asplund, Miss. Lillian Gertrud",female,5,4,2,347077,31.3875,,S 236 | 235,0,2,"Leyson, Mr. Robert William Norman",male,24,0,0,C.A. 29566,10.5,,S 237 | 236,0,3,"Harknett, Miss. Alice Phoebe",female,,0,0,W./C. 6609,7.55,,S 238 | 237,0,2,"Hold, Mr. Stephen",male,44,1,0,26707,26,,S 239 | 238,1,2,"Collyer, Miss. Marjorie ""Lottie""",female,8,0,2,C.A. 31921,26.25,,S 240 | 239,0,2,"Pengelly, Mr. Frederick William",male,19,0,0,28665,10.5,,S 241 | 240,0,2,"Hunt, Mr. George Henry",male,33,0,0,SCO/W 1585,12.275,,S 242 | 241,0,3,"Zabour, Miss. Thamine",female,,1,0,2665,14.4542,,C 243 | 242,1,3,"Murphy, Miss. Katherine ""Kate""",female,,1,0,367230,15.5,,Q 244 | 243,0,2,"Coleridge, Mr. Reginald Charles",male,29,0,0,W./C. 14263,10.5,,S 245 | 244,0,3,"Maenpaa, Mr. Matti Alexanteri",male,22,0,0,STON/O 2. 3101275,7.125,,S 246 | 245,0,3,"Attalah, Mr. Sleiman",male,30,0,0,2694,7.225,,C 247 | 246,0,1,"Minahan, Dr. William Edward",male,44,2,0,19928,90,C78,Q 248 | 247,0,3,"Lindahl, Miss. Agda Thorilda Viktoria",female,25,0,0,347071,7.775,,S 249 | 248,1,2,"Hamalainen, Mrs. William (Anna)",female,24,0,2,250649,14.5,,S 250 | 249,1,1,"Beckwith, Mr. Richard Leonard",male,37,1,1,11751,52.5542,D35,S 251 | 250,0,2,"Carter, Rev. Ernest Courtenay",male,54,1,0,244252,26,,S 252 | 251,0,3,"Reed, Mr. James George",male,,0,0,362316,7.25,,S 253 | 252,0,3,"Strom, Mrs. Wilhelm (Elna Matilda Persson)",female,29,1,1,347054,10.4625,G6,S 254 | 253,0,1,"Stead, Mr. William Thomas",male,62,0,0,113514,26.55,C87,S 255 | 254,0,3,"Lobb, Mr. William Arthur",male,30,1,0,A/5. 3336,16.1,,S 256 | 255,0,3,"Rosblom, Mrs. Viktor (Helena Wilhelmina)",female,41,0,2,370129,20.2125,,S 257 | 256,1,3,"Touma, Mrs. Darwis (Hanne Youssef Razi)",female,29,0,2,2650,15.2458,,C 258 | 257,1,1,"Thorne, Mrs. Gertrude Maybelle",female,,0,0,PC 17585,79.2,,C 259 | 258,1,1,"Cherry, Miss. Gladys",female,30,0,0,110152,86.5,B77,S 260 | 259,1,1,"Ward, Miss. Anna",female,35,0,0,PC 17755,512.3292,,C 261 | 260,1,2,"Parrish, Mrs. (Lutie Davis)",female,50,0,1,230433,26,,S 262 | 261,0,3,"Smith, Mr. Thomas",male,,0,0,384461,7.75,,Q 263 | 262,1,3,"Asplund, Master. Edvin Rojj Felix",male,3,4,2,347077,31.3875,,S 264 | 263,0,1,"Taussig, Mr. Emil",male,52,1,1,110413,79.65,E67,S 265 | 264,0,1,"Harrison, Mr. William",male,40,0,0,112059,0,B94,S 266 | 265,0,3,"Henry, Miss. Delia",female,,0,0,382649,7.75,,Q 267 | 266,0,2,"Reeves, Mr. David",male,36,0,0,C.A. 17248,10.5,,S 268 | 267,0,3,"Panula, Mr. Ernesti Arvid",male,16,4,1,3101295,39.6875,,S 269 | 268,1,3,"Persson, Mr. Ernst Ulrik",male,25,1,0,347083,7.775,,S 270 | 269,1,1,"Graham, Mrs. William Thompson (Edith Junkins)",female,58,0,1,PC 17582,153.4625,C125,S 271 | 270,1,1,"Bissette, Miss. Amelia",female,35,0,0,PC 17760,135.6333,C99,S 272 | 271,0,1,"Cairns, Mr. Alexander",male,,0,0,113798,31,,S 273 | 272,1,3,"Tornquist, Mr. William Henry",male,25,0,0,LINE,0,,S 274 | 273,1,2,"Mellinger, Mrs. (Elizabeth Anne Maidment)",female,41,0,1,250644,19.5,,S 275 | 274,0,1,"Natsch, Mr. Charles H",male,37,0,1,PC 17596,29.7,C118,C 276 | 275,1,3,"Healy, Miss. Hanora ""Nora""",female,,0,0,370375,7.75,,Q 277 | 276,1,1,"Andrews, Miss. Kornelia Theodosia",female,63,1,0,13502,77.9583,D7,S 278 | 277,0,3,"Lindblom, Miss. Augusta Charlotta",female,45,0,0,347073,7.75,,S 279 | 278,0,2,"Parkes, Mr. Francis ""Frank""",male,,0,0,239853,0,,S 280 | 279,0,3,"Rice, Master. Eric",male,7,4,1,382652,29.125,,Q 281 | 280,1,3,"Abbott, Mrs. Stanton (Rosa Hunt)",female,35,1,1,C.A. 2673,20.25,,S 282 | 281,0,3,"Duane, Mr. Frank",male,65,0,0,336439,7.75,,Q 283 | 282,0,3,"Olsson, Mr. Nils Johan Goransson",male,28,0,0,347464,7.8542,,S 284 | 283,0,3,"de Pelsmaeker, Mr. Alfons",male,16,0,0,345778,9.5,,S 285 | 284,1,3,"Dorking, Mr. Edward Arthur",male,19,0,0,A/5. 10482,8.05,,S 286 | 285,0,1,"Smith, Mr. Richard William",male,,0,0,113056,26,A19,S 287 | 286,0,3,"Stankovic, Mr. Ivan",male,33,0,0,349239,8.6625,,C 288 | 287,1,3,"de Mulder, Mr. Theodore",male,30,0,0,345774,9.5,,S 289 | 288,0,3,"Naidenoff, Mr. Penko",male,22,0,0,349206,7.8958,,S 290 | 289,1,2,"Hosono, Mr. Masabumi",male,42,0,0,237798,13,,S 291 | 290,1,3,"Connolly, Miss. Kate",female,22,0,0,370373,7.75,,Q 292 | 291,1,1,"Barber, Miss. Ellen ""Nellie""",female,26,0,0,19877,78.85,,S 293 | 292,1,1,"Bishop, Mrs. Dickinson H (Helen Walton)",female,19,1,0,11967,91.0792,B49,C 294 | 293,0,2,"Levy, Mr. Rene Jacques",male,36,0,0,SC/Paris 2163,12.875,D,C 295 | 294,0,3,"Haas, Miss. Aloisia",female,24,0,0,349236,8.85,,S 296 | 295,0,3,"Mineff, Mr. Ivan",male,24,0,0,349233,7.8958,,S 297 | 296,0,1,"Lewy, Mr. Ervin G",male,,0,0,PC 17612,27.7208,,C 298 | 297,0,3,"Hanna, Mr. Mansour",male,23.5,0,0,2693,7.2292,,C 299 | 298,0,1,"Allison, Miss. Helen Loraine",female,2,1,2,113781,151.55,C22 C26,S 300 | 299,1,1,"Saalfeld, Mr. Adolphe",male,,0,0,19988,30.5,C106,S 301 | 300,1,1,"Baxter, Mrs. James (Helene DeLaudeniere Chaput)",female,50,0,1,PC 17558,247.5208,B58 B60,C 302 | 301,1,3,"Kelly, Miss. Anna Katherine ""Annie Kate""",female,,0,0,9234,7.75,,Q 303 | 302,1,3,"McCoy, Mr. Bernard",male,,2,0,367226,23.25,,Q 304 | 303,0,3,"Johnson, Mr. William Cahoone Jr",male,19,0,0,LINE,0,,S 305 | 304,1,2,"Keane, Miss. Nora A",female,,0,0,226593,12.35,E101,Q 306 | 305,0,3,"Williams, Mr. Howard Hugh ""Harry""",male,,0,0,A/5 2466,8.05,,S 307 | 306,1,1,"Allison, Master. Hudson Trevor",male,0.92,1,2,113781,151.55,C22 C26,S 308 | 307,1,1,"Fleming, Miss. Margaret",female,,0,0,17421,110.8833,,C 309 | 308,1,1,"Penasco y Castellana, Mrs. Victor de Satode (Maria Josefa Perez de Soto y Vallejo)",female,17,1,0,PC 17758,108.9,C65,C 310 | 309,0,2,"Abelson, Mr. Samuel",male,30,1,0,P/PP 3381,24,,C 311 | 310,1,1,"Francatelli, Miss. Laura Mabel",female,30,0,0,PC 17485,56.9292,E36,C 312 | 311,1,1,"Hays, Miss. Margaret Bechstein",female,24,0,0,11767,83.1583,C54,C 313 | 312,1,1,"Ryerson, Miss. Emily Borie",female,18,2,2,PC 17608,262.375,B57 B59 B63 B66,C 314 | 313,0,2,"Lahtinen, Mrs. William (Anna Sylfven)",female,26,1,1,250651,26,,S 315 | 314,0,3,"Hendekovic, Mr. Ignjac",male,28,0,0,349243,7.8958,,S 316 | 315,0,2,"Hart, Mr. Benjamin",male,43,1,1,F.C.C. 13529,26.25,,S 317 | 316,1,3,"Nilsson, Miss. Helmina Josefina",female,26,0,0,347470,7.8542,,S 318 | 317,1,2,"Kantor, Mrs. Sinai (Miriam Sternin)",female,24,1,0,244367,26,,S 319 | 318,0,2,"Moraweck, Dr. Ernest",male,54,0,0,29011,14,,S 320 | 319,1,1,"Wick, Miss. Mary Natalie",female,31,0,2,36928,164.8667,C7,S 321 | 320,1,1,"Spedden, Mrs. Frederic Oakley (Margaretta Corning Stone)",female,40,1,1,16966,134.5,E34,C 322 | 321,0,3,"Dennis, Mr. Samuel",male,22,0,0,A/5 21172,7.25,,S 323 | 322,0,3,"Danoff, Mr. Yoto",male,27,0,0,349219,7.8958,,S 324 | 323,1,2,"Slayter, Miss. Hilda Mary",female,30,0,0,234818,12.35,,Q 325 | 324,1,2,"Caldwell, Mrs. Albert Francis (Sylvia Mae Harbaugh)",female,22,1,1,248738,29,,S 326 | 325,0,3,"Sage, Mr. George John Jr",male,,8,2,CA. 2343,69.55,,S 327 | 326,1,1,"Young, Miss. Marie Grice",female,36,0,0,PC 17760,135.6333,C32,C 328 | 327,0,3,"Nysveen, Mr. Johan Hansen",male,61,0,0,345364,6.2375,,S 329 | 328,1,2,"Ball, Mrs. (Ada E Hall)",female,36,0,0,28551,13,D,S 330 | 329,1,3,"Goldsmith, Mrs. Frank John (Emily Alice Brown)",female,31,1,1,363291,20.525,,S 331 | 330,1,1,"Hippach, Miss. Jean Gertrude",female,16,0,1,111361,57.9792,B18,C 332 | 331,1,3,"McCoy, Miss. Agnes",female,,2,0,367226,23.25,,Q 333 | 332,0,1,"Partner, Mr. Austen",male,45.5,0,0,113043,28.5,C124,S 334 | 333,0,1,"Graham, Mr. George Edward",male,38,0,1,PC 17582,153.4625,C91,S 335 | 334,0,3,"Vander Planke, Mr. Leo Edmondus",male,16,2,0,345764,18,,S 336 | 335,1,1,"Frauenthal, Mrs. Henry William (Clara Heinsheimer)",female,,1,0,PC 17611,133.65,,S 337 | 336,0,3,"Denkoff, Mr. Mitto",male,,0,0,349225,7.8958,,S 338 | 337,0,1,"Pears, Mr. Thomas Clinton",male,29,1,0,113776,66.6,C2,S 339 | 338,1,1,"Burns, Miss. Elizabeth Margaret",female,41,0,0,16966,134.5,E40,C 340 | 339,1,3,"Dahl, Mr. Karl Edwart",male,45,0,0,7598,8.05,,S 341 | 340,0,1,"Blackwell, Mr. Stephen Weart",male,45,0,0,113784,35.5,T,S 342 | 341,1,2,"Navratil, Master. Edmond Roger",male,2,1,1,230080,26,F2,S 343 | 342,1,1,"Fortune, Miss. Alice Elizabeth",female,24,3,2,19950,263,C23 C25 C27,S 344 | 343,0,2,"Collander, Mr. Erik Gustaf",male,28,0,0,248740,13,,S 345 | 344,0,2,"Sedgwick, Mr. Charles Frederick Waddington",male,25,0,0,244361,13,,S 346 | 345,0,2,"Fox, Mr. Stanley Hubert",male,36,0,0,229236,13,,S 347 | 346,1,2,"Brown, Miss. Amelia ""Mildred""",female,24,0,0,248733,13,F33,S 348 | 347,1,2,"Smith, Miss. Marion Elsie",female,40,0,0,31418,13,,S 349 | 348,1,3,"Davison, Mrs. Thomas Henry (Mary E Finck)",female,,1,0,386525,16.1,,S 350 | 349,1,3,"Coutts, Master. William Loch ""William""",male,3,1,1,C.A. 37671,15.9,,S 351 | 350,0,3,"Dimic, Mr. Jovan",male,42,0,0,315088,8.6625,,S 352 | 351,0,3,"Odahl, Mr. Nils Martin",male,23,0,0,7267,9.225,,S 353 | 352,0,1,"Williams-Lambert, Mr. Fletcher Fellows",male,,0,0,113510,35,C128,S 354 | 353,0,3,"Elias, Mr. Tannous",male,15,1,1,2695,7.2292,,C 355 | 354,0,3,"Arnold-Franchi, Mr. Josef",male,25,1,0,349237,17.8,,S 356 | 355,0,3,"Yousif, Mr. Wazli",male,,0,0,2647,7.225,,C 357 | 356,0,3,"Vanden Steen, Mr. Leo Peter",male,28,0,0,345783,9.5,,S 358 | 357,1,1,"Bowerman, Miss. Elsie Edith",female,22,0,1,113505,55,E33,S 359 | 358,0,2,"Funk, Miss. Annie Clemmer",female,38,0,0,237671,13,,S 360 | 359,1,3,"McGovern, Miss. Mary",female,,0,0,330931,7.8792,,Q 361 | 360,1,3,"Mockler, Miss. Helen Mary ""Ellie""",female,,0,0,330980,7.8792,,Q 362 | 361,0,3,"Skoog, Mr. Wilhelm",male,40,1,4,347088,27.9,,S 363 | 362,0,2,"del Carlo, Mr. Sebastiano",male,29,1,0,SC/PARIS 2167,27.7208,,C 364 | 363,0,3,"Barbara, Mrs. (Catherine David)",female,45,0,1,2691,14.4542,,C 365 | 364,0,3,"Asim, Mr. Adola",male,35,0,0,SOTON/O.Q. 3101310,7.05,,S 366 | 365,0,3,"O'Brien, Mr. Thomas",male,,1,0,370365,15.5,,Q 367 | 366,0,3,"Adahl, Mr. Mauritz Nils Martin",male,30,0,0,C 7076,7.25,,S 368 | 367,1,1,"Warren, Mrs. Frank Manley (Anna Sophia Atkinson)",female,60,1,0,110813,75.25,D37,C 369 | 368,1,3,"Moussa, Mrs. (Mantoura Boulos)",female,,0,0,2626,7.2292,,C 370 | 369,1,3,"Jermyn, Miss. Annie",female,,0,0,14313,7.75,,Q 371 | 370,1,1,"Aubart, Mme. Leontine Pauline",female,24,0,0,PC 17477,69.3,B35,C 372 | 371,1,1,"Harder, Mr. George Achilles",male,25,1,0,11765,55.4417,E50,C 373 | 372,0,3,"Wiklund, Mr. Jakob Alfred",male,18,1,0,3101267,6.4958,,S 374 | 373,0,3,"Beavan, Mr. William Thomas",male,19,0,0,323951,8.05,,S 375 | 374,0,1,"Ringhini, Mr. Sante",male,22,0,0,PC 17760,135.6333,,C 376 | 375,0,3,"Palsson, Miss. Stina Viola",female,3,3,1,349909,21.075,,S 377 | 376,1,1,"Meyer, Mrs. Edgar Joseph (Leila Saks)",female,,1,0,PC 17604,82.1708,,C 378 | 377,1,3,"Landergren, Miss. Aurora Adelia",female,22,0,0,C 7077,7.25,,S 379 | 378,0,1,"Widener, Mr. Harry Elkins",male,27,0,2,113503,211.5,C82,C 380 | 379,0,3,"Betros, Mr. Tannous",male,20,0,0,2648,4.0125,,C 381 | 380,0,3,"Gustafsson, Mr. Karl Gideon",male,19,0,0,347069,7.775,,S 382 | 381,1,1,"Bidois, Miss. Rosalie",female,42,0,0,PC 17757,227.525,,C 383 | 382,1,3,"Nakid, Miss. Maria (""Mary"")",female,1,0,2,2653,15.7417,,C 384 | 383,0,3,"Tikkanen, Mr. Juho",male,32,0,0,STON/O 2. 3101293,7.925,,S 385 | 384,1,1,"Holverson, Mrs. Alexander Oskar (Mary Aline Towner)",female,35,1,0,113789,52,,S 386 | 385,0,3,"Plotcharsky, Mr. Vasil",male,,0,0,349227,7.8958,,S 387 | 386,0,2,"Davies, Mr. Charles Henry",male,18,0,0,S.O.C. 14879,73.5,,S 388 | 387,0,3,"Goodwin, Master. Sidney Leonard",male,1,5,2,CA 2144,46.9,,S 389 | 388,1,2,"Buss, Miss. Kate",female,36,0,0,27849,13,,S 390 | 389,0,3,"Sadlier, Mr. Matthew",male,,0,0,367655,7.7292,,Q 391 | 390,1,2,"Lehmann, Miss. Bertha",female,17,0,0,SC 1748,12,,C 392 | 391,1,1,"Carter, Mr. William Ernest",male,36,1,2,113760,120,B96 B98,S 393 | 392,1,3,"Jansson, Mr. Carl Olof",male,21,0,0,350034,7.7958,,S 394 | 393,0,3,"Gustafsson, Mr. Johan Birger",male,28,2,0,3101277,7.925,,S 395 | 394,1,1,"Newell, Miss. Marjorie",female,23,1,0,35273,113.275,D36,C 396 | 395,1,3,"Sandstrom, Mrs. Hjalmar (Agnes Charlotta Bengtsson)",female,24,0,2,PP 9549,16.7,G6,S 397 | 396,0,3,"Johansson, Mr. Erik",male,22,0,0,350052,7.7958,,S 398 | 397,0,3,"Olsson, Miss. Elina",female,31,0,0,350407,7.8542,,S 399 | 398,0,2,"McKane, Mr. Peter David",male,46,0,0,28403,26,,S 400 | 399,0,2,"Pain, Dr. Alfred",male,23,0,0,244278,10.5,,S 401 | 400,1,2,"Trout, Mrs. William H (Jessie L)",female,28,0,0,240929,12.65,,S 402 | 401,1,3,"Niskanen, Mr. Juha",male,39,0,0,STON/O 2. 3101289,7.925,,S 403 | 402,0,3,"Adams, Mr. John",male,26,0,0,341826,8.05,,S 404 | 403,0,3,"Jussila, Miss. Mari Aina",female,21,1,0,4137,9.825,,S 405 | 404,0,3,"Hakkarainen, Mr. Pekka Pietari",male,28,1,0,STON/O2. 3101279,15.85,,S 406 | 405,0,3,"Oreskovic, Miss. Marija",female,20,0,0,315096,8.6625,,S 407 | 406,0,2,"Gale, Mr. Shadrach",male,34,1,0,28664,21,,S 408 | 407,0,3,"Widegren, Mr. Carl/Charles Peter",male,51,0,0,347064,7.75,,S 409 | 408,1,2,"Richards, Master. William Rowe",male,3,1,1,29106,18.75,,S 410 | 409,0,3,"Birkeland, Mr. Hans Martin Monsen",male,21,0,0,312992,7.775,,S 411 | 410,0,3,"Lefebre, Miss. Ida",female,,3,1,4133,25.4667,,S 412 | 411,0,3,"Sdycoff, Mr. Todor",male,,0,0,349222,7.8958,,S 413 | 412,0,3,"Hart, Mr. Henry",male,,0,0,394140,6.8583,,Q 414 | 413,1,1,"Minahan, Miss. Daisy E",female,33,1,0,19928,90,C78,Q 415 | 414,0,2,"Cunningham, Mr. Alfred Fleming",male,,0,0,239853,0,,S 416 | 415,1,3,"Sundman, Mr. Johan Julian",male,44,0,0,STON/O 2. 3101269,7.925,,S 417 | 416,0,3,"Meek, Mrs. Thomas (Annie Louise Rowley)",female,,0,0,343095,8.05,,S 418 | 417,1,2,"Drew, Mrs. James Vivian (Lulu Thorne Christian)",female,34,1,1,28220,32.5,,S 419 | 418,1,2,"Silven, Miss. Lyyli Karoliina",female,18,0,2,250652,13,,S 420 | 419,0,2,"Matthews, Mr. William John",male,30,0,0,28228,13,,S 421 | 420,0,3,"Van Impe, Miss. Catharina",female,10,0,2,345773,24.15,,S 422 | 421,0,3,"Gheorgheff, Mr. Stanio",male,,0,0,349254,7.8958,,C 423 | 422,0,3,"Charters, Mr. David",male,21,0,0,A/5. 13032,7.7333,,Q 424 | 423,0,3,"Zimmerman, Mr. Leo",male,29,0,0,315082,7.875,,S 425 | 424,0,3,"Danbom, Mrs. Ernst Gilbert (Anna Sigrid Maria Brogren)",female,28,1,1,347080,14.4,,S 426 | 425,0,3,"Rosblom, Mr. Viktor Richard",male,18,1,1,370129,20.2125,,S 427 | 426,0,3,"Wiseman, Mr. Phillippe",male,,0,0,A/4. 34244,7.25,,S 428 | 427,1,2,"Clarke, Mrs. Charles V (Ada Maria Winfield)",female,28,1,0,2003,26,,S 429 | 428,1,2,"Phillips, Miss. Kate Florence (""Mrs Kate Louise Phillips Marshall"")",female,19,0,0,250655,26,,S 430 | 429,0,3,"Flynn, Mr. James",male,,0,0,364851,7.75,,Q 431 | 430,1,3,"Pickard, Mr. Berk (Berk Trembisky)",male,32,0,0,SOTON/O.Q. 392078,8.05,E10,S 432 | 431,1,1,"Bjornstrom-Steffansson, Mr. Mauritz Hakan",male,28,0,0,110564,26.55,C52,S 433 | 432,1,3,"Thorneycroft, Mrs. Percival (Florence Kate White)",female,,1,0,376564,16.1,,S 434 | 433,1,2,"Louch, Mrs. Charles Alexander (Alice Adelaide Slow)",female,42,1,0,SC/AH 3085,26,,S 435 | 434,0,3,"Kallio, Mr. Nikolai Erland",male,17,0,0,STON/O 2. 3101274,7.125,,S 436 | 435,0,1,"Silvey, Mr. William Baird",male,50,1,0,13507,55.9,E44,S 437 | 436,1,1,"Carter, Miss. Lucile Polk",female,14,1,2,113760,120,B96 B98,S 438 | 437,0,3,"Ford, Miss. Doolina Margaret ""Daisy""",female,21,2,2,W./C. 6608,34.375,,S 439 | 438,1,2,"Richards, Mrs. Sidney (Emily Hocking)",female,24,2,3,29106,18.75,,S 440 | 439,0,1,"Fortune, Mr. Mark",male,64,1,4,19950,263,C23 C25 C27,S 441 | 440,0,2,"Kvillner, Mr. Johan Henrik Johannesson",male,31,0,0,C.A. 18723,10.5,,S 442 | 441,1,2,"Hart, Mrs. Benjamin (Esther Ada Bloomfield)",female,45,1,1,F.C.C. 13529,26.25,,S 443 | 442,0,3,"Hampe, Mr. Leon",male,20,0,0,345769,9.5,,S 444 | 443,0,3,"Petterson, Mr. Johan Emil",male,25,1,0,347076,7.775,,S 445 | 444,1,2,"Reynaldo, Ms. Encarnacion",female,28,0,0,230434,13,,S 446 | 445,1,3,"Johannesen-Bratthammer, Mr. Bernt",male,,0,0,65306,8.1125,,S 447 | 446,1,1,"Dodge, Master. Washington",male,4,0,2,33638,81.8583,A34,S 448 | 447,1,2,"Mellinger, Miss. Madeleine Violet",female,13,0,1,250644,19.5,,S 449 | 448,1,1,"Seward, Mr. Frederic Kimber",male,34,0,0,113794,26.55,,S 450 | 449,1,3,"Baclini, Miss. Marie Catherine",female,5,2,1,2666,19.2583,,C 451 | 450,1,1,"Peuchen, Major. Arthur Godfrey",male,52,0,0,113786,30.5,C104,S 452 | 451,0,2,"West, Mr. Edwy Arthur",male,36,1,2,C.A. 34651,27.75,,S 453 | 452,0,3,"Hagland, Mr. Ingvald Olai Olsen",male,,1,0,65303,19.9667,,S 454 | 453,0,1,"Foreman, Mr. Benjamin Laventall",male,30,0,0,113051,27.75,C111,C 455 | 454,1,1,"Goldenberg, Mr. Samuel L",male,49,1,0,17453,89.1042,C92,C 456 | 455,0,3,"Peduzzi, Mr. Joseph",male,,0,0,A/5 2817,8.05,,S 457 | 456,1,3,"Jalsevac, Mr. Ivan",male,29,0,0,349240,7.8958,,C 458 | 457,0,1,"Millet, Mr. Francis Davis",male,65,0,0,13509,26.55,E38,S 459 | 458,1,1,"Kenyon, Mrs. Frederick R (Marion)",female,,1,0,17464,51.8625,D21,S 460 | 459,1,2,"Toomey, Miss. Ellen",female,50,0,0,F.C.C. 13531,10.5,,S 461 | 460,0,3,"O'Connor, Mr. Maurice",male,,0,0,371060,7.75,,Q 462 | 461,1,1,"Anderson, Mr. Harry",male,48,0,0,19952,26.55,E12,S 463 | 462,0,3,"Morley, Mr. William",male,34,0,0,364506,8.05,,S 464 | 463,0,1,"Gee, Mr. Arthur H",male,47,0,0,111320,38.5,E63,S 465 | 464,0,2,"Milling, Mr. Jacob Christian",male,48,0,0,234360,13,,S 466 | 465,0,3,"Maisner, Mr. Simon",male,,0,0,A/S 2816,8.05,,S 467 | 466,0,3,"Goncalves, Mr. Manuel Estanslas",male,38,0,0,SOTON/O.Q. 3101306,7.05,,S 468 | 467,0,2,"Campbell, Mr. William",male,,0,0,239853,0,,S 469 | 468,0,1,"Smart, Mr. John Montgomery",male,56,0,0,113792,26.55,,S 470 | 469,0,3,"Scanlan, Mr. James",male,,0,0,36209,7.725,,Q 471 | 470,1,3,"Baclini, Miss. Helene Barbara",female,0.75,2,1,2666,19.2583,,C 472 | 471,0,3,"Keefe, Mr. Arthur",male,,0,0,323592,7.25,,S 473 | 472,0,3,"Cacic, Mr. Luka",male,38,0,0,315089,8.6625,,S 474 | 473,1,2,"West, Mrs. Edwy Arthur (Ada Mary Worth)",female,33,1,2,C.A. 34651,27.75,,S 475 | 474,1,2,"Jerwan, Mrs. Amin S (Marie Marthe Thuillard)",female,23,0,0,SC/AH Basle 541,13.7917,D,C 476 | 475,0,3,"Strandberg, Miss. Ida Sofia",female,22,0,0,7553,9.8375,,S 477 | 476,0,1,"Clifford, Mr. George Quincy",male,,0,0,110465,52,A14,S 478 | 477,0,2,"Renouf, Mr. Peter Henry",male,34,1,0,31027,21,,S 479 | 478,0,3,"Braund, Mr. Lewis Richard",male,29,1,0,3460,7.0458,,S 480 | 479,0,3,"Karlsson, Mr. Nils August",male,22,0,0,350060,7.5208,,S 481 | 480,1,3,"Hirvonen, Miss. Hildur E",female,2,0,1,3101298,12.2875,,S 482 | 481,0,3,"Goodwin, Master. Harold Victor",male,9,5,2,CA 2144,46.9,,S 483 | 482,0,2,"Frost, Mr. Anthony Wood ""Archie""",male,,0,0,239854,0,,S 484 | 483,0,3,"Rouse, Mr. Richard Henry",male,50,0,0,A/5 3594,8.05,,S 485 | 484,1,3,"Turkula, Mrs. (Hedwig)",female,63,0,0,4134,9.5875,,S 486 | 485,1,1,"Bishop, Mr. Dickinson H",male,25,1,0,11967,91.0792,B49,C 487 | 486,0,3,"Lefebre, Miss. Jeannie",female,,3,1,4133,25.4667,,S 488 | 487,1,1,"Hoyt, Mrs. Frederick Maxfield (Jane Anne Forby)",female,35,1,0,19943,90,C93,S 489 | 488,0,1,"Kent, Mr. Edward Austin",male,58,0,0,11771,29.7,B37,C 490 | 489,0,3,"Somerton, Mr. Francis William",male,30,0,0,A.5. 18509,8.05,,S 491 | 490,1,3,"Coutts, Master. Eden Leslie ""Neville""",male,9,1,1,C.A. 37671,15.9,,S 492 | 491,0,3,"Hagland, Mr. Konrad Mathias Reiersen",male,,1,0,65304,19.9667,,S 493 | 492,0,3,"Windelov, Mr. Einar",male,21,0,0,SOTON/OQ 3101317,7.25,,S 494 | 493,0,1,"Molson, Mr. Harry Markland",male,55,0,0,113787,30.5,C30,S 495 | 494,0,1,"Artagaveytia, Mr. Ramon",male,71,0,0,PC 17609,49.5042,,C 496 | 495,0,3,"Stanley, Mr. Edward Roland",male,21,0,0,A/4 45380,8.05,,S 497 | 496,0,3,"Yousseff, Mr. Gerious",male,,0,0,2627,14.4583,,C 498 | 497,1,1,"Eustis, Miss. Elizabeth Mussey",female,54,1,0,36947,78.2667,D20,C 499 | 498,0,3,"Shellard, Mr. Frederick William",male,,0,0,C.A. 6212,15.1,,S 500 | 499,0,1,"Allison, Mrs. Hudson J C (Bessie Waldo Daniels)",female,25,1,2,113781,151.55,C22 C26,S 501 | 500,0,3,"Svensson, Mr. Olof",male,24,0,0,350035,7.7958,,S 502 | 501,0,3,"Calic, Mr. Petar",male,17,0,0,315086,8.6625,,S 503 | 502,0,3,"Canavan, Miss. Mary",female,21,0,0,364846,7.75,,Q 504 | 503,0,3,"O'Sullivan, Miss. Bridget Mary",female,,0,0,330909,7.6292,,Q 505 | 504,0,3,"Laitinen, Miss. Kristina Sofia",female,37,0,0,4135,9.5875,,S 506 | 505,1,1,"Maioni, Miss. Roberta",female,16,0,0,110152,86.5,B79,S 507 | 506,0,1,"Penasco y Castellana, Mr. Victor de Satode",male,18,1,0,PC 17758,108.9,C65,C 508 | 507,1,2,"Quick, Mrs. Frederick Charles (Jane Richards)",female,33,0,2,26360,26,,S 509 | 508,1,1,"Bradley, Mr. George (""George Arthur Brayton"")",male,,0,0,111427,26.55,,S 510 | 509,0,3,"Olsen, Mr. Henry Margido",male,28,0,0,C 4001,22.525,,S 511 | 510,1,3,"Lang, Mr. Fang",male,26,0,0,1601,56.4958,,S 512 | 511,1,3,"Daly, Mr. Eugene Patrick",male,29,0,0,382651,7.75,,Q 513 | 512,0,3,"Webber, Mr. James",male,,0,0,SOTON/OQ 3101316,8.05,,S 514 | 513,1,1,"McGough, Mr. James Robert",male,36,0,0,PC 17473,26.2875,E25,S 515 | 514,1,1,"Rothschild, Mrs. Martin (Elizabeth L. Barrett)",female,54,1,0,PC 17603,59.4,,C 516 | 515,0,3,"Coleff, Mr. Satio",male,24,0,0,349209,7.4958,,S 517 | 516,0,1,"Walker, Mr. William Anderson",male,47,0,0,36967,34.0208,D46,S 518 | 517,1,2,"Lemore, Mrs. (Amelia Milley)",female,34,0,0,C.A. 34260,10.5,F33,S 519 | 518,0,3,"Ryan, Mr. Patrick",male,,0,0,371110,24.15,,Q 520 | 519,1,2,"Angle, Mrs. William A (Florence ""Mary"" Agnes Hughes)",female,36,1,0,226875,26,,S 521 | 520,0,3,"Pavlovic, Mr. Stefo",male,32,0,0,349242,7.8958,,S 522 | 521,1,1,"Perreault, Miss. Anne",female,30,0,0,12749,93.5,B73,S 523 | 522,0,3,"Vovk, Mr. Janko",male,22,0,0,349252,7.8958,,S 524 | 523,0,3,"Lahoud, Mr. Sarkis",male,,0,0,2624,7.225,,C 525 | 524,1,1,"Hippach, Mrs. Louis Albert (Ida Sophia Fischer)",female,44,0,1,111361,57.9792,B18,C 526 | 525,0,3,"Kassem, Mr. Fared",male,,0,0,2700,7.2292,,C 527 | 526,0,3,"Farrell, Mr. James",male,40.5,0,0,367232,7.75,,Q 528 | 527,1,2,"Ridsdale, Miss. Lucy",female,50,0,0,W./C. 14258,10.5,,S 529 | 528,0,1,"Farthing, Mr. John",male,,0,0,PC 17483,221.7792,C95,S 530 | 529,0,3,"Salonen, Mr. Johan Werner",male,39,0,0,3101296,7.925,,S 531 | 530,0,2,"Hocking, Mr. Richard George",male,23,2,1,29104,11.5,,S 532 | 531,1,2,"Quick, Miss. Phyllis May",female,2,1,1,26360,26,,S 533 | 532,0,3,"Toufik, Mr. Nakli",male,,0,0,2641,7.2292,,C 534 | 533,0,3,"Elias, Mr. Joseph Jr",male,17,1,1,2690,7.2292,,C 535 | 534,1,3,"Peter, Mrs. Catherine (Catherine Rizk)",female,,0,2,2668,22.3583,,C 536 | 535,0,3,"Cacic, Miss. Marija",female,30,0,0,315084,8.6625,,S 537 | 536,1,2,"Hart, Miss. Eva Miriam",female,7,0,2,F.C.C. 13529,26.25,,S 538 | 537,0,1,"Butt, Major. Archibald Willingham",male,45,0,0,113050,26.55,B38,S 539 | 538,1,1,"LeRoy, Miss. Bertha",female,30,0,0,PC 17761,106.425,,C 540 | 539,0,3,"Risien, Mr. Samuel Beard",male,,0,0,364498,14.5,,S 541 | 540,1,1,"Frolicher, Miss. Hedwig Margaritha",female,22,0,2,13568,49.5,B39,C 542 | 541,1,1,"Crosby, Miss. Harriet R",female,36,0,2,WE/P 5735,71,B22,S 543 | 542,0,3,"Andersson, Miss. Ingeborg Constanzia",female,9,4,2,347082,31.275,,S 544 | 543,0,3,"Andersson, Miss. Sigrid Elisabeth",female,11,4,2,347082,31.275,,S 545 | 544,1,2,"Beane, Mr. Edward",male,32,1,0,2908,26,,S 546 | 545,0,1,"Douglas, Mr. Walter Donald",male,50,1,0,PC 17761,106.425,C86,C 547 | 546,0,1,"Nicholson, Mr. Arthur Ernest",male,64,0,0,693,26,,S 548 | 547,1,2,"Beane, Mrs. Edward (Ethel Clarke)",female,19,1,0,2908,26,,S 549 | 548,1,2,"Padro y Manent, Mr. Julian",male,,0,0,SC/PARIS 2146,13.8625,,C 550 | 549,0,3,"Goldsmith, Mr. Frank John",male,33,1,1,363291,20.525,,S 551 | 550,1,2,"Davies, Master. John Morgan Jr",male,8,1,1,C.A. 33112,36.75,,S 552 | 551,1,1,"Thayer, Mr. John Borland Jr",male,17,0,2,17421,110.8833,C70,C 553 | 552,0,2,"Sharp, Mr. Percival James R",male,27,0,0,244358,26,,S 554 | 553,0,3,"O'Brien, Mr. Timothy",male,,0,0,330979,7.8292,,Q 555 | 554,1,3,"Leeni, Mr. Fahim (""Philip Zenni"")",male,22,0,0,2620,7.225,,C 556 | 555,1,3,"Ohman, Miss. Velin",female,22,0,0,347085,7.775,,S 557 | 556,0,1,"Wright, Mr. George",male,62,0,0,113807,26.55,,S 558 | 557,1,1,"Duff Gordon, Lady. (Lucille Christiana Sutherland) (""Mrs Morgan"")",female,48,1,0,11755,39.6,A16,C 559 | 558,0,1,"Robbins, Mr. Victor",male,,0,0,PC 17757,227.525,,C 560 | 559,1,1,"Taussig, Mrs. Emil (Tillie Mandelbaum)",female,39,1,1,110413,79.65,E67,S 561 | 560,1,3,"de Messemaeker, Mrs. Guillaume Joseph (Emma)",female,36,1,0,345572,17.4,,S 562 | 561,0,3,"Morrow, Mr. Thomas Rowan",male,,0,0,372622,7.75,,Q 563 | 562,0,3,"Sivic, Mr. Husein",male,40,0,0,349251,7.8958,,S 564 | 563,0,2,"Norman, Mr. Robert Douglas",male,28,0,0,218629,13.5,,S 565 | 564,0,3,"Simmons, Mr. John",male,,0,0,SOTON/OQ 392082,8.05,,S 566 | 565,0,3,"Meanwell, Miss. (Marion Ogden)",female,,0,0,SOTON/O.Q. 392087,8.05,,S 567 | 566,0,3,"Davies, Mr. Alfred J",male,24,2,0,A/4 48871,24.15,,S 568 | 567,0,3,"Stoytcheff, Mr. Ilia",male,19,0,0,349205,7.8958,,S 569 | 568,0,3,"Palsson, Mrs. Nils (Alma Cornelia Berglund)",female,29,0,4,349909,21.075,,S 570 | 569,0,3,"Doharr, Mr. Tannous",male,,0,0,2686,7.2292,,C 571 | 570,1,3,"Jonsson, Mr. Carl",male,32,0,0,350417,7.8542,,S 572 | 571,1,2,"Harris, Mr. George",male,62,0,0,S.W./PP 752,10.5,,S 573 | 572,1,1,"Appleton, Mrs. Edward Dale (Charlotte Lamson)",female,53,2,0,11769,51.4792,C101,S 574 | 573,1,1,"Flynn, Mr. John Irwin (""Irving"")",male,36,0,0,PC 17474,26.3875,E25,S 575 | 574,1,3,"Kelly, Miss. Mary",female,,0,0,14312,7.75,,Q 576 | 575,0,3,"Rush, Mr. Alfred George John",male,16,0,0,A/4. 20589,8.05,,S 577 | 576,0,3,"Patchett, Mr. George",male,19,0,0,358585,14.5,,S 578 | 577,1,2,"Garside, Miss. Ethel",female,34,0,0,243880,13,,S 579 | 578,1,1,"Silvey, Mrs. William Baird (Alice Munger)",female,39,1,0,13507,55.9,E44,S 580 | 579,0,3,"Caram, Mrs. Joseph (Maria Elias)",female,,1,0,2689,14.4583,,C 581 | 580,1,3,"Jussila, Mr. Eiriik",male,32,0,0,STON/O 2. 3101286,7.925,,S 582 | 581,1,2,"Christy, Miss. Julie Rachel",female,25,1,1,237789,30,,S 583 | 582,1,1,"Thayer, Mrs. John Borland (Marian Longstreth Morris)",female,39,1,1,17421,110.8833,C68,C 584 | 583,0,2,"Downton, Mr. William James",male,54,0,0,28403,26,,S 585 | 584,0,1,"Ross, Mr. John Hugo",male,36,0,0,13049,40.125,A10,C 586 | 585,0,3,"Paulner, Mr. Uscher",male,,0,0,3411,8.7125,,C 587 | 586,1,1,"Taussig, Miss. Ruth",female,18,0,2,110413,79.65,E68,S 588 | 587,0,2,"Jarvis, Mr. John Denzil",male,47,0,0,237565,15,,S 589 | 588,1,1,"Frolicher-Stehli, Mr. Maxmillian",male,60,1,1,13567,79.2,B41,C 590 | 589,0,3,"Gilinski, Mr. Eliezer",male,22,0,0,14973,8.05,,S 591 | 590,0,3,"Murdlin, Mr. Joseph",male,,0,0,A./5. 3235,8.05,,S 592 | 591,0,3,"Rintamaki, Mr. Matti",male,35,0,0,STON/O 2. 3101273,7.125,,S 593 | 592,1,1,"Stephenson, Mrs. Walter Bertram (Martha Eustis)",female,52,1,0,36947,78.2667,D20,C 594 | 593,0,3,"Elsbury, Mr. William James",male,47,0,0,A/5 3902,7.25,,S 595 | 594,0,3,"Bourke, Miss. Mary",female,,0,2,364848,7.75,,Q 596 | 595,0,2,"Chapman, Mr. John Henry",male,37,1,0,SC/AH 29037,26,,S 597 | 596,0,3,"Van Impe, Mr. Jean Baptiste",male,36,1,1,345773,24.15,,S 598 | 597,1,2,"Leitch, Miss. Jessie Wills",female,,0,0,248727,33,,S 599 | 598,0,3,"Johnson, Mr. Alfred",male,49,0,0,LINE,0,,S 600 | 599,0,3,"Boulos, Mr. Hanna",male,,0,0,2664,7.225,,C 601 | 600,1,1,"Duff Gordon, Sir. Cosmo Edmund (""Mr Morgan"")",male,49,1,0,PC 17485,56.9292,A20,C 602 | 601,1,2,"Jacobsohn, Mrs. Sidney Samuel (Amy Frances Christy)",female,24,2,1,243847,27,,S 603 | 602,0,3,"Slabenoff, Mr. Petco",male,,0,0,349214,7.8958,,S 604 | 603,0,1,"Harrington, Mr. Charles H",male,,0,0,113796,42.4,,S 605 | 604,0,3,"Torber, Mr. Ernst William",male,44,0,0,364511,8.05,,S 606 | 605,1,1,"Homer, Mr. Harry (""Mr E Haven"")",male,35,0,0,111426,26.55,,C 607 | 606,0,3,"Lindell, Mr. Edvard Bengtsson",male,36,1,0,349910,15.55,,S 608 | 607,0,3,"Karaic, Mr. Milan",male,30,0,0,349246,7.8958,,S 609 | 608,1,1,"Daniel, Mr. Robert Williams",male,27,0,0,113804,30.5,,S 610 | 609,1,2,"Laroche, Mrs. Joseph (Juliette Marie Louise Lafargue)",female,22,1,2,SC/Paris 2123,41.5792,,C 611 | 610,1,1,"Shutes, Miss. Elizabeth W",female,40,0,0,PC 17582,153.4625,C125,S 612 | 611,0,3,"Andersson, Mrs. Anders Johan (Alfrida Konstantia Brogren)",female,39,1,5,347082,31.275,,S 613 | 612,0,3,"Jardin, Mr. Jose Neto",male,,0,0,SOTON/O.Q. 3101305,7.05,,S 614 | 613,1,3,"Murphy, Miss. Margaret Jane",female,,1,0,367230,15.5,,Q 615 | 614,0,3,"Horgan, Mr. John",male,,0,0,370377,7.75,,Q 616 | 615,0,3,"Brocklebank, Mr. William Alfred",male,35,0,0,364512,8.05,,S 617 | 616,1,2,"Herman, Miss. Alice",female,24,1,2,220845,65,,S 618 | 617,0,3,"Danbom, Mr. Ernst Gilbert",male,34,1,1,347080,14.4,,S 619 | 618,0,3,"Lobb, Mrs. William Arthur (Cordelia K Stanlick)",female,26,1,0,A/5. 3336,16.1,,S 620 | 619,1,2,"Becker, Miss. Marion Louise",female,4,2,1,230136,39,F4,S 621 | 620,0,2,"Gavey, Mr. Lawrence",male,26,0,0,31028,10.5,,S 622 | 621,0,3,"Yasbeck, Mr. Antoni",male,27,1,0,2659,14.4542,,C 623 | 622,1,1,"Kimball, Mr. Edwin Nelson Jr",male,42,1,0,11753,52.5542,D19,S 624 | 623,1,3,"Nakid, Mr. Sahid",male,20,1,1,2653,15.7417,,C 625 | 624,0,3,"Hansen, Mr. Henry Damsgaard",male,21,0,0,350029,7.8542,,S 626 | 625,0,3,"Bowen, Mr. David John ""Dai""",male,21,0,0,54636,16.1,,S 627 | 626,0,1,"Sutton, Mr. Frederick",male,61,0,0,36963,32.3208,D50,S 628 | 627,0,2,"Kirkland, Rev. Charles Leonard",male,57,0,0,219533,12.35,,Q 629 | 628,1,1,"Longley, Miss. Gretchen Fiske",female,21,0,0,13502,77.9583,D9,S 630 | 629,0,3,"Bostandyeff, Mr. Guentcho",male,26,0,0,349224,7.8958,,S 631 | 630,0,3,"O'Connell, Mr. Patrick D",male,,0,0,334912,7.7333,,Q 632 | 631,1,1,"Barkworth, Mr. Algernon Henry Wilson",male,80,0,0,27042,30,A23,S 633 | 632,0,3,"Lundahl, Mr. Johan Svensson",male,51,0,0,347743,7.0542,,S 634 | 633,1,1,"Stahelin-Maeglin, Dr. Max",male,32,0,0,13214,30.5,B50,C 635 | 634,0,1,"Parr, Mr. William Henry Marsh",male,,0,0,112052,0,,S 636 | 635,0,3,"Skoog, Miss. Mabel",female,9,3,2,347088,27.9,,S 637 | 636,1,2,"Davis, Miss. Mary",female,28,0,0,237668,13,,S 638 | 637,0,3,"Leinonen, Mr. Antti Gustaf",male,32,0,0,STON/O 2. 3101292,7.925,,S 639 | 638,0,2,"Collyer, Mr. Harvey",male,31,1,1,C.A. 31921,26.25,,S 640 | 639,0,3,"Panula, Mrs. Juha (Maria Emilia Ojala)",female,41,0,5,3101295,39.6875,,S 641 | 640,0,3,"Thorneycroft, Mr. Percival",male,,1,0,376564,16.1,,S 642 | 641,0,3,"Jensen, Mr. Hans Peder",male,20,0,0,350050,7.8542,,S 643 | 642,1,1,"Sagesser, Mlle. Emma",female,24,0,0,PC 17477,69.3,B35,C 644 | 643,0,3,"Skoog, Miss. Margit Elizabeth",female,2,3,2,347088,27.9,,S 645 | 644,1,3,"Foo, Mr. Choong",male,,0,0,1601,56.4958,,S 646 | 645,1,3,"Baclini, Miss. Eugenie",female,0.75,2,1,2666,19.2583,,C 647 | 646,1,1,"Harper, Mr. Henry Sleeper",male,48,1,0,PC 17572,76.7292,D33,C 648 | 647,0,3,"Cor, Mr. Liudevit",male,19,0,0,349231,7.8958,,S 649 | 648,1,1,"Simonius-Blumer, Col. Oberst Alfons",male,56,0,0,13213,35.5,A26,C 650 | 649,0,3,"Willey, Mr. Edward",male,,0,0,S.O./P.P. 751,7.55,,S 651 | 650,1,3,"Stanley, Miss. Amy Zillah Elsie",female,23,0,0,CA. 2314,7.55,,S 652 | 651,0,3,"Mitkoff, Mr. Mito",male,,0,0,349221,7.8958,,S 653 | 652,1,2,"Doling, Miss. Elsie",female,18,0,1,231919,23,,S 654 | 653,0,3,"Kalvik, Mr. Johannes Halvorsen",male,21,0,0,8475,8.4333,,S 655 | 654,1,3,"O'Leary, Miss. Hanora ""Norah""",female,,0,0,330919,7.8292,,Q 656 | 655,0,3,"Hegarty, Miss. Hanora ""Nora""",female,18,0,0,365226,6.75,,Q 657 | 656,0,2,"Hickman, Mr. Leonard Mark",male,24,2,0,S.O.C. 14879,73.5,,S 658 | 657,0,3,"Radeff, Mr. Alexander",male,,0,0,349223,7.8958,,S 659 | 658,0,3,"Bourke, Mrs. John (Catherine)",female,32,1,1,364849,15.5,,Q 660 | 659,0,2,"Eitemiller, Mr. George Floyd",male,23,0,0,29751,13,,S 661 | 660,0,1,"Newell, Mr. Arthur Webster",male,58,0,2,35273,113.275,D48,C 662 | 661,1,1,"Frauenthal, Dr. Henry William",male,50,2,0,PC 17611,133.65,,S 663 | 662,0,3,"Badt, Mr. Mohamed",male,40,0,0,2623,7.225,,C 664 | 663,0,1,"Colley, Mr. Edward Pomeroy",male,47,0,0,5727,25.5875,E58,S 665 | 664,0,3,"Coleff, Mr. Peju",male,36,0,0,349210,7.4958,,S 666 | 665,1,3,"Lindqvist, Mr. Eino William",male,20,1,0,STON/O 2. 3101285,7.925,,S 667 | 666,0,2,"Hickman, Mr. Lewis",male,32,2,0,S.O.C. 14879,73.5,,S 668 | 667,0,2,"Butler, Mr. Reginald Fenton",male,25,0,0,234686,13,,S 669 | 668,0,3,"Rommetvedt, Mr. Knud Paust",male,,0,0,312993,7.775,,S 670 | 669,0,3,"Cook, Mr. Jacob",male,43,0,0,A/5 3536,8.05,,S 671 | 670,1,1,"Taylor, Mrs. Elmer Zebley (Juliet Cummins Wright)",female,,1,0,19996,52,C126,S 672 | 671,1,2,"Brown, Mrs. Thomas William Solomon (Elizabeth Catherine Ford)",female,40,1,1,29750,39,,S 673 | 672,0,1,"Davidson, Mr. Thornton",male,31,1,0,F.C. 12750,52,B71,S 674 | 673,0,2,"Mitchell, Mr. Henry Michael",male,70,0,0,C.A. 24580,10.5,,S 675 | 674,1,2,"Wilhelms, Mr. Charles",male,31,0,0,244270,13,,S 676 | 675,0,2,"Watson, Mr. Ennis Hastings",male,,0,0,239856,0,,S 677 | 676,0,3,"Edvardsson, Mr. Gustaf Hjalmar",male,18,0,0,349912,7.775,,S 678 | 677,0,3,"Sawyer, Mr. Frederick Charles",male,24.5,0,0,342826,8.05,,S 679 | 678,1,3,"Turja, Miss. Anna Sofia",female,18,0,0,4138,9.8417,,S 680 | 679,0,3,"Goodwin, Mrs. Frederick (Augusta Tyler)",female,43,1,6,CA 2144,46.9,,S 681 | 680,1,1,"Cardeza, Mr. Thomas Drake Martinez",male,36,0,1,PC 17755,512.3292,B51 B53 B55,C 682 | 681,0,3,"Peters, Miss. Katie",female,,0,0,330935,8.1375,,Q 683 | 682,1,1,"Hassab, Mr. Hammad",male,27,0,0,PC 17572,76.7292,D49,C 684 | 683,0,3,"Olsvigen, Mr. Thor Anderson",male,20,0,0,6563,9.225,,S 685 | 684,0,3,"Goodwin, Mr. Charles Edward",male,14,5,2,CA 2144,46.9,,S 686 | 685,0,2,"Brown, Mr. Thomas William Solomon",male,60,1,1,29750,39,,S 687 | 686,0,2,"Laroche, Mr. Joseph Philippe Lemercier",male,25,1,2,SC/Paris 2123,41.5792,,C 688 | 687,0,3,"Panula, Mr. Jaako Arnold",male,14,4,1,3101295,39.6875,,S 689 | 688,0,3,"Dakic, Mr. Branko",male,19,0,0,349228,10.1708,,S 690 | 689,0,3,"Fischer, Mr. Eberhard Thelander",male,18,0,0,350036,7.7958,,S 691 | 690,1,1,"Madill, Miss. Georgette Alexandra",female,15,0,1,24160,211.3375,B5,S 692 | 691,1,1,"Dick, Mr. Albert Adrian",male,31,1,0,17474,57,B20,S 693 | 692,1,3,"Karun, Miss. Manca",female,4,0,1,349256,13.4167,,C 694 | 693,1,3,"Lam, Mr. Ali",male,,0,0,1601,56.4958,,S 695 | 694,0,3,"Saad, Mr. Khalil",male,25,0,0,2672,7.225,,C 696 | 695,0,1,"Weir, Col. John",male,60,0,0,113800,26.55,,S 697 | 696,0,2,"Chapman, Mr. Charles Henry",male,52,0,0,248731,13.5,,S 698 | 697,0,3,"Kelly, Mr. James",male,44,0,0,363592,8.05,,S 699 | 698,1,3,"Mullens, Miss. Katherine ""Katie""",female,,0,0,35852,7.7333,,Q 700 | 699,0,1,"Thayer, Mr. John Borland",male,49,1,1,17421,110.8833,C68,C 701 | 700,0,3,"Humblen, Mr. Adolf Mathias Nicolai Olsen",male,42,0,0,348121,7.65,F G63,S 702 | 701,1,1,"Astor, Mrs. John Jacob (Madeleine Talmadge Force)",female,18,1,0,PC 17757,227.525,C62 C64,C 703 | 702,1,1,"Silverthorne, Mr. Spencer Victor",male,35,0,0,PC 17475,26.2875,E24,S 704 | 703,0,3,"Barbara, Miss. Saiide",female,18,0,1,2691,14.4542,,C 705 | 704,0,3,"Gallagher, Mr. Martin",male,25,0,0,36864,7.7417,,Q 706 | 705,0,3,"Hansen, Mr. Henrik Juul",male,26,1,0,350025,7.8542,,S 707 | 706,0,2,"Morley, Mr. Henry Samuel (""Mr Henry Marshall"")",male,39,0,0,250655,26,,S 708 | 707,1,2,"Kelly, Mrs. Florence ""Fannie""",female,45,0,0,223596,13.5,,S 709 | 708,1,1,"Calderhead, Mr. Edward Pennington",male,42,0,0,PC 17476,26.2875,E24,S 710 | 709,1,1,"Cleaver, Miss. Alice",female,22,0,0,113781,151.55,,S 711 | 710,1,3,"Moubarek, Master. Halim Gonios (""William George"")",male,,1,1,2661,15.2458,,C 712 | 711,1,1,"Mayne, Mlle. Berthe Antonine (""Mrs de Villiers"")",female,24,0,0,PC 17482,49.5042,C90,C 713 | 712,0,1,"Klaber, Mr. Herman",male,,0,0,113028,26.55,C124,S 714 | 713,1,1,"Taylor, Mr. Elmer Zebley",male,48,1,0,19996,52,C126,S 715 | 714,0,3,"Larsson, Mr. August Viktor",male,29,0,0,7545,9.4833,,S 716 | 715,0,2,"Greenberg, Mr. Samuel",male,52,0,0,250647,13,,S 717 | 716,0,3,"Soholt, Mr. Peter Andreas Lauritz Andersen",male,19,0,0,348124,7.65,F G73,S 718 | 717,1,1,"Endres, Miss. Caroline Louise",female,38,0,0,PC 17757,227.525,C45,C 719 | 718,1,2,"Troutt, Miss. Edwina Celia ""Winnie""",female,27,0,0,34218,10.5,E101,S 720 | 719,0,3,"McEvoy, Mr. Michael",male,,0,0,36568,15.5,,Q 721 | 720,0,3,"Johnson, Mr. Malkolm Joackim",male,33,0,0,347062,7.775,,S 722 | 721,1,2,"Harper, Miss. Annie Jessie ""Nina""",female,6,0,1,248727,33,,S 723 | 722,0,3,"Jensen, Mr. Svend Lauritz",male,17,1,0,350048,7.0542,,S 724 | 723,0,2,"Gillespie, Mr. William Henry",male,34,0,0,12233,13,,S 725 | 724,0,2,"Hodges, Mr. Henry Price",male,50,0,0,250643,13,,S 726 | 725,1,1,"Chambers, Mr. Norman Campbell",male,27,1,0,113806,53.1,E8,S 727 | 726,0,3,"Oreskovic, Mr. Luka",male,20,0,0,315094,8.6625,,S 728 | 727,1,2,"Renouf, Mrs. Peter Henry (Lillian Jefferys)",female,30,3,0,31027,21,,S 729 | 728,1,3,"Mannion, Miss. Margareth",female,,0,0,36866,7.7375,,Q 730 | 729,0,2,"Bryhl, Mr. Kurt Arnold Gottfrid",male,25,1,0,236853,26,,S 731 | 730,0,3,"Ilmakangas, Miss. Pieta Sofia",female,25,1,0,STON/O2. 3101271,7.925,,S 732 | 731,1,1,"Allen, Miss. Elisabeth Walton",female,29,0,0,24160,211.3375,B5,S 733 | 732,0,3,"Hassan, Mr. Houssein G N",male,11,0,0,2699,18.7875,,C 734 | 733,0,2,"Knight, Mr. Robert J",male,,0,0,239855,0,,S 735 | 734,0,2,"Berriman, Mr. William John",male,23,0,0,28425,13,,S 736 | 735,0,2,"Troupiansky, Mr. Moses Aaron",male,23,0,0,233639,13,,S 737 | 736,0,3,"Williams, Mr. Leslie",male,28.5,0,0,54636,16.1,,S 738 | 737,0,3,"Ford, Mrs. Edward (Margaret Ann Watson)",female,48,1,3,W./C. 6608,34.375,,S 739 | 738,1,1,"Lesurer, Mr. Gustave J",male,35,0,0,PC 17755,512.3292,B101,C 740 | 739,0,3,"Ivanoff, Mr. Kanio",male,,0,0,349201,7.8958,,S 741 | 740,0,3,"Nankoff, Mr. Minko",male,,0,0,349218,7.8958,,S 742 | 741,1,1,"Hawksford, Mr. Walter James",male,,0,0,16988,30,D45,S 743 | 742,0,1,"Cavendish, Mr. Tyrell William",male,36,1,0,19877,78.85,C46,S 744 | 743,1,1,"Ryerson, Miss. Susan Parker ""Suzette""",female,21,2,2,PC 17608,262.375,B57 B59 B63 B66,C 745 | 744,0,3,"McNamee, Mr. Neal",male,24,1,0,376566,16.1,,S 746 | 745,1,3,"Stranden, Mr. Juho",male,31,0,0,STON/O 2. 3101288,7.925,,S 747 | 746,0,1,"Crosby, Capt. Edward Gifford",male,70,1,1,WE/P 5735,71,B22,S 748 | 747,0,3,"Abbott, Mr. Rossmore Edward",male,16,1,1,C.A. 2673,20.25,,S 749 | 748,1,2,"Sinkkonen, Miss. Anna",female,30,0,0,250648,13,,S 750 | 749,0,1,"Marvin, Mr. Daniel Warner",male,19,1,0,113773,53.1,D30,S 751 | 750,0,3,"Connaghton, Mr. Michael",male,31,0,0,335097,7.75,,Q 752 | 751,1,2,"Wells, Miss. Joan",female,4,1,1,29103,23,,S 753 | 752,1,3,"Moor, Master. Meier",male,6,0,1,392096,12.475,E121,S 754 | 753,0,3,"Vande Velde, Mr. Johannes Joseph",male,33,0,0,345780,9.5,,S 755 | 754,0,3,"Jonkoff, Mr. Lalio",male,23,0,0,349204,7.8958,,S 756 | 755,1,2,"Herman, Mrs. Samuel (Jane Laver)",female,48,1,2,220845,65,,S 757 | 756,1,2,"Hamalainen, Master. Viljo",male,0.67,1,1,250649,14.5,,S 758 | 757,0,3,"Carlsson, Mr. August Sigfrid",male,28,0,0,350042,7.7958,,S 759 | 758,0,2,"Bailey, Mr. Percy Andrew",male,18,0,0,29108,11.5,,S 760 | 759,0,3,"Theobald, Mr. Thomas Leonard",male,34,0,0,363294,8.05,,S 761 | 760,1,1,"Rothes, the Countess. of (Lucy Noel Martha Dyer-Edwards)",female,33,0,0,110152,86.5,B77,S 762 | 761,0,3,"Garfirth, Mr. John",male,,0,0,358585,14.5,,S 763 | 762,0,3,"Nirva, Mr. Iisakki Antino Aijo",male,41,0,0,SOTON/O2 3101272,7.125,,S 764 | 763,1,3,"Barah, Mr. Hanna Assi",male,20,0,0,2663,7.2292,,C 765 | 764,1,1,"Carter, Mrs. William Ernest (Lucile Polk)",female,36,1,2,113760,120,B96 B98,S 766 | 765,0,3,"Eklund, Mr. Hans Linus",male,16,0,0,347074,7.775,,S 767 | 766,1,1,"Hogeboom, Mrs. John C (Anna Andrews)",female,51,1,0,13502,77.9583,D11,S 768 | 767,0,1,"Brewe, Dr. Arthur Jackson",male,,0,0,112379,39.6,,C 769 | 768,0,3,"Mangan, Miss. Mary",female,30.5,0,0,364850,7.75,,Q 770 | 769,0,3,"Moran, Mr. Daniel J",male,,1,0,371110,24.15,,Q 771 | 770,0,3,"Gronnestad, Mr. Daniel Danielsen",male,32,0,0,8471,8.3625,,S 772 | 771,0,3,"Lievens, Mr. Rene Aime",male,24,0,0,345781,9.5,,S 773 | 772,0,3,"Jensen, Mr. Niels Peder",male,48,0,0,350047,7.8542,,S 774 | 773,0,2,"Mack, Mrs. (Mary)",female,57,0,0,S.O./P.P. 3,10.5,E77,S 775 | 774,0,3,"Elias, Mr. Dibo",male,,0,0,2674,7.225,,C 776 | 775,1,2,"Hocking, Mrs. Elizabeth (Eliza Needs)",female,54,1,3,29105,23,,S 777 | 776,0,3,"Myhrman, Mr. Pehr Fabian Oliver Malkolm",male,18,0,0,347078,7.75,,S 778 | 777,0,3,"Tobin, Mr. Roger",male,,0,0,383121,7.75,F38,Q 779 | 778,1,3,"Emanuel, Miss. Virginia Ethel",female,5,0,0,364516,12.475,,S 780 | 779,0,3,"Kilgannon, Mr. Thomas J",male,,0,0,36865,7.7375,,Q 781 | 780,1,1,"Robert, Mrs. Edward Scott (Elisabeth Walton McMillan)",female,43,0,1,24160,211.3375,B3,S 782 | 781,1,3,"Ayoub, Miss. Banoura",female,13,0,0,2687,7.2292,,C 783 | 782,1,1,"Dick, Mrs. Albert Adrian (Vera Gillespie)",female,17,1,0,17474,57,B20,S 784 | 783,0,1,"Long, Mr. Milton Clyde",male,29,0,0,113501,30,D6,S 785 | 784,0,3,"Johnston, Mr. Andrew G",male,,1,2,W./C. 6607,23.45,,S 786 | 785,0,3,"Ali, Mr. William",male,25,0,0,SOTON/O.Q. 3101312,7.05,,S 787 | 786,0,3,"Harmer, Mr. Abraham (David Lishin)",male,25,0,0,374887,7.25,,S 788 | 787,1,3,"Sjoblom, Miss. Anna Sofia",female,18,0,0,3101265,7.4958,,S 789 | 788,0,3,"Rice, Master. George Hugh",male,8,4,1,382652,29.125,,Q 790 | 789,1,3,"Dean, Master. Bertram Vere",male,1,1,2,C.A. 2315,20.575,,S 791 | 790,0,1,"Guggenheim, Mr. Benjamin",male,46,0,0,PC 17593,79.2,B82 B84,C 792 | 791,0,3,"Keane, Mr. Andrew ""Andy""",male,,0,0,12460,7.75,,Q 793 | 792,0,2,"Gaskell, Mr. Alfred",male,16,0,0,239865,26,,S 794 | 793,0,3,"Sage, Miss. Stella Anna",female,,8,2,CA. 2343,69.55,,S 795 | 794,0,1,"Hoyt, Mr. William Fisher",male,,0,0,PC 17600,30.6958,,C 796 | 795,0,3,"Dantcheff, Mr. Ristiu",male,25,0,0,349203,7.8958,,S 797 | 796,0,2,"Otter, Mr. Richard",male,39,0,0,28213,13,,S 798 | 797,1,1,"Leader, Dr. Alice (Farnham)",female,49,0,0,17465,25.9292,D17,S 799 | 798,1,3,"Osman, Mrs. Mara",female,31,0,0,349244,8.6833,,S 800 | 799,0,3,"Ibrahim Shawah, Mr. Yousseff",male,30,0,0,2685,7.2292,,C 801 | 800,0,3,"Van Impe, Mrs. Jean Baptiste (Rosalie Paula Govaert)",female,30,1,1,345773,24.15,,S 802 | 801,0,2,"Ponesell, Mr. Martin",male,34,0,0,250647,13,,S 803 | 802,1,2,"Collyer, Mrs. Harvey (Charlotte Annie Tate)",female,31,1,1,C.A. 31921,26.25,,S 804 | 803,1,1,"Carter, Master. William Thornton II",male,11,1,2,113760,120,B96 B98,S 805 | 804,1,3,"Thomas, Master. Assad Alexander",male,0.42,0,1,2625,8.5167,,C 806 | 805,1,3,"Hedman, Mr. Oskar Arvid",male,27,0,0,347089,6.975,,S 807 | 806,0,3,"Johansson, Mr. Karl Johan",male,31,0,0,347063,7.775,,S 808 | 807,0,1,"Andrews, Mr. Thomas Jr",male,39,0,0,112050,0,A36,S 809 | 808,0,3,"Pettersson, Miss. Ellen Natalia",female,18,0,0,347087,7.775,,S 810 | 809,0,2,"Meyer, Mr. August",male,39,0,0,248723,13,,S 811 | 810,1,1,"Chambers, Mrs. Norman Campbell (Bertha Griggs)",female,33,1,0,113806,53.1,E8,S 812 | 811,0,3,"Alexander, Mr. William",male,26,0,0,3474,7.8875,,S 813 | 812,0,3,"Lester, Mr. James",male,39,0,0,A/4 48871,24.15,,S 814 | 813,0,2,"Slemen, Mr. Richard James",male,35,0,0,28206,10.5,,S 815 | 814,0,3,"Andersson, Miss. Ebba Iris Alfrida",female,6,4,2,347082,31.275,,S 816 | 815,0,3,"Tomlin, Mr. Ernest Portage",male,30.5,0,0,364499,8.05,,S 817 | 816,0,1,"Fry, Mr. Richard",male,,0,0,112058,0,B102,S 818 | 817,0,3,"Heininen, Miss. Wendla Maria",female,23,0,0,STON/O2. 3101290,7.925,,S 819 | 818,0,2,"Mallet, Mr. Albert",male,31,1,1,S.C./PARIS 2079,37.0042,,C 820 | 819,0,3,"Holm, Mr. John Fredrik Alexander",male,43,0,0,C 7075,6.45,,S 821 | 820,0,3,"Skoog, Master. Karl Thorsten",male,10,3,2,347088,27.9,,S 822 | 821,1,1,"Hays, Mrs. Charles Melville (Clara Jennings Gregg)",female,52,1,1,12749,93.5,B69,S 823 | 822,1,3,"Lulic, Mr. Nikola",male,27,0,0,315098,8.6625,,S 824 | 823,0,1,"Reuchlin, Jonkheer. John George",male,38,0,0,19972,0,,S 825 | 824,1,3,"Moor, Mrs. (Beila)",female,27,0,1,392096,12.475,E121,S 826 | 825,0,3,"Panula, Master. Urho Abraham",male,2,4,1,3101295,39.6875,,S 827 | 826,0,3,"Flynn, Mr. John",male,,0,0,368323,6.95,,Q 828 | 827,0,3,"Lam, Mr. Len",male,,0,0,1601,56.4958,,S 829 | 828,1,2,"Mallet, Master. Andre",male,1,0,2,S.C./PARIS 2079,37.0042,,C 830 | 829,1,3,"McCormack, Mr. Thomas Joseph",male,,0,0,367228,7.75,,Q 831 | 830,1,1,"Stone, Mrs. George Nelson (Martha Evelyn)",female,62,0,0,113572,80,B28, 832 | 831,1,3,"Yasbeck, Mrs. Antoni (Selini Alexander)",female,15,1,0,2659,14.4542,,C 833 | 832,1,2,"Richards, Master. George Sibley",male,0.83,1,1,29106,18.75,,S 834 | 833,0,3,"Saad, Mr. Amin",male,,0,0,2671,7.2292,,C 835 | 834,0,3,"Augustsson, Mr. Albert",male,23,0,0,347468,7.8542,,S 836 | 835,0,3,"Allum, Mr. Owen George",male,18,0,0,2223,8.3,,S 837 | 836,1,1,"Compton, Miss. Sara Rebecca",female,39,1,1,PC 17756,83.1583,E49,C 838 | 837,0,3,"Pasic, Mr. Jakob",male,21,0,0,315097,8.6625,,S 839 | 838,0,3,"Sirota, Mr. Maurice",male,,0,0,392092,8.05,,S 840 | 839,1,3,"Chip, Mr. Chang",male,32,0,0,1601,56.4958,,S 841 | 840,1,1,"Marechal, Mr. Pierre",male,,0,0,11774,29.7,C47,C 842 | 841,0,3,"Alhomaki, Mr. Ilmari Rudolf",male,20,0,0,SOTON/O2 3101287,7.925,,S 843 | 842,0,2,"Mudd, Mr. Thomas Charles",male,16,0,0,S.O./P.P. 3,10.5,,S 844 | 843,1,1,"Serepeca, Miss. Augusta",female,30,0,0,113798,31,,C 845 | 844,0,3,"Lemberopolous, Mr. Peter L",male,34.5,0,0,2683,6.4375,,C 846 | 845,0,3,"Culumovic, Mr. Jeso",male,17,0,0,315090,8.6625,,S 847 | 846,0,3,"Abbing, Mr. Anthony",male,42,0,0,C.A. 5547,7.55,,S 848 | 847,0,3,"Sage, Mr. Douglas Bullen",male,,8,2,CA. 2343,69.55,,S 849 | 848,0,3,"Markoff, Mr. Marin",male,35,0,0,349213,7.8958,,C 850 | 849,0,2,"Harper, Rev. John",male,28,0,1,248727,33,,S 851 | 850,1,1,"Goldenberg, Mrs. Samuel L (Edwiga Grabowska)",female,,1,0,17453,89.1042,C92,C 852 | 851,0,3,"Andersson, Master. Sigvard Harald Elias",male,4,4,2,347082,31.275,,S 853 | 852,0,3,"Svensson, Mr. Johan",male,74,0,0,347060,7.775,,S 854 | 853,0,3,"Boulos, Miss. Nourelain",female,9,1,1,2678,15.2458,,C 855 | 854,1,1,"Lines, Miss. Mary Conover",female,16,0,1,PC 17592,39.4,D28,S 856 | 855,0,2,"Carter, Mrs. Ernest Courtenay (Lilian Hughes)",female,44,1,0,244252,26,,S 857 | 856,1,3,"Aks, Mrs. Sam (Leah Rosen)",female,18,0,1,392091,9.35,,S 858 | 857,1,1,"Wick, Mrs. George Dennick (Mary Hitchcock)",female,45,1,1,36928,164.8667,,S 859 | 858,1,1,"Daly, Mr. Peter Denis ",male,51,0,0,113055,26.55,E17,S 860 | 859,1,3,"Baclini, Mrs. Solomon (Latifa Qurban)",female,24,0,3,2666,19.2583,,C 861 | 860,0,3,"Razi, Mr. Raihed",male,,0,0,2629,7.2292,,C 862 | 861,0,3,"Hansen, Mr. Claus Peter",male,41,2,0,350026,14.1083,,S 863 | 862,0,2,"Giles, Mr. Frederick Edward",male,21,1,0,28134,11.5,,S 864 | 863,1,1,"Swift, Mrs. Frederick Joel (Margaret Welles Barron)",female,48,0,0,17466,25.9292,D17,S 865 | 864,0,3,"Sage, Miss. Dorothy Edith ""Dolly""",female,,8,2,CA. 2343,69.55,,S 866 | 865,0,2,"Gill, Mr. John William",male,24,0,0,233866,13,,S 867 | 866,1,2,"Bystrom, Mrs. (Karolina)",female,42,0,0,236852,13,,S 868 | 867,1,2,"Duran y More, Miss. Asuncion",female,27,1,0,SC/PARIS 2149,13.8583,,C 869 | 868,0,1,"Roebling, Mr. Washington Augustus II",male,31,0,0,PC 17590,50.4958,A24,S 870 | 869,0,3,"van Melkebeke, Mr. Philemon",male,,0,0,345777,9.5,,S 871 | 870,1,3,"Johnson, Master. Harold Theodor",male,4,1,1,347742,11.1333,,S 872 | 871,0,3,"Balkic, Mr. Cerin",male,26,0,0,349248,7.8958,,S 873 | 872,1,1,"Beckwith, Mrs. Richard Leonard (Sallie Monypeny)",female,47,1,1,11751,52.5542,D35,S 874 | 873,0,1,"Carlsson, Mr. Frans Olof",male,33,0,0,695,5,B51 B53 B55,S 875 | 874,0,3,"Vander Cruyssen, Mr. Victor",male,47,0,0,345765,9,,S 876 | 875,1,2,"Abelson, Mrs. Samuel (Hannah Wizosky)",female,28,1,0,P/PP 3381,24,,C 877 | 876,1,3,"Najib, Miss. Adele Kiamie ""Jane""",female,15,0,0,2667,7.225,,C 878 | 877,0,3,"Gustafsson, Mr. Alfred Ossian",male,20,0,0,7534,9.8458,,S 879 | 878,0,3,"Petroff, Mr. Nedelio",male,19,0,0,349212,7.8958,,S 880 | 879,0,3,"Laleff, Mr. Kristo",male,,0,0,349217,7.8958,,S 881 | 880,1,1,"Potter, Mrs. Thomas Jr (Lily Alexenia Wilson)",female,56,0,1,11767,83.1583,C50,C 882 | 881,1,2,"Shelley, Mrs. William (Imanita Parrish Hall)",female,25,0,1,230433,26,,S 883 | 882,0,3,"Markun, Mr. Johann",male,33,0,0,349257,7.8958,,S 884 | 883,0,3,"Dahlberg, Miss. Gerda Ulrika",female,22,0,0,7552,10.5167,,S 885 | 884,0,2,"Banfield, Mr. Frederick James",male,28,0,0,C.A./SOTON 34068,10.5,,S 886 | 885,0,3,"Sutehall, Mr. Henry Jr",male,25,0,0,SOTON/OQ 392076,7.05,,S 887 | 886,0,3,"Rice, Mrs. William (Margaret Norton)",female,39,0,5,382652,29.125,,Q 888 | 887,0,2,"Montvila, Rev. Juozas",male,27,0,0,211536,13,,S 889 | 888,1,1,"Graham, Miss. Margaret Edith",female,19,0,0,112053,30,B42,S 890 | 889,0,3,"Johnston, Miss. Catherine Helen ""Carrie""",female,,1,2,W./C. 6607,23.45,,S 891 | 890,1,1,"Behr, Mr. Karl Howell",male,26,0,0,111369,30,C148,C 892 | 891,0,3,"Dooley, Mr. Patrick",male,32,0,0,370376,7.75,,Q 893 | -------------------------------------------------------------------------------- /data/trump.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fbagattini/An-introduction-to-Data-Science-with-Python/722fe35c1c5752bc24efa7d023e659b0ed815677/data/trump.jpg -------------------------------------------------------------------------------- /images/tree2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fbagattini/An-introduction-to-Data-Science-with-Python/722fe35c1c5752bc24efa7d023e659b0ed815677/images/tree2.pdf -------------------------------------------------------------------------------- /images/treemax.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fbagattini/An-introduction-to-Data-Science-with-Python/722fe35c1c5752bc24efa7d023e659b0ed815677/images/treemax.pdf --------------------------------------------------------------------------------