├── LICENSE.cc-by-sa.md ├── README-es.md ├── README.md ├── python_1 ├── unit_1 │ ├── .gitignore │ ├── CAT-prog_datasci_1.ipynb │ ├── IB-prog_datasci_1.ipynb │ ├── README.md │ ├── pdf │ │ ├── CAT-prog_datasci_1.pdf │ │ └── IB-prog_datasci_1.pdf │ └── test_user.py ├── unit_2 │ ├── .gitignore │ ├── CAT-prog_datasci_2_python.ipynb │ ├── IB-prog_datasci_2_python.ipynb │ ├── README.md │ └── pdf │ │ ├── CAT-prog_datasci_2_python.pdf │ │ └── IB-prog_datasci_2_python.pdf ├── unit_3 │ ├── .gitignore │ ├── CAT-prog_datasci_3_apython.ipynb │ ├── IB-prog_datasci_3_apython.ipynb │ ├── README.md │ ├── pdf │ │ ├── CAT-prog_datasci_3_apython.pdf │ │ └── IB-prog_datasci_3_apython.pdf │ └── prog_datasci.py ├── unit_4 │ ├── .gitignore │ ├── CAT-prog_datasci_4_matplotlib.ipynb │ ├── CAT-prog_datasci_4_numpy.ipynb │ ├── CAT-prog_datasci_4_pandas.ipynb │ ├── CAT-prog_datasci_4_scipy.ipynb │ ├── IB-prog_datasci_4_matplotlib.ipynb │ ├── IB-prog_datasci_4_numpy.ipynb │ ├── IB-prog_datasci_4_pandas.ipynb │ ├── IB-prog_datasci_4_scipy.ipynb │ ├── README.md │ ├── data │ │ ├── README.md │ │ ├── got.csv │ │ ├── historical_projections.csv │ │ ├── marvel-wikia-data.csv │ │ └── us_births.csv │ ├── media │ │ ├── Cryoem_groel.png │ │ └── sagan.png │ └── pdf │ │ ├── CAT-prog_datasci_4_matplotlib.pdf │ │ ├── CAT-prog_datasci_4_numpy.pdf │ │ ├── CAT-prog_datasci_4_pandas.pdf │ │ ├── CAT-prog_datasci_4_scipy.pdf │ │ ├── IB-prog_datasci_4_matplotlib.pdf │ │ ├── IB-prog_datasci_4_numpy.pdf │ │ ├── IB-prog_datasci_4_pandas.pdf │ │ └── IB-prog_datasci_4_scipy.pdf ├── unit_5 │ ├── .gitignore │ ├── CAT-prog_datasci_5_api.ipynb │ ├── IB-prog_datasci_5_api.ipynb │ ├── README.md │ └── pdf │ │ ├── CAT-prog_datasci_5_api.pdf │ │ └── IB-prog_datasci_5_api.pdf ├── unit_6 │ ├── .gitignore │ ├── CAT-prog_datasci_6_preproc.ipynb │ ├── IB-prog_datasci_6_preproc.ipynb │ ├── README.md │ ├── data │ │ ├── Baseball.csv │ │ ├── README.md │ │ ├── Salarios.csv │ │ ├── bank_edited.csv │ │ └── weather_dataset_edited.csv │ └── pdf │ │ ├── CAT-prog_datasci_6_preproc.pdf │ │ └── IB-prog_datasci_6_preproc.pdf ├── unit_7 │ ├── .gitignore │ ├── CAT-prog_datasci_7_analisis.ipynb │ ├── IB-prog_datasci_7_analisis.ipynb │ ├── README.md │ └── pdf │ │ ├── CAT-prog_datasci_7_analisis.pdf │ │ └── IB-prog_datasci_7_analisis.pdf └── unit_8 │ ├── .gitignore │ ├── CAT-prog_datasci_8_vis.ipynb │ ├── IB-prog_datasci_8_vis.ipynb │ ├── README.md │ ├── data │ ├── README.md │ ├── bus.csv │ ├── elecciones.csv │ ├── flights.csv │ ├── gz_2010_us_050_00_20m.json │ ├── pulitzer-circulation-data.csv │ └── unemployment.json │ └── pdf │ ├── CAT-prog_datasci_8_vis.pdf │ └── IB-prog_datasci_8_vis.pdf ├── python_2 ├── unit_0 │ ├── .gitignore │ ├── 0-CAT-Refermant_conceptes.ipynb │ ├── 0-ES-Afianzando_conceptos.ipynb │ ├── README.md │ └── pdf │ │ ├── 0-CAT-Refermant_conceptes.pdf │ │ └── 0-ES-Afianzando_conceptos.pdf ├── unit_1 │ ├── .gitignore │ ├── 1-CAT-Estructures_dades_avançades.ipynb │ ├── 1-ES-Estructuras_de_datos_avanzadas.ipynb │ ├── README.md │ ├── data │ │ └── flight714.csv │ └── pdf │ │ ├── 1-CAT-Estructures_dades_avançades.pdf │ │ └── 1-ES-Estructuras_de_datos_avanzadas.pdf ├── unit_2 │ ├── .gitignore │ ├── 2-CAT-Ús avançat de funcions.ipynb │ ├── 2-ES-Uso_avanzado_de_funciones.ipynb │ ├── README.md │ └── pdf │ │ ├── 2-CAT-Ús avançat de funcions.pdf │ │ └── 2-IB-Uso_avanzado_de_funciones.pdf ├── unit_3 │ ├── .gitignore │ ├── 3-CAT-Fitxers_i_interacció_amb_el_sistema.ipynb │ ├── 3-ES-Ficheros_e_interacción_con_el_sistema.ipynb │ ├── README.md │ ├── data │ │ └── marvel-wikia-data.csv │ ├── files_folder.zip │ ├── files_folder │ │ ├── a_folder_in_a_zip │ │ │ └── file_3.txt │ │ ├── a_number.txt │ │ ├── echo_read_script.sh │ │ ├── echo_script.sh │ │ ├── endless_script.sh │ │ ├── file_1.txt │ │ ├── file_2.txt │ │ ├── original_file.txt │ │ ├── somehow_big_file.txt │ │ └── zip_with_multiple_files.zip │ └── pdf │ │ ├── 3-CAT-Fitxers_i_interacció_amb_el_sistema.pdf │ │ └── 3-ES-Ficheros_e_interacción_con_el_sistema.pdf ├── unit_4 │ ├── .gitignore │ ├── 4-CAT-Optimització_complexitat_i_profiling.ipynb │ ├── 4-ES-Optimización_complejidad_y_profiling.ipynb │ ├── README.md │ └── pdf │ │ ├── 4-CAT-Optimització_complexitat_i_profiling.pdf │ │ └── 4-ES-Optimización_complejidad_y_profiling.pdf ├── unit_5 │ ├── .gitignore │ ├── 5-CAT-Optimització_paral·lelisme_i_concurrencia.ipynb │ ├── 5-ES-Optimización_paralelismo_y_concurrencia.ipynb │ ├── README.md │ ├── data │ │ └── COVID-19.csv │ ├── img │ │ ├── concurrencia_cat.png │ │ └── concurrencia_ib.png │ └── pdf │ │ ├── 5-CAT-Optimització_paral·lelisme_i_concurrencia.pdf │ │ └── 5-ES-Optimización_paralelismo_y_concurrencia.pdf └── unit_6 │ ├── 6-CAT-Testing_manteniment_desplegament.ipynb │ ├── 6-IB-Testing_matenimiento_y_despliegue.ipynb │ ├── README.md │ ├── data │ └── COVID-19.csv │ ├── img │ ├── 1.png │ ├── 10.png │ ├── 11.png │ ├── 2.png │ ├── 3.png │ ├── 4.png │ ├── 5.png │ ├── 6.png │ ├── 7.png │ ├── 8.png │ ├── 9.png │ ├── arquitectura_cat.png │ ├── arquitectura_ib.png │ ├── py_cat.png │ └── py_ib.png │ ├── pdf │ ├── 6-CAT-Testing_manteniment_desplegament.pdf │ └── 6-IB-Testing_matenimiento_y_despliegue.pdf │ ├── pycharm │ └── covid │ │ ├── basic_analysis.py │ │ ├── data │ │ └── COVID-19.csv │ │ ├── requirements.txt │ │ ├── tests │ │ └── test.py │ │ └── utils.py │ └── python_code │ └── hello_world.py └── requirements.txt /LICENSE.cc-by-sa.md: -------------------------------------------------------------------------------- 1 | ## creative commons 2 | 3 | # Attribution-ShareAlike 4.0 International 4 | 5 | Creative Commons Corporation (“Creative Commons”) is not a law firm and does not provide legal services or legal advice. Distribution of Creative Commons public licenses does not create a lawyer-client or other relationship. Creative Commons makes its licenses and related information available on an “as-is” basis. Creative Commons gives no warranties regarding its licenses, any material licensed under their terms and conditions, or any related information. Creative Commons disclaims all liability for damages resulting from their use to the fullest extent possible. 6 | 7 | ### Using Creative Commons Public Licenses 8 | 9 | Creative Commons public licenses provide a standard set of terms and conditions that creators and other rights holders may use to share original works of authorship and other material subject to copyright and certain other rights specified in the public license below. The following considerations are for informational purposes only, are not exhaustive, and do not form part of our licenses. 10 | 11 | * __Considerations for licensors:__ Our public licenses are intended for use by those authorized to give the public permission to use material in ways otherwise restricted by copyright and certain other rights. Our licenses are irrevocable. Licensors should read and understand the terms and conditions of the license they choose before applying it. Licensors should also secure all rights necessary before applying our licenses so that the public can reuse the material as expected. Licensors should clearly mark any material not subject to the license. This includes other CC-licensed material, or material used under an exception or limitation to copyright. [More considerations for licensors](http://wiki.creativecommons.org/Considerations_for_licensors_and_licensees#Considerations_for_licensors). 12 | 13 | * __Considerations for the public:__ By using one of our public licenses, a licensor grants the public permission to use the licensed material under specified terms and conditions. If the licensor’s permission is not necessary for any reason–for example, because of any applicable exception or limitation to copyright–then that use is not regulated by the license. Our licenses grant only permissions under copyright and certain other rights that a licensor has authority to grant. Use of the licensed material may still be restricted for other reasons, including because others have copyright or other rights in the material. A licensor may make special requests, such as asking that all changes be marked or described. Although not required by our licenses, you are encouraged to respect those requests where reasonable. [More considerations for the public](http://wiki.creativecommons.org/Considerations_for_licensors_and_licensees#Considerations_for_licensees). 14 | 15 | ## Creative Commons Attribution-ShareAlike 4.0 International Public License 16 | 17 | By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-ShareAlike 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions. 18 | 19 | ### Section 1 – Definitions. 20 | 21 | a. __Adapted Material__ means material subject to Copyright and Similar Rights that is derived from or based upon the Licensed Material and in which the Licensed Material is translated, altered, arranged, transformed, or otherwise modified in a manner requiring permission under the Copyright and Similar Rights held by the Licensor. For purposes of this Public License, where the Licensed Material is a musical work, performance, or sound recording, Adapted Material is always produced where the Licensed Material is synched in timed relation with a moving image. 22 | 23 | b. __Adapter's License__ means the license You apply to Your Copyright and Similar Rights in Your contributions to Adapted Material in accordance with the terms and conditions of this Public License. 24 | 25 | c. __BY-SA Compatible License__ means a license listed at [creativecommons.org/compatiblelicenses](http://creativecommons.org/compatiblelicenses), approved by Creative Commons as essentially the equivalent of this Public License. 26 | 27 | d. __Copyright and Similar Rights__ means copyright and/or similar rights closely related to copyright including, without limitation, performance, broadcast, sound recording, and Sui Generis Database Rights, without regard to how the rights are labeled or categorized. For purposes of this Public License, the rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. 28 | 29 | e. __Effective Technological Measures__ means those measures that, in the absence of proper authority, may not be circumvented under laws fulfilling obligations under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, and/or similar international agreements. 30 | 31 | f. __Exceptions and Limitations__ means fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material. 32 | 33 | g. __License Elements__ means the license attributes listed in the name of a Creative Commons Public License. The License Elements of this Public License are Attribution and ShareAlike. 34 | 35 | h. __Licensed Material__ means the artistic or literary work, database, or other material to which the Licensor applied this Public License. 36 | 37 | i. __Licensed Rights__ means the rights granted to You subject to the terms and conditions of this Public License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license. 38 | 39 | j. __Licensor__ means the individual(s) or entity(ies) granting rights under this Public License. 40 | 41 | k. __Share__ means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them. 42 | 43 | l. __Sui Generis Database Rights__ means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world. 44 | 45 | m. __You__ means the individual or entity exercising the Licensed Rights under this Public License. Your has a corresponding meaning. 46 | 47 | ### Section 2 – Scope. 48 | 49 | a. ___License grant.___ 50 | 51 | 1. Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to: 52 | 53 | A. reproduce and Share the Licensed Material, in whole or in part; and 54 | 55 | B. produce, reproduce, and Share Adapted Material. 56 | 57 | 2. __Exceptions and Limitations.__ For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions. 58 | 59 | 3. __Term.__ The term of this Public License is specified in Section 6(a). 60 | 61 | 4. __Media and formats; technical modifications allowed.__ The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this Public License, simply making modifications authorized by this Section 2(a)(4) never produces Adapted Material. 62 | 63 | 5. __Downstream recipients.__ 64 | 65 | A. __Offer from the Licensor – Licensed Material.__ Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License. 66 | 67 | B. __Additional offer from the Licensor – Adapted Material. Every recipient of Adapted Material from You automatically receives an offer from the Licensor to exercise the Licensed Rights in the Adapted Material under the conditions of the Adapter’s License You apply. 68 | 69 | C. __No downstream restrictions.__ You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material. 70 | 71 | 6. __No endorsement.__ Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(A)(i). 72 | 73 | b. ___Other rights.___ 74 | 75 | 1. Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise. 76 | 77 | 2. Patent and trademark rights are not licensed under this Public License. 78 | 79 | 3. To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties. 80 | 81 | ### Section 3 – License Conditions. 82 | 83 | Your exercise of the Licensed Rights is expressly made subject to the following conditions. 84 | 85 | a. ___Attribution.___ 86 | 87 | 1. If You Share the Licensed Material (including in modified form), You must: 88 | 89 | A. retain the following if it is supplied by the Licensor with the Licensed Material: 90 | 91 | i. identification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor (including by pseudonym if designated); 92 | 93 | ii. a copyright notice; 94 | 95 | iii. a notice that refers to this Public License; 96 | 97 | iv. a notice that refers to the disclaimer of warranties; 98 | 99 | v. a URI or hyperlink to the Licensed Material to the extent reasonably practicable; 100 | 101 | B. indicate if You modified the Licensed Material and retain an indication of any previous modifications; and 102 | 103 | C. indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License. 104 | 105 | 2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information. 106 | 107 | 3. If requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable. 108 | 109 | b. ___ShareAlike.___ 110 | 111 | In addition to the conditions in Section 3(a), if You Share Adapted Material You produce, the following conditions also apply. 112 | 113 | 1. The Adapter’s License You apply must be a Creative Commons license with the same License Elements, this version or later, or a BY-SA Compatible License. 114 | 115 | 2. You must include the text of, or the URI or hyperlink to, the Adapter's License You apply. You may satisfy this condition in any reasonable manner based on the medium, means, and context in which You Share Adapted Material. 116 | 117 | 3. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, Adapted Material that restrict exercise of the rights granted under the Adapter's License You apply. 118 | 119 | ### Section 4 – Sui Generis Database Rights. 120 | 121 | Where the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material: 122 | 123 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database; 124 | 125 | b. if You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Adapted Material, including for purposes of Section 3(b); and 126 | 127 | c. You must comply with the conditions in Section 3(a) if You Share all or a substantial portion of the contents of the database. 128 | 129 | For the avoidance of doubt, this Section 4 supplements and does not replace Your obligations under this Public License where the Licensed Rights include other Copyright and Similar Rights. 130 | 131 | ### Section 5 – Disclaimer of Warranties and Limitation of Liability. 132 | 133 | a. __Unless otherwise separately undertaken by the Licensor, to the extent possible, the Licensor offers the Licensed Material as-is and as-available, and makes no representations or warranties of any kind concerning the Licensed Material, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You.__ 134 | 135 | b. __To the extent possible, in no event will the Licensor be liable to You on any legal theory (including, without limitation, negligence) or otherwise for any direct, special, indirect, incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages arising out of this Public License or use of the Licensed Material, even if the Licensor has been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation of liability is not allowed in full or in part, this limitation may not apply to You.__ 136 | 137 | c. The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability. 138 | 139 | ### Section 6 – Term and Termination. 140 | 141 | a. This Public License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this Public License, then Your rights under this Public License terminate automatically. 142 | 143 | b. Where Your right to use the Licensed Material has terminated under Section 6(a), it reinstates: 144 | 145 | 1. automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or 146 | 147 | 2. upon express reinstatement by the Licensor. 148 | 149 | For the avoidance of doubt, this Section 6(b) does not affect any right the Licensor may have to seek remedies for Your violations of this Public License. 150 | 151 | c. For the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time; however, doing so will not terminate this Public License. 152 | 153 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public License. 154 | 155 | ### Section 7 – Other Terms and Conditions. 156 | 157 | a. The Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed. 158 | 159 | b. Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License.t stated herein are separate from and independent of the terms and conditions of this Public License. 160 | 161 | ### Section 8 – Interpretation. 162 | 163 | a. For the avoidance of doubt, this Public License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Licensed Material that could lawfully be made without permission under this Public License. 164 | 165 | b. To the extent possible, if any provision of this Public License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this Public License without affecting the enforceability of the remaining terms and conditions. 166 | 167 | c. No term or condition of this Public License will be waived and no failure to comply consented to unless expressly agreed to by the Licensor. 168 | 169 | d. Nothing in this Public License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority. 170 | 171 | ``` 172 | Creative Commons is not a party to its public licenses. Notwithstanding, Creative Commons may elect to apply one of its public licenses to material it publishes and in those instances will be considered the “Licensor.” Except for the limited purpose of indicating that material is shared under a Creative Commons public license or as otherwise permitted by the Creative Commons policies published at [creativecommons.org/policies](http://creativecommons.org/policies), Creative Commons does not authorize the use of the trademark “Creative Commons” or any other trademark or logo of Creative Commons without its prior written consent including, without limitation, in connection with any unauthorized modifications to any of its public licenses or any other arrangements, understandings, or agreements concerning use of licensed material. For the avoidance of doubt, this paragraph does not form part of the public licenses. 173 | 174 | Creative Commons may be contacted at creativecommons.org 175 | ``` 176 | -------------------------------------------------------------------------------- /README-es.md: -------------------------------------------------------------------------------- 1 | # Programación Python para la ciencia de datos 2 | ---- 3 | Para acceder a la versión en catalán de este documento, haced clic [aquí](README.md). 4 | # 1. Introducción 5 | 6 | Este repositorio contiene un conjunto de *notebooks* de jupyter que forman parte de los cursos de programación Python para la ciencia de datos de la Universitat Oberta de Catalunya, y que se distribuyen bajo licencia [`CC-BY-SA`](https://creativecommons.org/licenses/by-sa/4.0/). 7 | 8 | El repositorio contiene los notebooks separados en dos carpetas: 9 | 1. La carpeta `python_1` contiene los *notebooks* de la asignatura **Fundamentos de programación**, que ofrece una introducción a la programación en lenguaje Python centrada en la resolución de problemas del ámbito de la ciencia de datos. 10 | 11 | 2. La carpeta `python_2` contiene los *notebooks* de la asignatura **Programación para la ciencia de datos**, profundizando en la comprensión de algunos de los conceptos clave, a la vez que se explican otros conceptos de programación más avanzados , que permitirán a los estudiantes afrontar problemas de programación más complejos y de manera más eficiente, en Python. 12 | 13 | El índice de contenidos del material de `python_1` es el siguiente: 14 | 15 | * Unidad 1: Instalación y configuración del entorno de programación Python 16 | * Unidad 2: Breve introducción a la programación en Python 17 | * Unidad 3: Estructuras de control y funciones en Python 18 | * Unidad 4: Librerías científicas en Python 19 | * Unidad 5: Captura de datos en Python 20 | * Unidad 6: Preprocesamiento de datos en Python 21 | * Unidad 7: Introducción al análisis de datos en Python 22 | * Unidad 8: Visualización de datos en Python 23 | 24 | El índice de contenidos del material de `python_2` es el siguiente: 25 | * Unidad 0: Afianzando conceptos 26 | * Unidad 1: Estructuras de datos avanzadas 27 | * Unidad 2: Uso avanzado de funciones 28 | * Unidad 3: Archivos e interacción con el sistema 29 | * Unidad 4: Optimización: complejidad y profiling 30 | * Unidad 5: Optimización: concurrencia y paralelismo 31 | * Unidad 6: Testing, mantenimiento y desarrollo de aplicaciones 32 | 33 | Cada unidad se encuentra dentro de una carpeta que tiene por nombre `unit_x`, donde `x` es el número de la unidad. Dentro de la carpeta de cada unidad, encontraréis tanto el *notebook* que podéis ejecutar, como una exportación a pdf del contenido del *notebook*. Si se utilizan conjuntos de datos para ejemplificar los conceptos explicados en las unidades, también encontraréis una carpeta `data` que contendrá todos los datos necesarios para ejecutar el *notebook*. 34 | 35 | # 2. Preparación del entorno 36 | 37 | Con el fin de ejecutar los *notebooks* necesitaréis: 38 | * Una instalación de `python3` con algunas librerías adicionales y 39 | * El software `jupyter`. 40 | 41 | La máquina virtual que se proporciona en cualquiera de las dos asignaturas ya incorpora todo el software necesario para ejecutar el contenido de este repositorio. Como alternativa, podéis instalar en la máquina el software siguiendo las indicaciones de los apartados siguientes. 42 | 43 | ## 2.1. Instalación de python3 44 | 45 | Descargad e instalad `python3` para vuestro sistema operativo. 46 | 47 | Si trabajáis con una distribución linux basada en debian, podéis ejecutar: 48 | 49 | ``` 50 | $ sudo apt-get install python3 51 | ``` 52 | 53 | ## 2.2. Instalación de dependencias 54 | 55 | Instalad las librerías adicionales necesarias, que se encuentran especificadas en `requirements.txt` ejecutando desde dentro de la carpeta del repositorio: 56 | 57 | ``` 58 | $ pip install -r requirements.txt 59 | ``` 60 | 61 | ## 2.3. Instalación de jupyter 62 | 63 | Instalad el software jupyter siguiendo las indicaciones de la [web oficial](https://jupyter.org/install) 64 | 65 | # 3. Ejecución de los notebooks 66 | 67 | Una vez que tengáis el software instalado, iniciad jupyter y abrid los *notebooks*: 68 | 69 | ``` 70 | $ jupyter notebook 71 | ``` 72 | 73 | Si utilizáis la máquina virtual de las asignaturas, también podéis iniciar jupyter ejecutando el *script* `start_uoc`: 74 | ``` 75 | $ start_uoc.sh 76 | ``` 77 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Programació Python per a la ciència de dades 2 | ---- 3 | Per a accedir a la versió en castellà d'aquest document, feu clic [aquí](README-es.md). 4 | # 1. Introducció 5 | 6 | Aquest repositori conté un conjunt de *notebooks* de jupyter que formen part dels cursos de programació Python per a la ciència de dades de la Universitat Oberta de Catalunya, i que es distribueixen sota llicència [`CC-BY-SA`](https://creativecommons.org/licenses/by-sa/4.0/). 7 | 8 | El repositori conté els notebooks separats en dues carpetes: 9 | 1. La carpeta `python_1` conté els *notebooks* de l'assignatura **Fonaments de programació**, que ofereix una introducció a la programació en llenguatge Python centrada en la resolució de problemes de l'àmbit de la ciència de dades. 10 | 11 | 2. La carpeta `python_2` conté els *notebooks* de l'assignatura **Programació per a la ciència de dades**, aprofundint en la comprensió d'alguns dels conceptes clau, alhora que s'expliquen altres conceptes de programació més avançats, que permetran als estudiants afrontar problemes de programació més complexos i de manera més eficient, en Python. 12 | 13 | L'índex de continguts del material de `python_1` és el següent: 14 | 15 | * Unitat 1: Instal·lació i configuració de l'entorn de programació Python 16 | * Unitat 2: Breu introducció a la programació en Python 17 | * Unitat 3: Estructures de control i funcions en Python 18 | * Unitat 4: Llibreries científiques en Python 19 | * Unitat 5: Captura de dades en Python 20 | * Unitat 6: Preprocessament de dades en Python 21 | * Unitat 7: Introducció a l'anàlisi de dades en Python 22 | * Unitat 8: Visualització de dades en Python 23 | 24 | L'índex de continguts del material de `python_2` és el següent: 25 | * Unitat 0: Refermant conceptes 26 | * Unitat 1: Estructures de dades avançades 27 | * Unitat 2: Ús avançat de funcions 28 | * Unitat 3: Fitxers i interacció amb el sistema 29 | * Unitat 4: Optimització: complexitat i profiling 30 | * Unitat 5: Optimització: concurrència i paral·lelisme 31 | * Unitat 6: Testing, manteniment i desplegament d'aplicacions 32 | 33 | Cada unitat es troba dins d'una carpeta que porta per nom `unit_x`, on `x` és el número de la unitat. Dins de la carpeta de cada unitat, hi trobareu tant el *notebook* que podeu executar, com una exportació a pdf del contingut del *notebook*. Si es fan servir conjunts de dades per a exemplificar els conceptes explicats a les unitats, també hi trobareu una carpeta `data` que contindrà totes les dades necessàries per a executar el *notebook*. 34 | 35 | # 2. Preparació de l'entorn 36 | 37 | Per tal d'executar els *notebooks* necessitareu: 38 | * una instal·lació de `python3` amb algunes llibreries addicionals i 39 | * el programari `jupyter`. 40 | 41 | La màquina virtual que es proporciona en qualsevol de les dues assignatures ja incorpora tot el programari necessari per a executar el contingut d'aquest repositori. Com a alternativa, podeu instal·lar a la vostra màquina el programari seguint les indicacions dels apartats següents. 42 | 43 | ## 2.1. Instal·lació de python3 44 | 45 | Descarregueu i instal·leu `python3` per al vostre sistema operatiu. 46 | 47 | Si treballeu en una distribució linux basada en debian, podeu fer: 48 | 49 | ``` 50 | $ sudo apt-get install python3 51 | ``` 52 | 53 | ## 2.2. Instal·lació de dependències 54 | 55 | Instal·leu les llibreries addicionals necessàries, que es troben especificades al fitxer `requirements.txt` executant des de dins de la carpeta del repositori: 56 | 57 | ``` 58 | $ pip install -r requirements.txt 59 | ``` 60 | 61 | ## 2.3. Instal·lació de jupyter 62 | 63 | Instal·leu el programari jupyter seguint les indicacions de la [web oficial](https://jupyter.org/install) 64 | 65 | # 3. Execució dels notebooks 66 | 67 | Una vegada tingueu el programari instal·lat, inicieu jupyter i obriu els *notebooks* amb les activitats: 68 | 69 | ``` 70 | $ jupyter notebook 71 | ``` 72 | 73 | Si utilitzeu la màquina virtual de les assignatures, també podeu iniciar jupyter executant l'*script* `start_uoc`: 74 | ``` 75 | $ start_uoc.sh 76 | ``` 77 | -------------------------------------------------------------------------------- /python_1/unit_1/.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # IPython Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # dotenv 79 | .env 80 | 81 | # virtualenv 82 | venv/ 83 | ENV/ 84 | 85 | # Spyder project settings 86 | .spyderproject 87 | 88 | # Rope project settings 89 | .ropeproject 90 | .DS_Store 91 | -------------------------------------------------------------------------------- /python_1/unit_1/CAT-prog_datasci_1.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "metadata": { 3 | "name": "", 4 | "signature": "sha256:c456630b60002f8f9b4ca835e9bcb71a237983510c785c514754d604a27812aa" 5 | }, 6 | "nbformat": 3, 7 | "nbformat_minor": 0, 8 | "worksheets": [ 9 | { 10 | "cells": [ 11 | { 12 | "cell_type": "heading", 13 | "level": 1, 14 | "metadata": {}, 15 | "source": [ 16 | "Programaci\u00f3 per a *Data Science*" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "metadata": {}, 22 | "source": [ 23 | "Unitat 1: Instal\u00b7laci\u00f3 i configuraci\u00f3 de l'entorn de programaci\u00f3 Python\n", 24 | "--------------------------------------------" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": {}, 30 | "source": [ 31 | "## Funciona!" 32 | ] 33 | } 34 | ], 35 | "metadata": {} 36 | } 37 | ] 38 | } -------------------------------------------------------------------------------- /python_1/unit_1/IB-prog_datasci_1.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "metadata": { 3 | "name": "", 4 | "signature": "sha256:2401cffc320e2ac3cd3c12baeea605c90637454bcadbee453563efc35def3905" 5 | }, 6 | "nbformat": 3, 7 | "nbformat_minor": 0, 8 | "worksheets": [ 9 | { 10 | "cells": [ 11 | { 12 | "cell_type": "heading", 13 | "level": 1, 14 | "metadata": {}, 15 | "source": [ 16 | "Programaci\u00f3n para *Data Science*" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "metadata": {}, 22 | "source": [ 23 | "Unidad 1: Instalaci\u00f3n y configuraci\u00f3n del entorno de programaci\u00f3n Python\n", 24 | "--------------------------------------------" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": {}, 30 | "source": [ 31 | "## \u00a1Funciona!" 32 | ] 33 | } 34 | ], 35 | "metadata": {} 36 | } 37 | ] 38 | } -------------------------------------------------------------------------------- /python_1/unit_1/README.md: -------------------------------------------------------------------------------- 1 | # Unit 1 - Setup 2 | 3 | This is the repository of the content for unit 1 (Instal·lació i configuració de l'entorn de programació Python / Instalación y configuración del entorno de programación Python) of the course: 4 | * 22.401 - Fonaments de Programació 5 | * 22.501 - Fundamentos de Programación 6 | 7 | 8 | -------------------------------------------------------------------------------- /python_1/unit_1/pdf/CAT-prog_datasci_1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_1/unit_1/pdf/CAT-prog_datasci_1.pdf -------------------------------------------------------------------------------- /python_1/unit_1/pdf/IB-prog_datasci_1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_1/unit_1/pdf/IB-prog_datasci_1.pdf -------------------------------------------------------------------------------- /python_1/unit_1/test_user.py: -------------------------------------------------------------------------------- 1 | import hashlib 2 | 3 | seed = 'Programacion Python para Data Science' 4 | 5 | if __name__ == "__main__": 6 | try: 7 | dni = raw_input('Introduce tu DNI o NIE (sin letra):') 8 | except ValueError: 9 | raise SystemExit('Error al introducir el DNI') 10 | 11 | digest = hashlib.sha224('.'.join(seed.split())+dni).hexdigest() 12 | with open('prog_datasci_1.txt', 'w') as output: 13 | output.write("%s %s\n" % (dni, digest)) 14 | print 'Archivo prog_datasci_1.txt generado' 15 | -------------------------------------------------------------------------------- /python_1/unit_2/.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # IPython Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # dotenv 79 | .env 80 | 81 | # virtualenv 82 | venv/ 83 | ENV/ 84 | 85 | # Spyder project settings 86 | .spyderproject 87 | 88 | # Rope project settings 89 | .ropeproject 90 | .DS_Store 91 | -------------------------------------------------------------------------------- /python_1/unit_2/README.md: -------------------------------------------------------------------------------- 1 | # Unit 2 - Introduction to Python 2 | 3 | This is the repository of the content for unit 2 (Breu introducció a la programació en Python / Breve introducción a la programación en Python) of the course: 4 | * 22.401 - Fonaments de Programació 5 | * 22.501 - Fundamentos de Programación 6 | 7 | 8 | -------------------------------------------------------------------------------- /python_1/unit_2/pdf/CAT-prog_datasci_2_python.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_1/unit_2/pdf/CAT-prog_datasci_2_python.pdf -------------------------------------------------------------------------------- /python_1/unit_2/pdf/IB-prog_datasci_2_python.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_1/unit_2/pdf/IB-prog_datasci_2_python.pdf -------------------------------------------------------------------------------- /python_1/unit_3/.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # IPython Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # dotenv 79 | .env 80 | 81 | # virtualenv 82 | venv/ 83 | ENV/ 84 | 85 | # Spyder project settings 86 | .spyderproject 87 | 88 | # Rope project settings 89 | .ropeproject 90 | .DS_Store 91 | -------------------------------------------------------------------------------- /python_1/unit_3/CAT-prog_datasci_3_apython.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "Programació per a *Data Science*\n", 8 | "============================\n", 9 | "\n", 10 | "Unitat 3: Conceptes avançats de Python\n", 11 | "--------------------------------------\n", 12 | "\n", 13 | "### Instruccions d'ús\n", 14 | "\n", 15 | "Al mòdul anterior hem introduït conceptes bàsics sobre variables i el seu ús\n", 16 | "en Python. En aquest mòdul estudiarem conceptes més avançats com les\n", 17 | "instruccions de flux d'execució (_for_, _while_, _if_), com definir i\n", 18 | "utilitzar funcions, com llegir i escriure fitxers i com organitzar el\n", 19 | "codi.\n", 20 | "\n", 21 | "Iteració i operacions lògiques\n", 22 | "------------------------------\n", 23 | "\n", 24 | "En la majoria de casos haurem de manipular les nostres dades, i\n", 25 | "per fer-ho utilitzarem els conceptes d'iteració i les operacions\n", 26 | "lògiques. Les operacions lògiques ens permeten comparar valors entre\n", 27 | "variables (més gran, més petit, igualtat), i la iteració, anar visitant un a un\n", 28 | "els elements d'una llista, tupla, diccionari o qualsevol estructura de\n", 29 | "dades que sigui susceptible de seqüenciar-se." 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": 1, 35 | "metadata": { 36 | "attributes": { 37 | "classes": [ 38 | "sourceCode" 39 | ], 40 | "id": "" 41 | } 42 | }, 43 | "outputs": [ 44 | { 45 | "name": "stdout", 46 | "output_type": "stream", 47 | "text": [ 48 | "True\n" 49 | ] 50 | } 51 | ], 52 | "source": [ 53 | "# Les operacions lògiques tindran com a resultat un valor cert (True) o fals (False):\n", 54 | "\n", 55 | "a = 5\n", 56 | "b = 1\n", 57 | "\n", 58 | "# El valor a és més gran que b?\n", 59 | "print(a > b)" 60 | ] 61 | }, 62 | { 63 | "cell_type": "code", 64 | "execution_count": 2, 65 | "metadata": { 66 | "attributes": { 67 | "classes": [ 68 | "sourceCode" 69 | ], 70 | "id": "" 71 | } 72 | }, 73 | "outputs": [ 74 | { 75 | "name": "stdout", 76 | "output_type": "stream", 77 | "text": [ 78 | "False\n" 79 | ] 80 | } 81 | ], 82 | "source": [ 83 | "# El valor a és més petit que b?\n", 84 | "print(a < b)" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": 3, 90 | "metadata": { 91 | "attributes": { 92 | "classes": [ 93 | "sourceCode" 94 | ], 95 | "id": "" 96 | } 97 | }, 98 | "outputs": [ 99 | { 100 | "name": "stdout", 101 | "output_type": "stream", 102 | "text": [ 103 | "True\n" 104 | ] 105 | } 106 | ], 107 | "source": [ 108 | "b = 5\n", 109 | "# El valor de b és igual que el d'a?\n", 110 | "print(b == a)" 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": 4, 116 | "metadata": { 117 | "attributes": { 118 | "classes": [ 119 | "sourceCode" 120 | ], 121 | "id": "" 122 | } 123 | }, 124 | "outputs": [ 125 | { 126 | "name": "stdout", 127 | "output_type": "stream", 128 | "text": [ 129 | "True\n", 130 | "True\n", 131 | "True\n" 132 | ] 133 | } 134 | ], 135 | "source": [ 136 | "# Altres operadors lògics disponibles són més petit o igual '<=', més gran o igual '> =' \n", 137 | "# o la negació 'not'\n", 138 | "print(a <= b)\n", 139 | "print(a >= b)\n", 140 | "\n", 141 | "a = False\n", 142 | "print(not a)" 143 | ] 144 | }, 145 | { 146 | "cell_type": "markdown", 147 | "metadata": {}, 148 | "source": [ 149 | "També podem alterar el flux d'execució del nostre programa utilitzant\n", 150 | "les estructures *if... else* o *if... elif... else*. Vegem-ne uns quants\n", 151 | "exemples:" 152 | ] 153 | }, 154 | { 155 | "cell_type": "code", 156 | "execution_count": 5, 157 | "metadata": { 158 | "attributes": { 159 | "classes": [ 160 | "sourceCode" 161 | ], 162 | "id": "" 163 | } 164 | }, 165 | "outputs": [ 166 | { 167 | "name": "stdout", 168 | "output_type": "stream", 169 | "text": [ 170 | "a és menor o igual que b\n" 171 | ] 172 | } 173 | ], 174 | "source": [ 175 | "a = 5\n", 176 | "b = 6\n", 177 | "if a > b:\n", 178 | " print('a és major que b')\n", 179 | "else:\n", 180 | " print('a és menor o igual que b')" 181 | ] 182 | }, 183 | { 184 | "cell_type": "code", 185 | "execution_count": 6, 186 | "metadata": { 187 | "attributes": { 188 | "classes": [ 189 | "sourceCode" 190 | ], 191 | "id": "" 192 | } 193 | }, 194 | "outputs": [ 195 | { 196 | "name": "stdout", 197 | "output_type": "stream", 198 | "text": [ 199 | "a és igual a b\n" 200 | ] 201 | } 202 | ], 203 | "source": [ 204 | "a = 5\n", 205 | "b = 5\n", 206 | "if a > b:\n", 207 | " print('a és major que b')\n", 208 | "elif a < b:\n", 209 | " print('a és menor que b')\n", 210 | "else:\n", 211 | " print('a és igual a b')" 212 | ] 213 | }, 214 | { 215 | "cell_type": "markdown", 216 | "metadata": {}, 217 | "source": [ 218 | "En Python hi només dues maneres d'iterar una seqüència: mitjançant\n", 219 | "_**for**_ o mitjançant _**while**_. La primera de les opcions, *for*,\n", 220 | "iterarà un per un els elements continguts en una llista. En el cas de\n", 221 | "*while*, iteraremos mentre la condició de permanència al bucle es\n", 222 | "compleixi. Vegem-ne uns exemples:" 223 | ] 224 | }, 225 | { 226 | "cell_type": "code", 227 | "execution_count": 7, 228 | "metadata": { 229 | "attributes": { 230 | "classes": [ 231 | "sourceCode" 232 | ], 233 | "id": "" 234 | } 235 | }, 236 | "outputs": [ 237 | { 238 | "name": "stdout", 239 | "output_type": "stream", 240 | "text": [ 241 | "Kraken\n", 242 | "Leviathan\n", 243 | "Uroborus\n", 244 | "Hydra\n", 245 | "0 Kraken\n", 246 | "1 Leviathan\n", 247 | "2 Uroborus\n", 248 | "3 Hydra\n" 249 | ] 250 | } 251 | ], 252 | "source": [ 253 | "monsters = ['Kraken', 'Leviathan', 'Uroborus', 'Hydra']\n", 254 | "\n", 255 | "# Primer mètode iterant mitjançant for:\n", 256 | "for monster in monsters:\n", 257 | " print(monster)\n", 258 | "\n", 259 | "print\n", 260 | "\n", 261 | "# Segon mètode. La funció especial 'enumerate' ens retorna una tupla en què el primer element és un \n", 262 | "# índex que comença per 0 i augmenta d'1 a 1 i el segon element és el valor de la posició a la llista:\n", 263 | "for i, monster in enumerate(monsters):\n", 264 | " print(i, monster)" 265 | ] 266 | }, 267 | { 268 | "cell_type": "code", 269 | "execution_count": 8, 270 | "metadata": { 271 | "attributes": { 272 | "classes": [ 273 | "sourceCode" 274 | ], 275 | "id": "" 276 | } 277 | }, 278 | "outputs": [ 279 | { 280 | "name": "stdout", 281 | "output_type": "stream", 282 | "text": [ 283 | "0 Kraken\n", 284 | "1 Leviathan\n", 285 | "2 Uroborus\n", 286 | "3 Hydra\n" 287 | ] 288 | } 289 | ], 290 | "source": [ 291 | "# També podríem iterar la llista mitjançant while, però és una manera molt menys idiomàtica en Python \n", 292 | "# i preferirem sempre l'opció de for:\n", 293 | "i = 0\n", 294 | "# Mentre que l'índex 'i' sigui més petit que la longitud de la llista 'monsters':\n", 295 | "while i < len(monsters):\n", 296 | " # Imprimeix el valor de la llista en la posició 'i'.\n", 297 | " print(i, monsters[i])\n", 298 | " # No ens oblidem d'actualitzar el valor de 'i' sumant-li 1 o tindrem un bucle infinit.\n", 299 | " i += 1" 300 | ] 301 | }, 302 | { 303 | "cell_type": "markdown", 304 | "metadata": {}, 305 | "source": [ 306 | "En aquest moment seríem capaços de calcular la sèrie de Fibonacci fins a\n", 307 | "un determinat valor:" 308 | ] 309 | }, 310 | { 311 | "cell_type": "code", 312 | "execution_count": 9, 313 | "metadata": { 314 | "attributes": { 315 | "classes": [ 316 | "sourceCode" 317 | ], 318 | "id": "" 319 | } 320 | }, 321 | "outputs": [ 322 | { 323 | "name": "stdout", 324 | "output_type": "stream", 325 | "text": [ 326 | "0 1 1 2 3 5 8 13 21 34 55 89 " 327 | ] 328 | } 329 | ], 330 | "source": [ 331 | "# Calculem el valor de la sèrie fins a un valor n = 100.\n", 332 | "n = 100\n", 333 | "\n", 334 | "a, b = 0, 1\n", 335 | "while a < n:\n", 336 | " print(a, end =\" \")\n", 337 | " a, b = b, a+b" 338 | ] 339 | }, 340 | { 341 | "cell_type": "markdown", 342 | "metadata": {}, 343 | "source": [ 344 | "A Python disposem d'una funció molt útil per generar una seqüència de\n", 345 | "nombres, que podem utilitzar de diferents maneres:" 346 | ] 347 | }, 348 | { 349 | "cell_type": "code", 350 | "execution_count": 10, 351 | "metadata": { 352 | "attributes": { 353 | "classes": [ 354 | "sourceCode" 355 | ], 356 | "id": "" 357 | } 358 | }, 359 | "outputs": [ 360 | { 361 | "data": { 362 | "text/plain": [ 363 | "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]" 364 | ] 365 | }, 366 | "execution_count": 10, 367 | "metadata": {}, 368 | "output_type": "execute_result" 369 | } 370 | ], 371 | "source": [ 372 | "# La funció 'range' ens retorna una llista de nombres:\n", 373 | "list(range(10))" 374 | ] 375 | }, 376 | { 377 | "cell_type": "markdown", 378 | "metadata": {}, 379 | "source": [ 380 | "Fixeu-vos que `range` no torna directament una llista, sinó que retorna un tipus propi del mateix nom. Per aquest motiu, per obtenir una llista cal fer una conversió de tipus utilitzant `list()`. Això és una novetat en Python 3, ja que en Python 2 la funció `range` retornava una llista." 381 | ] 382 | }, 383 | { 384 | "cell_type": "code", 385 | "execution_count": 11, 386 | "metadata": {}, 387 | "outputs": [ 388 | { 389 | "name": "stdout", 390 | "output_type": "stream", 391 | "text": [ 392 | "\n", 393 | "\n" 394 | ] 395 | } 396 | ], 397 | "source": [ 398 | "# Visualitzem el tipus de retorn de range\n", 399 | "print(type(range(10)))\n", 400 | "print(type(list(range(10))))" 401 | ] 402 | }, 403 | { 404 | "cell_type": "markdown", 405 | "metadata": {}, 406 | "source": [ 407 | "Vegem alguns dels usos més habituals de `range`:" 408 | ] 409 | }, 410 | { 411 | "cell_type": "code", 412 | "execution_count": 12, 413 | "metadata": { 414 | "attributes": { 415 | "classes": [ 416 | "sourceCode" 417 | ], 418 | "id": "" 419 | } 420 | }, 421 | "outputs": [ 422 | { 423 | "name": "stdout", 424 | "output_type": "stream", 425 | "text": [ 426 | "0 1 2 3 4 5 6 7 8 9 \n" 427 | ] 428 | } 429 | ], 430 | "source": [ 431 | "# Podem utilitzar-la per iterar:\n", 432 | "for i in range(10):\n", 433 | " print(i, end = \" \")\n", 434 | "\n", 435 | "print()" 436 | ] 437 | }, 438 | { 439 | "cell_type": "code", 440 | "execution_count": 13, 441 | "metadata": { 442 | "attributes": { 443 | "classes": [ 444 | "sourceCode" 445 | ], 446 | "id": "" 447 | } 448 | }, 449 | "outputs": [ 450 | { 451 | "name": "stdout", 452 | "output_type": "stream", 453 | "text": [ 454 | "0 1 2 3 4 5 6 7 8 9 \n", 455 | "5 6 7 8 9 \n", 456 | "5 8 " 457 | ] 458 | } 459 | ], 460 | "source": [ 461 | "# Podem definir el rang d'acció. \n", 462 | "\n", 463 | "# Per exemple, especificant només el final com hem fet abans\n", 464 | "for i in range(10):\n", 465 | " print(i, end = \" \")\n", 466 | "\n", 467 | "print()\n", 468 | "\n", 469 | "# especificant inici i fi:\n", 470 | "for i in range(5, 10):\n", 471 | " print(i, end = \" \")\n", 472 | "\n", 473 | "print()\n", 474 | "\n", 475 | "# o especificant també el salt entre cada valor:\n", 476 | "for i in range(5, 10, 3):\n", 477 | " print(i, end = \" \")" 478 | ] 479 | }, 480 | { 481 | "cell_type": "markdown", 482 | "metadata": {}, 483 | "source": [ 484 | "Sempre que no necessitem explícitament una llista, farem servir directament el tipus `range` (sense fer la conversió a llista), ja que això és en general més eficient (estalvia memòria). Només quan necessitem una llista, (per exemple, per visualitzar el resultat com hem fet en el primer exemple) convertirem el resultat de `range` a llista." 485 | ] 486 | }, 487 | { 488 | "cell_type": "code", 489 | "execution_count": 14, 490 | "metadata": { 491 | "attributes": { 492 | "classes": [ 493 | "sourceCode" 494 | ], 495 | "id": "" 496 | } 497 | }, 498 | "outputs": [ 499 | { 500 | "name": "stdout", 501 | "output_type": "stream", 502 | "text": [ 503 | "34\n", 504 | "376\n", 505 | "41\n", 506 | "424\n", 507 | "\n", 508 | "Spain\n", 509 | "Andorra\n", 510 | "Switzerland\n", 511 | "None\n", 512 | "\n", 513 | "34 Spain\n", 514 | "376 Andorra\n", 515 | "41 Switzerland\n", 516 | "424 None\n" 517 | ] 518 | } 519 | ], 520 | "source": [ 521 | "# També és possible iterar en un diccionari:\n", 522 | "country_codes = {34: 'Spain', 376: 'Andorra', 41: 'Switzerland', 424: None}\n", 523 | "\n", 524 | "# Per clau:\n", 525 | "for country_code in country_codes.keys():\n", 526 | " print(country_code)\n", 527 | "print()\n", 528 | "\n", 529 | "# Per valor:\n", 530 | "for country in country_codes.values():\n", 531 | " print(country)\n", 532 | "print()\n", 533 | "\n", 534 | "# Per tots dos alhora:\n", 535 | "for country_code, country in country_codes.items():\n", 536 | " print(country_code, country)" 537 | ] 538 | }, 539 | { 540 | "cell_type": "markdown", 541 | "metadata": {}, 542 | "source": [ 543 | "Funcions\n", 544 | "---------\n", 545 | "\n", 546 | "Una altra manera molt important d'organitzar el flux d'execució és\n", 547 | "encapsulant una certa porció de codi en una funció reutilitzable. Una funció\n", 548 | "en Python utilitza el mateix concepte que una funció matemàtica. Per\n", 549 | "exemple, imaginem-nos la funció matemàtica:\n", 550 | "\n", 551 | "*suma(x, y) = x + y*\n", 552 | "\n", 553 | "A Python podem definir la mateixa funció de la manera següent:" 554 | ] 555 | }, 556 | { 557 | "cell_type": "code", 558 | "execution_count": 15, 559 | "metadata": { 560 | "attributes": { 561 | "classes": [ 562 | "sourceCode" 563 | ], 564 | "id": "" 565 | } 566 | }, 567 | "outputs": [ 568 | { 569 | "name": "stdout", 570 | "output_type": "stream", 571 | "text": [ 572 | "6\n", 573 | "0\n", 574 | "6.0\n" 575 | ] 576 | } 577 | ], 578 | "source": [ 579 | "# La funció 'suma' es defineix mitjançant la paraula especial 'def' i té dos arguments: 'x' i 'y':\n", 580 | "def suma(x, y):\n", 581 | " # Tornem el valor de la suma\n", 582 | " return x + y\n", 583 | "\n", 584 | "# En aquest moment, podem anomenar-la amb qualsevol valor:\n", 585 | "print(suma(2, 4))\n", 586 | "print(suma(5, -5))\n", 587 | "print(suma(3.5, 2.5))" 588 | ] 589 | }, 590 | { 591 | "cell_type": "code", 592 | "execution_count": 16, 593 | "metadata": { 594 | "attributes": { 595 | "classes": [ 596 | "sourceCode" 597 | ], 598 | "id": "" 599 | } 600 | }, 601 | "outputs": [], 602 | "source": [ 603 | "# Podem definir una funció que no faci res utilitzant la paraula especial 'pass':\n", 604 | "\n", 605 | "def dummy():\n", 606 | " pass\n", 607 | "\n", 608 | "dummy()" 609 | ] 610 | }, 611 | { 612 | "cell_type": "code", 613 | "execution_count": 17, 614 | "metadata": { 615 | "attributes": { 616 | "classes": [ 617 | "sourceCode" 618 | ], 619 | "id": "" 620 | } 621 | }, 622 | "outputs": [ 623 | { 624 | "name": "stdout", 625 | "output_type": "stream", 626 | "text": [ 627 | "0 1 1 2 3 5 8 " 628 | ] 629 | } 630 | ], 631 | "source": [ 632 | "# Podríem tornar a definir el tros de codi de la seqüència de Fibonacci com una funció:\n", 633 | "\n", 634 | "def fibonacci(n=100):\n", 635 | " a, b = 0, 1\n", 636 | " while a < n:\n", 637 | " print(a, end = \" \")\n", 638 | " a, b = b, a+b\n", 639 | "\n", 640 | "fibonacci(10)" 641 | ] 642 | }, 643 | { 644 | "cell_type": "code", 645 | "execution_count": 18, 646 | "metadata": { 647 | "attributes": { 648 | "classes": [ 649 | "sourceCode" 650 | ], 651 | "id": "" 652 | } 653 | }, 654 | "outputs": [ 655 | { 656 | "name": "stdout", 657 | "output_type": "stream", 658 | "text": [ 659 | "0 1 1 2 3 5 8 13 21 34 55 89 " 660 | ] 661 | } 662 | ], 663 | "source": [ 664 | "# A l'exemple anterior, hem definit que l'argument n tingui un valor per defecte. Això és molt útil\n", 665 | "# en els casos en què utilitzem la funció sempre amb un mateix valor, vulguem deixar constància d'un\n", 666 | "# cas d'exemple o per defecte. En aquest cas, podem executar la funció sense passar-li cap valor:\n", 667 | "fibonacci()" 668 | ] 669 | }, 670 | { 671 | "cell_type": "code", 672 | "execution_count": 19, 673 | "metadata": { 674 | "attributes": { 675 | "classes": [ 676 | "sourceCode" 677 | ], 678 | "id": "" 679 | } 680 | }, 681 | "outputs": [ 682 | { 683 | "name": "stdout", 684 | "output_type": "stream", 685 | "text": [ 686 | "9\n", 687 | "8\n" 688 | ] 689 | } 690 | ], 691 | "source": [ 692 | "# Podem definir part dels arguments amb valors per defecte i un altre sense. \n", 693 | "# Els arguments sense valor per defecte sempre han d'estar més a l'esquerra a la definició de la funció:\n", 694 | "\n", 695 | "def potencia(a, b=2):\n", 696 | " # Per defecte, elevarem al quadrat.\n", 697 | " return a**b\n", 698 | "\n", 699 | "print(potencia(3))\n", 700 | "print(potencia(2, 3))" 701 | ] 702 | }, 703 | { 704 | "cell_type": "markdown", 705 | "metadata": {}, 706 | "source": [ 707 | "**Recomanem la lectura de la [documentació oficial](https://docs.python.org/3/tutorial/controlflow.html)** per\n", 708 | "acabar de fixar coneixements.\n", 709 | "\n", 710 | "Llegir i escriure des de fitxers\n", 711 | "------------------------------\n", 712 | "\n", 713 | "Una tasca habitual és llegir línies d'un fitxer o escriure línies en un\n", 714 | "fitxer. A Python, llegir i escriure fitxers es fa amb la\n", 715 | "llibreria *os*. Una llibreria és un conjunt de codi que té cert\n", 716 | "sentit agrupar per a ser utilitzat per altra gent. En el nostre cas, *os* és\n", 717 | "una llibreria que agrupa funcions relacionades amb el sistema\n", 718 | "operatiu (_**o**perating **s**ystem_). Per carregar una llibreria,\n", 719 | "utilitzarem la paraula reservada _**import**_. Més endavant explicarem\n", 720 | "algunes particularitats d'utilitzar i importar llibreries. A\n", 721 | "continuació us expliquem com escriure i llegir un fitxer:" 722 | ] 723 | }, 724 | { 725 | "cell_type": "code", 726 | "execution_count": 20, 727 | "metadata": {}, 728 | "outputs": [], 729 | "source": [ 730 | "# Primer de tot, escriurem en un fitxer:\n", 731 | "import os\n", 732 | "\n", 733 | "# Obrim un fitxer de nom 'a_file.txt' per a escriptura (d'aquí la 'w', 'writing').\n", 734 | "# L'assignem a un objecte per gestionar el fitxer de nom 'out':\n", 735 | "out = open('a_file.txt', 'w')\n", 736 | "# Escriurem 10 línies, cadascuna amb un número del 0 al 9.\n", 737 | "for i in range(10):\n", 738 | " # La línia següent escriu al fitxer tot el que posem dins 'out.write()'\n", 739 | " # En el nostre cas, és un string del tipus '0\\n', '1\\n', etc. Això ho aconseguim \n", 740 | " # utilitzant els wildcards %d i %s.\n", 741 | " # %s representa un string o una cadena de caràcters i %d un nombre enter.\n", 742 | " # Concatenem en aquest cas un nombre amb un string que es tracta del salt de\n", 743 | " # línia, os.linesep, que equival a Linux\n", 744 | " # a '\\n':\n", 745 | " out.write(\"Línea %d%s\" % (i, os.linesep))\n", 746 | " \n", 747 | "out.close()" 748 | ] 749 | }, 750 | { 751 | "cell_type": "code", 752 | "execution_count": 21, 753 | "metadata": {}, 754 | "outputs": [ 755 | { 756 | "name": "stdout", 757 | "output_type": "stream", 758 | "text": [ 759 | "Línea 0\n", 760 | "Línea 1\n", 761 | "Línea 2\n", 762 | "Línea 3\n", 763 | "Línea 4\n", 764 | "Línea 5\n", 765 | "Línea 6\n", 766 | "Línea 7\n", 767 | "Línea 8\n", 768 | "Línea 9\n", 769 | "\n", 770 | "Línea 0\n", 771 | "Línea 1\n", 772 | "Línea 2\n", 773 | "Línea 3\n", 774 | "Línea 4\n", 775 | "Línea 5\n", 776 | "Línea 6\n", 777 | "Línea 7\n", 778 | "Línea 8\n", 779 | "Línea 9\n", 780 | "\n", 781 | "Línea 0\n", 782 | "Línea 1\n", 783 | "Línea 2\n", 784 | "Línea 3\n", 785 | "Línea 4\n", 786 | "Línea 5\n", 787 | "Línea 6\n", 788 | "Línea 7\n", 789 | "Línea 8\n", 790 | "Línea 9\n" 791 | ] 792 | } 793 | ], 794 | "source": [ 795 | "# Ara llegirem el fitxer que acabem d'escriure de tres maneres diferents:\n", 796 | "\n", 797 | "# Primer mètode\n", 798 | "f = open('a_file.txt')\n", 799 | "for line in f:\n", 800 | " print(line, end = \"\")\n", 801 | "f.close()\n", 802 | "print()\n", 803 | "\n", 804 | "# Segon mètode\n", 805 | "f = open('a_file.txt')\n", 806 | "lines = f.readlines()\n", 807 | "for line in lines:\n", 808 | " print(line, end = \"\")\n", 809 | "f.close()\n", 810 | "print()\n", 811 | "\n", 812 | "# Tercer mètode\n", 813 | "with open('a_file.txt') as f:\n", 814 | " for line in f:\n", 815 | " print(line, end = \"\")" 816 | ] 817 | }, 818 | { 819 | "cell_type": "markdown", 820 | "metadata": {}, 821 | "source": [ 822 | "Organització del codi\n", 823 | "-----------------------\n", 824 | "\n", 825 | "Un mòdul de Python és qualsevol fitxer amb extensió *.py* que estigui\n", 826 | "sota la ruta del _path_ de Python. El path de Python es pot consultar\n", 827 | "important la llibreria sys:" 828 | ] 829 | }, 830 | { 831 | "cell_type": "code", 832 | "execution_count": 22, 833 | "metadata": {}, 834 | "outputs": [ 835 | { 836 | "name": "stdout", 837 | "output_type": "stream", 838 | "text": [ 839 | "['/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '', '/usr/local/lib/python3.6/dist-packages', '/usr/lib/python3/dist-packages', '/usr/local/lib/python3.6/dist-packages/IPython/extensions', '/home/datasci/.ipython']\n" 840 | ] 841 | } 842 | ], 843 | "source": [ 844 | "import sys\n", 845 | "print(sys.path)" 846 | ] 847 | }, 848 | { 849 | "cell_type": "markdown", 850 | "metadata": {}, 851 | "source": [ 852 | "Per defecte, Python també mira les llibreries que s'hagin definit a\n", 853 | "la variable d'entorn \\$PYTHONPATH (això pot canviar lleugerament en un\n", 854 | "[entorn Windows](https://docs.python.org/3/using/cmdline.html))." 855 | ] 856 | }, 857 | { 858 | "cell_type": "markdown", 859 | "metadata": {}, 860 | "source": [ 861 | "Un paquet en Python és qualsevol directori que contingui un fitxer\n", 862 | "especial de nom *\\_\\_init\\_\\_.py* (aquest fitxer estarà buit la majoria\n", 863 | "de vegades).\n", 864 | "\n", 865 | "Un mòdul pot contenir diferents funcions, variables o objectes. Per\n", 866 | "exemple, definim un mòdul de nom *prog\\_datasci.py* que contingui:" 867 | ] 868 | }, 869 | { 870 | "cell_type": "code", 871 | "execution_count": 23, 872 | "metadata": { 873 | "attributes": { 874 | "classes": [ 875 | "sourceCode" 876 | ], 877 | "id": "" 878 | } 879 | }, 880 | "outputs": [], 881 | "source": [ 882 | "# prog_datasci.py\n", 883 | "\n", 884 | "PI = 3.14159265\n", 885 | "\n", 886 | "def suma(x, y):\n", 887 | " return x + y\n", 888 | "\n", 889 | "\n", 890 | "def resta(x, y):\n", 891 | " return x - y" 892 | ] 893 | }, 894 | { 895 | "cell_type": "markdown", 896 | "metadata": {}, 897 | "source": [ 898 | "Per utilitzar des d'un altre mòdul o _script_ aquestes funcions, hauríem\n", 899 | "d'escriure el següent:" 900 | ] 901 | }, 902 | { 903 | "cell_type": "code", 904 | "execution_count": 24, 905 | "metadata": { 906 | "attributes": { 907 | "classes": [ 908 | "sourceCode" 909 | ], 910 | "id": "" 911 | } 912 | }, 913 | "outputs": [], 914 | "source": [ 915 | "from prog_datasci import PI, suma, resta\n", 916 | "\n", 917 | "# I llavors podríem utilitzar-les normalment.\n", 918 | "rset = suma(2,5)" 919 | ] 920 | }, 921 | { 922 | "cell_type": "markdown", 923 | "metadata": {}, 924 | "source": [ 925 | "A Python també podem utilitzar la directiva `from prog_datasci import *`, però el seu ús està **totalment desaconsellat**. La raó és\n", 926 | "que estaríem important gran quantitat de codi que no utilitzarem (amb el\n", 927 | "consegüent augment de l'ús de la memòria), però a més, podríem tenir\n", 928 | "col·lisions de noms (funcions que es diguin de la mateixa manera en\n", 929 | "diferents mòduls) sense el nostre coneixement. Si no és que és\n", 930 | "imprescindible, no utilitzarem aquesta directiva i importarem una a una\n", 931 | "les llibreries i les funcions que necessitarem.\n", 932 | "\n", 933 | "Podeu aprendre més sobre importar llibreries i definir els vostres\n", 934 | "propis mòduls [aquí](http://life.bsc.es/pid/brian/python/#/5)." 935 | ] 936 | } 937 | ], 938 | "metadata": { 939 | "kernelspec": { 940 | "display_name": "Python 3", 941 | "language": "python", 942 | "name": "python3" 943 | }, 944 | "language_info": { 945 | "codemirror_mode": { 946 | "name": "ipython", 947 | "version": 3 948 | }, 949 | "file_extension": ".py", 950 | "mimetype": "text/x-python", 951 | "name": "python", 952 | "nbconvert_exporter": "python", 953 | "pygments_lexer": "ipython3", 954 | "version": "3.6.8" 955 | } 956 | }, 957 | "nbformat": 4, 958 | "nbformat_minor": 1 959 | } 960 | -------------------------------------------------------------------------------- /python_1/unit_3/IB-prog_datasci_3_apython.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Programación para *Data Science*" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "Unidad 3: Conceptos avanzados de Python\n", 15 | "------------------------------------------------------\n", 16 | "\n", 17 | "### Instrucciones de uso\n", 18 | "\n", 19 | "En el módulo anterior introducimos conceptos básicos sobre variables y su uso en Python. En este módulo estudiaremos conceptos más avanzados como las instrucciones de flujo de ejecución (for, while, if), cómo definir y utilizar funciones, cómo leer y escribir ficheros y cómo organizar el código." 20 | ] 21 | }, 22 | { 23 | "cell_type": "markdown", 24 | "metadata": {}, 25 | "source": [ 26 | "Iteración y operaciones lógicas\n", 27 | "-------------------------------\n", 28 | "\n", 29 | "En la gran mayoría de ocasiones, tendremos que manipular nuestros datos y para ello utilizaremos los conceptos de iteración y las operaciones lógicas. Las operaciones lógicas nos permiten comparar valores entre variables (mayor, menor, igualdad) y la iteración ir visitando uno a uno los elementos de una lista, tupla, diccionario o cualquier estructura de datos que sea susceptible de secuenciarse." 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": 1, 35 | "metadata": {}, 36 | "outputs": [ 37 | { 38 | "name": "stdout", 39 | "output_type": "stream", 40 | "text": [ 41 | "True\n" 42 | ] 43 | } 44 | ], 45 | "source": [ 46 | "# Las operaciones lógicas tendrán como resultado un valor cierto (True) o falso (False):\n", 47 | "\n", 48 | "a = 5\n", 49 | "b = 1\n", 50 | "\n", 51 | "# ¿Es el valor de a mayor que b?\n", 52 | "print(a > b)" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": 2, 58 | "metadata": {}, 59 | "outputs": [ 60 | { 61 | "name": "stdout", 62 | "output_type": "stream", 63 | "text": [ 64 | "False\n" 65 | ] 66 | } 67 | ], 68 | "source": [ 69 | "# ¿Es el valor de a menor que b?\n", 70 | "print(a < b)" 71 | ] 72 | }, 73 | { 74 | "cell_type": "code", 75 | "execution_count": 3, 76 | "metadata": {}, 77 | "outputs": [ 78 | { 79 | "name": "stdout", 80 | "output_type": "stream", 81 | "text": [ 82 | "True\n" 83 | ] 84 | } 85 | ], 86 | "source": [ 87 | "b = 5\n", 88 | "# ¿Es el valor de b igual al de a?\n", 89 | "print(b == a)" 90 | ] 91 | }, 92 | { 93 | "cell_type": "code", 94 | "execution_count": 4, 95 | "metadata": {}, 96 | "outputs": [ 97 | { 98 | "name": "stdout", 99 | "output_type": "stream", 100 | "text": [ 101 | "True\n", 102 | "True\n", 103 | "True\n" 104 | ] 105 | } 106 | ], 107 | "source": [ 108 | "# Otros operadores lógicos disponibles son menor o igual '<=', mayor o igual '>=' o la negación 'not'.\n", 109 | "print(a <= b)\n", 110 | "print(a >= b)\n", 111 | "\n", 112 | "a = False\n", 113 | "print(not a)" 114 | ] 115 | }, 116 | { 117 | "cell_type": "markdown", 118 | "metadata": {}, 119 | "source": [ 120 | "También podemos alterar el flujo de ejecución de nuestro programa utilizando las estructuras *if...else* o *if...elif...else*. Veamos unos cuantos ejemplos:" 121 | ] 122 | }, 123 | { 124 | "cell_type": "code", 125 | "execution_count": 5, 126 | "metadata": {}, 127 | "outputs": [ 128 | { 129 | "name": "stdout", 130 | "output_type": "stream", 131 | "text": [ 132 | "a es menor o igual que b\n" 133 | ] 134 | } 135 | ], 136 | "source": [ 137 | "a = 5\n", 138 | "b = 6\n", 139 | "if a > b:\n", 140 | " print('a es mayor que b')\n", 141 | "else:\n", 142 | " print('a es menor o igual que b')" 143 | ] 144 | }, 145 | { 146 | "cell_type": "code", 147 | "execution_count": 6, 148 | "metadata": {}, 149 | "outputs": [ 150 | { 151 | "name": "stdout", 152 | "output_type": "stream", 153 | "text": [ 154 | "a es igual a b\n" 155 | ] 156 | } 157 | ], 158 | "source": [ 159 | "a = 5\n", 160 | "b = 5\n", 161 | "if a > b:\n", 162 | " print('a es mayor que b')\n", 163 | "elif a < b:\n", 164 | " print('a es menor que b')\n", 165 | "else:\n", 166 | " print('a es igual a b')" 167 | ] 168 | }, 169 | { 170 | "cell_type": "markdown", 171 | "metadata": {}, 172 | "source": [ 173 | "En Python existen solo dos formas de iterar una secuencia: mediante **for** o mediante **while**. La primera de las opciones, *for*, iterará uno por uno los elementos contenidos en una lista. En el caso de *while*, iteraremos mientras la condición de permanencia en el bucle se cumpla. Veamos unos ejemplos:" 174 | ] 175 | }, 176 | { 177 | "cell_type": "code", 178 | "execution_count": 7, 179 | "metadata": {}, 180 | "outputs": [ 181 | { 182 | "name": "stdout", 183 | "output_type": "stream", 184 | "text": [ 185 | "Kraken\n", 186 | "Leviathan\n", 187 | "Uroborus\n", 188 | "Hydra\n", 189 | "\n", 190 | "0 Kraken\n", 191 | "1 Leviathan\n", 192 | "2 Uroborus\n", 193 | "3 Hydra\n" 194 | ] 195 | } 196 | ], 197 | "source": [ 198 | "monsters = ['Kraken', 'Leviathan', 'Uroborus', 'Hydra']\n", 199 | "\n", 200 | "# Primer método iterando mediante for:\n", 201 | "for monster in monsters:\n", 202 | " print(monster)\n", 203 | "\n", 204 | "print()\n", 205 | "\n", 206 | "# Segundo método. La función especial 'enumerate' nos devuelve una tupla en la que el primer elemento es un \n", 207 | "# índice que empieza en 0 y aumenta de 1 en 1 y el segundo elemento es el valor de la posición en la lista:\n", 208 | "for i, monster in enumerate(monsters):\n", 209 | " print(i, monster)" 210 | ] 211 | }, 212 | { 213 | "cell_type": "code", 214 | "execution_count": 8, 215 | "metadata": {}, 216 | "outputs": [ 217 | { 218 | "name": "stdout", 219 | "output_type": "stream", 220 | "text": [ 221 | "0 Kraken\n", 222 | "1 Leviathan\n", 223 | "2 Uroborus\n", 224 | "3 Hydra\n" 225 | ] 226 | } 227 | ], 228 | "source": [ 229 | "# También podríamos iterar la lista mediante while, pero es una forma mucho menos idiomática en Python \n", 230 | "# y preferiremos siempre la opción de for:\n", 231 | "i = 0\n", 232 | "# Mientras que el índice 'i' sea menor que la longitud de la lista 'monsters':\n", 233 | "while i < len(monsters):\n", 234 | " # Imprime el valor de la lista en la posición 'i'.\n", 235 | " print(i, monsters[i])\n", 236 | " # No nos olvidemos de actualizar el valor de 'i' sumándole 1 o tendremos un bucle infinito.\n", 237 | " i += 1\n" 238 | ] 239 | }, 240 | { 241 | "cell_type": "markdown", 242 | "metadata": {}, 243 | "source": [ 244 | "En este momento seríamos capaces de calcular la serie de Fibonacci hasta un determinado valor:" 245 | ] 246 | }, 247 | { 248 | "cell_type": "code", 249 | "execution_count": 9, 250 | "metadata": {}, 251 | "outputs": [ 252 | { 253 | "name": "stdout", 254 | "output_type": "stream", 255 | "text": [ 256 | "0 1 1 2 3 5 8 13 21 34 55 89 " 257 | ] 258 | } 259 | ], 260 | "source": [ 261 | "# Calculamos el valor de la serie hasta un valor n=100.\n", 262 | "n = 100\n", 263 | "\n", 264 | "a, b = 0, 1\n", 265 | "while a < n:\n", 266 | " print(a, end = \" \")\n", 267 | " a, b = b, a+b" 268 | ] 269 | }, 270 | { 271 | "cell_type": "markdown", 272 | "metadata": {}, 273 | "source": [ 274 | "En Python disponemos de una función muy útil para generar una secuencia de números, que podemos utilizar de diferentes formas:" 275 | ] 276 | }, 277 | { 278 | "cell_type": "code", 279 | "execution_count": 10, 280 | "metadata": {}, 281 | "outputs": [ 282 | { 283 | "data": { 284 | "text/plain": [ 285 | "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]" 286 | ] 287 | }, 288 | "execution_count": 10, 289 | "metadata": {}, 290 | "output_type": "execute_result" 291 | } 292 | ], 293 | "source": [ 294 | "# Podemos usar la función range para obtener una lista de números:\n", 295 | "list(range(10))" 296 | ] 297 | }, 298 | { 299 | "cell_type": "markdown", 300 | "metadata": {}, 301 | "source": [ 302 | "Fijaros que `range` no devuelve directamente una lista, sino que devuelve un tipo propio del mismo nombre. Por este motivo, para obtener una lista hay que hacer una conversión de tipo usando `list()`. Esto es una novedad en Python 3, ya que en Python 2 la función `range` devolvía una lista." 303 | ] 304 | }, 305 | { 306 | "cell_type": "code", 307 | "execution_count": 11, 308 | "metadata": {}, 309 | "outputs": [ 310 | { 311 | "name": "stdout", 312 | "output_type": "stream", 313 | "text": [ 314 | "\n", 315 | "\n" 316 | ] 317 | } 318 | ], 319 | "source": [ 320 | "# Visualizamos el tipo de retorno de range\n", 321 | "print(type(range(10)))\n", 322 | "print(type(list(range(10))))" 323 | ] 324 | }, 325 | { 326 | "cell_type": "markdown", 327 | "metadata": {}, 328 | "source": [ 329 | "Veamos algunos de los usos más habituales de `range`:" 330 | ] 331 | }, 332 | { 333 | "cell_type": "code", 334 | "execution_count": 12, 335 | "metadata": {}, 336 | "outputs": [ 337 | { 338 | "name": "stdout", 339 | "output_type": "stream", 340 | "text": [ 341 | "0 1 2 3 4 5 6 7 8 9 \n" 342 | ] 343 | } 344 | ], 345 | "source": [ 346 | "# Podemos utilizar range para iterar:\n", 347 | "for i in range(10):\n", 348 | " print(i, end = \" \")\n", 349 | "\n", 350 | "print()" 351 | ] 352 | }, 353 | { 354 | "cell_type": "code", 355 | "execution_count": 13, 356 | "metadata": {}, 357 | "outputs": [ 358 | { 359 | "name": "stdout", 360 | "output_type": "stream", 361 | "text": [ 362 | "0 1 2 3 4 5 6 7 8 9 \n", 363 | "5 6 7 8 9 \n", 364 | "5 8 " 365 | ] 366 | } 367 | ], 368 | "source": [ 369 | "# Podemos definir el rango de acción. \n", 370 | "\n", 371 | "# Por ejemplo, especificando únicamente el final como hemos hecho anteriormente\n", 372 | "for i in range(10):\n", 373 | " print(i, end = \" \")\n", 374 | "\n", 375 | "print()\n", 376 | "\n", 377 | "# especificando inicio y final:\n", 378 | "for i in range(5, 10):\n", 379 | " print(i, end = \" \")\n", 380 | "\n", 381 | "print()\n", 382 | "\n", 383 | "# o especificar también el salto entre cada valor del resultado:\n", 384 | "for i in range(5, 10, 3):\n", 385 | " print(i, end = \" \")" 386 | ] 387 | }, 388 | { 389 | "cell_type": "markdown", 390 | "metadata": {}, 391 | "source": [ 392 | "Siempre que no necesitemos explícitamente una lista, usaremos directamente el tipo `range` (sin hacer la conversión a lista), ya que esto es en general más eficiente (ahorra memoria). Solo cuando necesitemos una lista, (por ejemplo, para visualizar el resultado como hemos hecho en el primer ejemplo) convertiremos el resultado de `range` a lista." 393 | ] 394 | }, 395 | { 396 | "cell_type": "code", 397 | "execution_count": 14, 398 | "metadata": {}, 399 | "outputs": [ 400 | { 401 | "name": "stdout", 402 | "output_type": "stream", 403 | "text": [ 404 | "34\n", 405 | "376\n", 406 | "41\n", 407 | "424\n", 408 | "\n", 409 | "Spain\n", 410 | "Andorra\n", 411 | "Switzerland\n", 412 | "None\n", 413 | "\n", 414 | "34 Spain\n", 415 | "376 Andorra\n", 416 | "41 Switzerland\n", 417 | "424 None\n" 418 | ] 419 | } 420 | ], 421 | "source": [ 422 | "# También es posible iterar en un diccionario:\n", 423 | "country_codes = {34: 'Spain', 376: 'Andorra', 41: 'Switzerland', 424: None}\n", 424 | "\n", 425 | "# Por clave:\n", 426 | "for country_code in country_codes.keys():\n", 427 | " print(country_code)\n", 428 | "print()\n", 429 | "\n", 430 | "# Por valor:\n", 431 | "for country in country_codes.values():\n", 432 | " print(country)\n", 433 | "print()\n", 434 | "\n", 435 | "# Por los dos a la vez:\n", 436 | "for country_code, country in country_codes.items():\n", 437 | " print(country_code, country)" 438 | ] 439 | }, 440 | { 441 | "cell_type": "markdown", 442 | "metadata": {}, 443 | "source": [ 444 | "Funciones\n", 445 | "---------\n", 446 | "\n", 447 | "Otra forma muy importante de organizar el flujo de ejecución es encapsulando cierta porción de código en una función reutilizable. Una función en Python utiliza el mismo concepto que una función matemática. Por ejemplo, imaginemos la función matemática:\n", 448 | "\n", 449 | "*suma(x, y) = x + y*\n", 450 | "\n", 451 | "En Python podemos definir la misma función de la siguiente forma:" 452 | ] 453 | }, 454 | { 455 | "cell_type": "code", 456 | "execution_count": 15, 457 | "metadata": {}, 458 | "outputs": [ 459 | { 460 | "name": "stdout", 461 | "output_type": "stream", 462 | "text": [ 463 | "6\n", 464 | "0\n", 465 | "6.0\n" 466 | ] 467 | } 468 | ], 469 | "source": [ 470 | "# La función suma se define mediante la palabra especial 'def' y tiene dos argumentos: 'x' e 'y':\n", 471 | "def suma(x, y):\n", 472 | " # Devolvemos el valor de la suma.\n", 473 | " return x + y\n", 474 | "\n", 475 | "# En este momento, podemos llamarla con cualquier valor:\n", 476 | "print(suma(2, 4))\n", 477 | "print(suma(5, -5))\n", 478 | "print(suma(3.5, 2.5))" 479 | ] 480 | }, 481 | { 482 | "cell_type": "code", 483 | "execution_count": 16, 484 | "metadata": {}, 485 | "outputs": [], 486 | "source": [ 487 | "# Podemos definir una función que no haga nada utilizando la palabra especial 'pass':\n", 488 | "\n", 489 | "def dummy():\n", 490 | " pass\n", 491 | "\n", 492 | "dummy()" 493 | ] 494 | }, 495 | { 496 | "cell_type": "code", 497 | "execution_count": 17, 498 | "metadata": {}, 499 | "outputs": [ 500 | { 501 | "name": "stdout", 502 | "output_type": "stream", 503 | "text": [ 504 | "0 1 1 2 3 5 8 " 505 | ] 506 | } 507 | ], 508 | "source": [ 509 | "# Podríamos volver a definir el trozo de código de la secuencia de Fibonacci como una función:\n", 510 | "\n", 511 | "def fibonacci(n=100):\n", 512 | " a, b = 0, 1\n", 513 | " while a < n:\n", 514 | " print(a, end = \" \")\n", 515 | " a, b = b, a+b\n", 516 | "\n", 517 | "fibonacci(10)" 518 | ] 519 | }, 520 | { 521 | "cell_type": "code", 522 | "execution_count": 18, 523 | "metadata": {}, 524 | "outputs": [ 525 | { 526 | "name": "stdout", 527 | "output_type": "stream", 528 | "text": [ 529 | "0 1 1 2 3 5 8 13 21 34 55 89 " 530 | ] 531 | } 532 | ], 533 | "source": [ 534 | "# En el anterior ejemplo, hemos definido que el argumento n tenga un valor por defecto. Esto es muy útil\n", 535 | "# en los casos en los que utilicemos la función siempre con un mismo valor, queramos dejar constancia de un\n", 536 | "# caso de ejemplo o por defecto. En este caso, podemos ejecutar la función sin pasarle ningún valor:\n", 537 | "fibonacci()" 538 | ] 539 | }, 540 | { 541 | "cell_type": "code", 542 | "execution_count": 19, 543 | "metadata": {}, 544 | "outputs": [ 545 | { 546 | "name": "stdout", 547 | "output_type": "stream", 548 | "text": [ 549 | "9\n", 550 | "8\n" 551 | ] 552 | } 553 | ], 554 | "source": [ 555 | "# Podemos definir parte de los argumentos con valores por defecto y otro sin. \n", 556 | "# Los argumentos sin valor por defecto siempre tienen que estar más a la izquierda en la definición de la función:\n", 557 | "\n", 558 | "def potencia(a, b=2):\n", 559 | " # Por defecto, elevaremos al cuadrado.\n", 560 | " return a**b\n", 561 | "\n", 562 | "print(potencia(3))\n", 563 | "print(potencia(2, 3))" 564 | ] 565 | }, 566 | { 567 | "cell_type": "markdown", 568 | "metadata": {}, 569 | "source": [ 570 | "**Recomendamos la lectura de la [documentación oficial](https://docs.python.org/3/tutorial/controlflow.html)** para acabar de fijar conocimientos." 571 | ] 572 | }, 573 | { 574 | "cell_type": "markdown", 575 | "metadata": {}, 576 | "source": [ 577 | "Leer y escribir desde ficheros\n", 578 | "------------------------------\n", 579 | "\n", 580 | "Una tarea habitual es leer líneas de un fichero o escribir líneas en un fichero. En Python, leer y escribir ficheros se hace a través de la librería *os*. Una librería es un conjunto de código que tiene cierto sentido agrupar para ser usado por otra gente. En nuestro caso, *os* es una librería que agrupa funciones relacionadas con el sistema operativo (**o**perating **s**ystem). Para cargar una librería, utilizaremos la palabra reservada **import**. Más adelante explicaremos algunas particularidades de utilizar e importar librerías. A continuación os explicamos cómo escribir y leer un fichero:" 581 | ] 582 | }, 583 | { 584 | "cell_type": "code", 585 | "execution_count": 20, 586 | "metadata": {}, 587 | "outputs": [], 588 | "source": [ 589 | "# Primero de todo, vamos a escribir en un fichero.\n", 590 | "import os\n", 591 | "\n", 592 | "# Abrimos un fichero de nombre 'a_file.txt' para escritura (de ahí la 'w', 'writing').\n", 593 | "# Lo asignamos a un objeto para manejar el fichero de nombre 'out':\n", 594 | "out = open('a_file.txt', 'w')\n", 595 | "# Vamos a escribir 10 líneas, cada una con un número de 0 a 9.\n", 596 | "for i in range(10):\n", 597 | " # La siguiente línea escribe en el fichero todo lo que pongamos dentro de out.write()\n", 598 | " # En nuestro caso, es un string del tipo '0\\n', '1\\n', etc. Esto lo conseguimos utilizando las wildcards %d y %s.\n", 599 | " # %s representa un string o cadena de caracteres y %d un número entero.\n", 600 | " # Concatenamos en este caso un número con un string que se trata del salto de línea, os.linesep, que equivale en Linux\n", 601 | " # a '\\n':\n", 602 | " out.write(\"Línea %d%s\" % (i, os.linesep))\n", 603 | "\n", 604 | "out.close()" 605 | ] 606 | }, 607 | { 608 | "cell_type": "code", 609 | "execution_count": 21, 610 | "metadata": {}, 611 | "outputs": [ 612 | { 613 | "name": "stdout", 614 | "output_type": "stream", 615 | "text": [ 616 | "Línea 0\n", 617 | "Línea 1\n", 618 | "Línea 2\n", 619 | "Línea 3\n", 620 | "Línea 4\n", 621 | "Línea 5\n", 622 | "Línea 6\n", 623 | "Línea 7\n", 624 | "Línea 8\n", 625 | "Línea 9\n", 626 | "\n", 627 | "Línea 0\n", 628 | "Línea 1\n", 629 | "Línea 2\n", 630 | "Línea 3\n", 631 | "Línea 4\n", 632 | "Línea 5\n", 633 | "Línea 6\n", 634 | "Línea 7\n", 635 | "Línea 8\n", 636 | "Línea 9\n", 637 | "\n", 638 | "Línea 0\n", 639 | "Línea 1\n", 640 | "Línea 2\n", 641 | "Línea 3\n", 642 | "Línea 4\n", 643 | "Línea 5\n", 644 | "Línea 6\n", 645 | "Línea 7\n", 646 | "Línea 8\n", 647 | "Línea 9\n" 648 | ] 649 | } 650 | ], 651 | "source": [ 652 | "# Ahora vamos a leer el fichero que acabamos de escribir de tres formas distintas:\n", 653 | "\n", 654 | "# Primer método\n", 655 | "f = open('a_file.txt')\n", 656 | "for line in f:\n", 657 | " print(line, end = \"\")\n", 658 | "f.close()\n", 659 | "print()\n", 660 | "\n", 661 | "# Segundo método\n", 662 | "f = open('a_file.txt')\n", 663 | "lines = f.readlines()\n", 664 | "for line in lines:\n", 665 | " print(line, end = \"\")\n", 666 | "f.close()\n", 667 | "print()\n", 668 | "\n", 669 | "# Tercer método\n", 670 | "with open('a_file.txt') as f:\n", 671 | " for line in f:\n", 672 | " print(line, end = \"\")" 673 | ] 674 | }, 675 | { 676 | "cell_type": "markdown", 677 | "metadata": {}, 678 | "source": [ 679 | "Organización del código\n", 680 | "------------------------\n", 681 | "\n", 682 | "Un módulo de Python es cualquier fichero con extensión *.py* que esté bajo la ruta del path de Python. El path de Python puede consultarse importando la librería sys:" 683 | ] 684 | }, 685 | { 686 | "cell_type": "code", 687 | "execution_count": 22, 688 | "metadata": {}, 689 | "outputs": [ 690 | { 691 | "name": "stdout", 692 | "output_type": "stream", 693 | "text": [ 694 | "['/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '', '/usr/local/lib/python3.6/dist-packages', '/usr/lib/python3/dist-packages', '/usr/local/lib/python3.6/dist-packages/IPython/extensions', '/home/datasci/.ipython']\n" 695 | ] 696 | } 697 | ], 698 | "source": [ 699 | "import sys\n", 700 | "print(sys.path)" 701 | ] 702 | }, 703 | { 704 | "cell_type": "markdown", 705 | "metadata": {}, 706 | "source": [ 707 | "Por defecto, Python también mira las librerías que se hayan definido en la variable de entorno $PYTHONPATH (esto puede cambiar ligeramente en un [entorno Windows](https://docs.python.org/3/using/cmdline.html)).\n", 708 | "\n", 709 | "Un paquete en Python es cualquier directorio que contenga un fichero especial de nombre *\\_\\_init\\_\\_.py* (este fichero estará vacío la mayoría de veces).\n", 710 | "\n", 711 | "Un módulo puede contener diferentes funciones, variables u objetos. Por ejemplo, definamos un módulo de nombre *prog_datasci.py* que contenga:" 712 | ] 713 | }, 714 | { 715 | "cell_type": "code", 716 | "execution_count": 23, 717 | "metadata": {}, 718 | "outputs": [], 719 | "source": [ 720 | "# prog_datasci.py\n", 721 | "\n", 722 | "PI = 3.14159265\n", 723 | "\n", 724 | "def suma(x, y):\n", 725 | " return x + y\n", 726 | "\n", 727 | "\n", 728 | "def resta(x, y):\n", 729 | " return x - y\n" 730 | ] 731 | }, 732 | { 733 | "cell_type": "markdown", 734 | "metadata": {}, 735 | "source": [ 736 | "Para utilizar desde otro módulo o script estas funciones, deberíamos escribir lo siguiente:" 737 | ] 738 | }, 739 | { 740 | "cell_type": "code", 741 | "execution_count": 24, 742 | "metadata": {}, 743 | "outputs": [], 744 | "source": [ 745 | "from prog_datasci import PI, suma, resta\n", 746 | "\n", 747 | "# Y entonces podríamos utilizarlas normalmente.\n", 748 | "siete = suma(2,5)" 749 | ] 750 | }, 751 | { 752 | "cell_type": "markdown", 753 | "metadata": {}, 754 | "source": [ 755 | "En Python también podemos utilizar la directiva `from prog_datasci import *`, pero su uso está **totalmente desaconsejado**. La razón es que estaríamos importando gran cantidad de código que no utilizaremos (con el consiguiente aumento del uso de la memoria), pero además, podríamos tener colisiones de nombres (funciones que se llamen de la misma forma en diferentes módulos) sin nuestro conocimiento. A no ser que sea imprescindible, no utilizaremos esa directiva e importaremos una a una las librerías y las funciones que vayamos a necesitar.\n", 756 | "\n", 757 | "Podéis aprender más sobre importar librerías y definir vuestros propios módulos [aquí](http://life.bsc.es/pid/brian/python/#/5)." 758 | ] 759 | } 760 | ], 761 | "metadata": { 762 | "kernelspec": { 763 | "display_name": "Python 3", 764 | "language": "python", 765 | "name": "python3" 766 | }, 767 | "language_info": { 768 | "codemirror_mode": { 769 | "name": "ipython", 770 | "version": 3 771 | }, 772 | "file_extension": ".py", 773 | "mimetype": "text/x-python", 774 | "name": "python", 775 | "nbconvert_exporter": "python", 776 | "pygments_lexer": "ipython3", 777 | "version": "3.6.8" 778 | } 779 | }, 780 | "nbformat": 4, 781 | "nbformat_minor": 1 782 | } 783 | -------------------------------------------------------------------------------- /python_1/unit_3/README.md: -------------------------------------------------------------------------------- 1 | # Unit 3 - Flow control tools and functions 2 | 3 | This is the repository of the content for unit 3 (Estructures de control i funcions en Python / Estructuras de control y funciones en Python) of the course: 4 | * 22.401 - Fonaments de Programació 5 | * 22.501 - Fundamentos de Programación 6 | 7 | 8 | -------------------------------------------------------------------------------- /python_1/unit_3/pdf/CAT-prog_datasci_3_apython.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_1/unit_3/pdf/CAT-prog_datasci_3_apython.pdf -------------------------------------------------------------------------------- /python_1/unit_3/pdf/IB-prog_datasci_3_apython.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_1/unit_3/pdf/IB-prog_datasci_3_apython.pdf -------------------------------------------------------------------------------- /python_1/unit_3/prog_datasci.py: -------------------------------------------------------------------------------- 1 | PI = 3.14159265 2 | 3 | def suma(x, y): 4 | return x + y 5 | 6 | 7 | def resta(x, y): 8 | return x - y 9 | -------------------------------------------------------------------------------- /python_1/unit_4/.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # IPython Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # dotenv 79 | .env 80 | 81 | # virtualenv 82 | venv/ 83 | ENV/ 84 | 85 | # Spyder project settings 86 | .spyderproject 87 | 88 | # Rope project settings 89 | .ropeproject 90 | .DS_Store 91 | -------------------------------------------------------------------------------- /python_1/unit_4/CAT-prog_datasci_4_numpy.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "Programació per a *Data Science*\n", 8 | "============================\n", 9 | "\n", 10 | "Unitat 4: Llibreries científiques en Python - NumPy\n", 11 | "-------------------------------------------------\n", 12 | "\n", 13 | "Instruccions d'ús\n", 14 | "-----------------\n", 15 | "\n", 16 | "A continuació es presentaran explicacions i exemples d'ús de la\n", 17 | "llibreria NumPy. Recordeu que podeu anar executant els exemples per\n", 18 | "obtenir-ne els resultats.\n", 19 | "\n", 20 | "Primers passos\n", 21 | "--------------\n", 22 | "\n", 23 | "Importarem la llibreria:" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": 1, 29 | "metadata": { 30 | "attributes": { 31 | "classes": [ 32 | "sourceCode" 33 | ], 34 | "id": "" 35 | } 36 | }, 37 | "outputs": [], 38 | "source": [ 39 | "# A la línia següent, importem NumPy i li donem un nom més curt \n", 40 | "# perquè ens sigui més còmode fer les crides\n", 41 | "import numpy as np" 42 | ] 43 | }, 44 | { 45 | "cell_type": "markdown", 46 | "metadata": {}, 47 | "source": [ 48 | "A NumPy, l'objecte bàsic és una llista multidimensional de\n", 49 | "nombres (normalment) del mateix tipus." 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": 2, 55 | "metadata": { 56 | "attributes": { 57 | "classes": [ 58 | "sourceCode" 59 | ], 60 | "id": "" 61 | } 62 | }, 63 | "outputs": [], 64 | "source": [ 65 | "# Exemple bàsic, un punt a l'espai:\n", 66 | "p = np.array([1, 2, 3])" 67 | ] 68 | }, 69 | { 70 | "cell_type": "markdown", 71 | "metadata": {}, 72 | "source": [ 73 | "A NumPy, a les dimensions se les coneix amb el nom d'eixos (*axes*), i\n", 74 | "al nombre d'eixos, rang (*rank*). *Array* és un àlies per referir-se al\n", 75 | "tipus d'objecte *numpy.ndarray*.\n", 76 | "\n", 77 | "Algunes propietats importants dels _arrays_ són les següents: \n", 78 | "* **ndarray.ndim**: el nombre d'eixos de l'objecte _array_ (matriu).\n", 79 | "* **ndarray.shape**: una tupla de nombres enters indicant la longitud de\n", 80 | "les dimensions de la matriu.\n", 81 | "* **ndarray.size**: el nombre total d'elements de la matriu." 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": 3, 87 | "metadata": { 88 | "attributes": { 89 | "classes": [ 90 | "sourceCode" 91 | ], 92 | "id": "" 93 | } 94 | }, 95 | "outputs": [ 96 | { 97 | "name": "stdout", 98 | "output_type": "stream", 99 | "text": [ 100 | "Array unidimensional:\n", 101 | "[0 1 2 3 4 5]\n", 102 | "Matriu 3x2:\n", 103 | "[[0 1]\n", 104 | " [2 3]\n", 105 | " [4 5]]\n" 106 | ] 107 | } 108 | ], 109 | "source": [ 110 | "# Crearem una matriu bidimensional 3x2 (tres files, dues columnes).\n", 111 | "a = np.arange(3*2) # Creem un array unidimensional de sis elements\n", 112 | "print('Array unidimensional:')\n", 113 | "print(a)\n", 114 | "a = a.reshape(3,2) # Li donem \"forma\" de matrix 3x2.\n", 115 | "print('Matriu 3x2:')\n", 116 | "print(a)" 117 | ] 118 | }, 119 | { 120 | "cell_type": "code", 121 | "execution_count": 4, 122 | "metadata": { 123 | "attributes": { 124 | "classes": [ 125 | "sourceCode" 126 | ], 127 | "id": "" 128 | } 129 | }, 130 | "outputs": [ 131 | { 132 | "data": { 133 | "text/plain": [ 134 | "2" 135 | ] 136 | }, 137 | "execution_count": 4, 138 | "metadata": {}, 139 | "output_type": "execute_result" 140 | } 141 | ], 142 | "source": [ 143 | "# La dimensió és 2.\n", 144 | "a.ndim" 145 | ] 146 | }, 147 | { 148 | "cell_type": "code", 149 | "execution_count": 5, 150 | "metadata": { 151 | "attributes": { 152 | "classes": [ 153 | "sourceCode" 154 | ], 155 | "id": "" 156 | } 157 | }, 158 | "outputs": [ 159 | { 160 | "data": { 161 | "text/plain": [ 162 | "(3, 2)" 163 | ] 164 | }, 165 | "execution_count": 5, 166 | "metadata": {}, 167 | "output_type": "execute_result" 168 | } 169 | ], 170 | "source": [ 171 | "# Longitud de les dimensions.\n", 172 | "a.shape" 173 | ] 174 | }, 175 | { 176 | "cell_type": "code", 177 | "execution_count": 6, 178 | "metadata": { 179 | "attributes": { 180 | "classes": [ 181 | "sourceCode" 182 | ], 183 | "id": "" 184 | } 185 | }, 186 | "outputs": [ 187 | { 188 | "data": { 189 | "text/plain": [ 190 | "6" 191 | ] 192 | }, 193 | "execution_count": 6, 194 | "metadata": {}, 195 | "output_type": "execute_result" 196 | } 197 | ], 198 | "source": [ 199 | "# El nombre total d'elements:\n", 200 | "a.size" 201 | ] 202 | }, 203 | { 204 | "cell_type": "markdown", 205 | "metadata": {}, 206 | "source": [ 207 | "A l'hora de crear _arrays_, tenim diferents opcions:" 208 | ] 209 | }, 210 | { 211 | "cell_type": "code", 212 | "execution_count": 7, 213 | "metadata": { 214 | "attributes": { 215 | "classes": [ 216 | "sourceCode" 217 | ], 218 | "id": "" 219 | } 220 | }, 221 | "outputs": [ 222 | { 223 | "name": "stdout", 224 | "output_type": "stream", 225 | "text": [ 226 | "[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n" 227 | ] 228 | } 229 | ], 230 | "source": [ 231 | "# Creem un array (vector) de deu elements:\n", 232 | "z = np.zeros(10)\n", 233 | "print(z)" 234 | ] 235 | }, 236 | { 237 | "cell_type": "code", 238 | "execution_count": 8, 239 | "metadata": { 240 | "attributes": { 241 | "classes": [ 242 | "sourceCode" 243 | ], 244 | "id": "" 245 | } 246 | }, 247 | "outputs": [ 248 | { 249 | "name": "stdout", 250 | "output_type": "stream", 251 | "text": [ 252 | "[0. 0. 0. 0. 5. 0. 0. 0. 0. 0.1]\n" 253 | ] 254 | } 255 | ], 256 | "source": [ 257 | "# Podem canviar qualsevol dels valors d'aquest vector accedint a la seva posició:\n", 258 | "z[4] = 5.0\n", 259 | "z[-1] = 0.1\n", 260 | "print(z)" 261 | ] 262 | }, 263 | { 264 | "cell_type": "code", 265 | "execution_count": 9, 266 | "metadata": { 267 | "attributes": { 268 | "classes": [ 269 | "sourceCode" 270 | ], 271 | "id": "" 272 | } 273 | }, 274 | "outputs": [ 275 | { 276 | "name": "stdout", 277 | "output_type": "stream", 278 | "text": [ 279 | "[10 11 12 13 14 15 16 17 18 19]\n" 280 | ] 281 | } 282 | ], 283 | "source": [ 284 | "# La funció 'arange' ens permet definir diferents opcions, com el punt d'inici i el de final:\n", 285 | "a = np.arange(10,20)\n", 286 | "print(a)" 287 | ] 288 | }, 289 | { 290 | "cell_type": "code", 291 | "execution_count": 10, 292 | "metadata": { 293 | "attributes": { 294 | "classes": [ 295 | "sourceCode" 296 | ], 297 | "id": "" 298 | } 299 | }, 300 | "outputs": [ 301 | { 302 | "name": "stdout", 303 | "output_type": "stream", 304 | "text": [ 305 | "[10 12 14 16 18]\n" 306 | ] 307 | } 308 | ], 309 | "source": [ 310 | "# L'últim argument ens permet utilitzar un pas de 2:\n", 311 | "a = np.arange(10,20,2)\n", 312 | "print(a)" 313 | ] 314 | }, 315 | { 316 | "cell_type": "code", 317 | "execution_count": 11, 318 | "metadata": { 319 | "attributes": { 320 | "classes": [ 321 | "sourceCode" 322 | ], 323 | "id": "" 324 | } 325 | }, 326 | "outputs": [ 327 | { 328 | "name": "stdout", 329 | "output_type": "stream", 330 | "text": [ 331 | "[[1 2 3]\n", 332 | " [4 5 6]]\n" 333 | ] 334 | } 335 | ], 336 | "source": [ 337 | "# Podem crear arrays des de llistes de Python de diverses dimensions:\n", 338 | "a = np.array([[1, 2, 3], [4, 5, 6]])\n", 339 | "print(a)" 340 | ] 341 | }, 342 | { 343 | "cell_type": "markdown", 344 | "metadata": {}, 345 | "source": [ 346 | "Operacions amb matrius\n", 347 | "----------------------\n", 348 | "\n", 349 | "NumPy implementa totes les operacions habituals amb matrius." 350 | ] 351 | }, 352 | { 353 | "cell_type": "code", 354 | "execution_count": 12, 355 | "metadata": { 356 | "attributes": { 357 | "classes": [ 358 | "sourceCode" 359 | ], 360 | "id": "" 361 | } 362 | }, 363 | "outputs": [], 364 | "source": [ 365 | "A = np.array([[1,0], [0,1]])\n", 366 | "B = np.array([[1,2], [3,4]])" 367 | ] 368 | }, 369 | { 370 | "cell_type": "code", 371 | "execution_count": 13, 372 | "metadata": { 373 | "attributes": { 374 | "classes": [ 375 | "sourceCode" 376 | ], 377 | "id": "" 378 | } 379 | }, 380 | "outputs": [ 381 | { 382 | "name": "stdout", 383 | "output_type": "stream", 384 | "text": [ 385 | "[[2 2]\n", 386 | " [3 5]]\n" 387 | ] 388 | } 389 | ], 390 | "source": [ 391 | "# Suma de matrius\n", 392 | "print(A+B)" 393 | ] 394 | }, 395 | { 396 | "cell_type": "code", 397 | "execution_count": 14, 398 | "metadata": { 399 | "attributes": { 400 | "classes": [ 401 | "sourceCode" 402 | ], 403 | "id": "" 404 | } 405 | }, 406 | "outputs": [ 407 | { 408 | "name": "stdout", 409 | "output_type": "stream", 410 | "text": [ 411 | "[[ 0 -2]\n", 412 | " [-3 -3]]\n" 413 | ] 414 | } 415 | ], 416 | "source": [ 417 | "# Resta de matrius\n", 418 | "print(A-B)" 419 | ] 420 | }, 421 | { 422 | "cell_type": "code", 423 | "execution_count": 15, 424 | "metadata": { 425 | "attributes": { 426 | "classes": [ 427 | "sourceCode" 428 | ], 429 | "id": "" 430 | } 431 | }, 432 | "outputs": [ 433 | { 434 | "name": "stdout", 435 | "output_type": "stream", 436 | "text": [ 437 | "[[1 0]\n", 438 | " [0 4]]\n" 439 | ] 440 | } 441 | ], 442 | "source": [ 443 | "# Multiplicació element per element\n", 444 | "print(A*B)" 445 | ] 446 | }, 447 | { 448 | "cell_type": "code", 449 | "execution_count": 16, 450 | "metadata": { 451 | "attributes": { 452 | "classes": [ 453 | "sourceCode" 454 | ], 455 | "id": "" 456 | } 457 | }, 458 | "outputs": [ 459 | { 460 | "name": "stdout", 461 | "output_type": "stream", 462 | "text": [ 463 | "[[1 2]\n", 464 | " [3 4]]\n" 465 | ] 466 | } 467 | ], 468 | "source": [ 469 | "# Multiplicació de matrius\n", 470 | "print(A.dot(B))" 471 | ] 472 | }, 473 | { 474 | "cell_type": "code", 475 | "execution_count": 17, 476 | "metadata": { 477 | "attributes": { 478 | "classes": [ 479 | "sourceCode" 480 | ], 481 | "id": "" 482 | } 483 | }, 484 | "outputs": [ 485 | { 486 | "name": "stdout", 487 | "output_type": "stream", 488 | "text": [ 489 | "[[ 1 4]\n", 490 | " [ 9 16]]\n" 491 | ] 492 | } 493 | ], 494 | "source": [ 495 | "# Potència\n", 496 | "print(B**2)" 497 | ] 498 | }, 499 | { 500 | "cell_type": "markdown", 501 | "metadata": {}, 502 | "source": [ 503 | "*Slicing* i iteració\n", 504 | "--------------------\n", 505 | "\n", 506 | "Els _arrays_ en NumPy suporten la tècnica de *slicing* de Python:" 507 | ] 508 | }, 509 | { 510 | "cell_type": "code", 511 | "execution_count": 18, 512 | "metadata": { 513 | "attributes": { 514 | "classes": [ 515 | "sourceCode" 516 | ], 517 | "id": "" 518 | } 519 | }, 520 | "outputs": [ 521 | { 522 | "name": "stdout", 523 | "output_type": "stream", 524 | "text": [ 525 | "[2 3 4]\n" 526 | ] 527 | } 528 | ], 529 | "source": [ 530 | "# Definim un array de 0 a 9.\n", 531 | "a = np.arange(10)\n", 532 | "# Obtenim els 5-2 elements des de la posició 3 de l'array (els índexs comencen a 0).\n", 533 | "print(a[2:5])" 534 | ] 535 | }, 536 | { 537 | "cell_type": "code", 538 | "execution_count": 19, 539 | "metadata": { 540 | "attributes": { 541 | "classes": [ 542 | "sourceCode" 543 | ], 544 | "id": "" 545 | } 546 | }, 547 | "outputs": [ 548 | { 549 | "data": { 550 | "text/plain": [ 551 | "array([2, 3, 4, 5, 6, 7, 8, 9])" 552 | ] 553 | }, 554 | "execution_count": 19, 555 | "metadata": {}, 556 | "output_type": "execute_result" 557 | } 558 | ], 559 | "source": [ 560 | "# Tots els elements a partir de la tercera posició:\n", 561 | "a[2:]" 562 | ] 563 | }, 564 | { 565 | "cell_type": "code", 566 | "execution_count": 20, 567 | "metadata": { 568 | "attributes": { 569 | "classes": [ 570 | "sourceCode" 571 | ], 572 | "id": "" 573 | } 574 | }, 575 | "outputs": [ 576 | { 577 | "name": "stdout", 578 | "output_type": "stream", 579 | "text": [ 580 | "0\n", 581 | "1\n", 582 | "2\n", 583 | "3\n", 584 | "4\n", 585 | "5\n", 586 | "6\n", 587 | "7\n", 588 | "8\n", 589 | "9\n" 590 | ] 591 | } 592 | ], 593 | "source": [ 594 | "# Podem iterar per cada element de l'array:\n", 595 | "for i in a:\n", 596 | " print(i)" 597 | ] 598 | }, 599 | { 600 | "cell_type": "code", 601 | "execution_count": 21, 602 | "metadata": { 603 | "attributes": { 604 | "classes": [ 605 | "sourceCode" 606 | ], 607 | "id": "" 608 | } 609 | }, 610 | "outputs": [ 611 | { 612 | "name": "stdout", 613 | "output_type": "stream", 614 | "text": [ 615 | "[[ 0 1 2]\n", 616 | " [ 3 4 5]\n", 617 | " [ 6 7 8]\n", 618 | " [ 9 10 11]\n", 619 | " [12 13 14]\n", 620 | " [15 16 17]]\n" 621 | ] 622 | } 623 | ], 624 | "source": [ 625 | "# Ara definim un array multidimensional.\n", 626 | "A = np.arange(18).reshape(6,3)\n", 627 | "print(A)" 628 | ] 629 | }, 630 | { 631 | "cell_type": "code", 632 | "execution_count": 22, 633 | "metadata": { 634 | "attributes": { 635 | "classes": [ 636 | "sourceCode" 637 | ], 638 | "id": "" 639 | } 640 | }, 641 | "outputs": [ 642 | { 643 | "name": "stdout", 644 | "output_type": "stream", 645 | "text": [ 646 | "[[ 0 1 2]\n", 647 | " [ 3 4 5]\n", 648 | " [ 6 7 8]\n", 649 | " [ 9 10 11]\n", 650 | " [12 13 14]]\n" 651 | ] 652 | } 653 | ], 654 | "source": [ 655 | "# Obtenim fins a la cinquena fila.\n", 656 | "print(A[:5])" 657 | ] 658 | }, 659 | { 660 | "cell_type": "code", 661 | "execution_count": 23, 662 | "metadata": { 663 | "attributes": { 664 | "classes": [ 665 | "sourceCode" 666 | ], 667 | "id": "" 668 | } 669 | }, 670 | "outputs": [ 671 | { 672 | "name": "stdout", 673 | "output_type": "stream", 674 | "text": [ 675 | "[[0 0 0]\n", 676 | " [0 0 0]\n", 677 | " [0 0 0]\n", 678 | " [0 0 0]\n", 679 | " [0 0 0]\n", 680 | " [0 0 0]]\n" 681 | ] 682 | } 683 | ], 684 | "source": [ 685 | "# Igualem tots els elements a 0 (l'operador ... afegeix tots els : necessaris).\n", 686 | "A[...] = 0\n", 687 | "print(A)" 688 | ] 689 | }, 690 | { 691 | "cell_type": "markdown", 692 | "metadata": {}, 693 | "source": [ 694 | "Exemple: el joc de la vida de Conway\n", 695 | "------------------------------------\n", 696 | "\n", 697 | "El joc de la vida és un exemple clàssic d'autòmat cel·lular creat el\n", 698 | "1970 pel famós matemàtic John H. Conway. Al problema clàssic, es\n", 699 | "representen en una matriu bidimensional cèl·lules que viuran o moriran\n", 700 | "depenent del nombre de veïns en un determinat pas de la simulació. Cada\n", 701 | "cèl·lula té vuit veïns (les caselles adjacents en un tauler bidimensional)\n", 702 | "i pot estar viva (1) o morta (0). Les regles clàssiques entre transició\n", 703 | "vida/mort són les següents:\n", 704 | "\n", 705 | "* Una cèl·lula morta amb exactament tres cèl·lules veïnes vives al torn següent estarà viva.\n", 706 | "* Una cèl·lula viva amb dues o tres cèl·lules veïnes vives segueix viva, en un altre cas mor o roman morta (solitud en cas d'un número més petit que 2, superpoblació si és major a 3).\n", 707 | "\n", 708 | "Aquest problema (o joc) té moltes variants depenent de les condicions\n", 709 | "inicials, si el tauler (o món) té vores o no, o si bé les regles de vida\n", 710 | "o mort són alterades.\n", 711 | "\n", 712 | "A continuació teniu un exemple del joc clàssic implementat a NumPy:" 713 | ] 714 | }, 715 | { 716 | "cell_type": "code", 717 | "execution_count": 24, 718 | "metadata": {}, 719 | "outputs": [ 720 | { 721 | "name": "stdout", 722 | "output_type": "stream", 723 | "text": [ 724 | "[[0 0 0 0 0 0 0 0 0 0]\n", 725 | " [0 0 0 0 0 0 0 0 0 0]\n", 726 | " [0 0 0 0 0 0 0 0 0 0]\n", 727 | " [0 0 0 0 0 0 1 1 0 0]\n", 728 | " [0 0 0 0 0 0 0 1 1 0]\n", 729 | " [0 0 0 0 1 1 0 0 0 0]\n", 730 | " [0 0 1 1 1 0 0 0 0 0]\n", 731 | " [0 0 0 1 1 0 0 0 0 0]\n", 732 | " [0 0 1 0 0 0 0 0 0 0]\n", 733 | " [0 0 0 0 0 0 0 0 0 0]]\n" 734 | ] 735 | } 736 | ], 737 | "source": [ 738 | "# Autor: Nicolas Rougier\n", 739 | "# Font: http://www.labri.fr/perso/nrougier/teaching/numpy.100/\n", 740 | "\n", 741 | "SIZE = 10\n", 742 | "STEPS = 10\n", 743 | "\n", 744 | "def iterate(Z):\n", 745 | " # Comptem veïns:\n", 746 | " N = (Z[0:-2,0:-2] + Z[0:-2,1:-1] + Z[0:-2,2:] +\n", 747 | " Z[1:-1,0:-2] + Z[1:-1,2:] +\n", 748 | " Z[2: ,0:-2] + Z[2: ,1:-1] + Z[2: ,2:])\n", 749 | "\n", 750 | " # Apliquem les regles:\n", 751 | " birth = (N==3) & (Z[1:-1,1:-1]==0)\n", 752 | " survive = ((N==2) | (N==3)) & (Z[1:-1,1:-1]==1)\n", 753 | " Z[...] = 0\n", 754 | " Z[1:-1,1:-1][birth | survive] = 1\n", 755 | " return Z\n", 756 | "\n", 757 | "#Creem un tauler amb cèl·lules vives o mortes de manera aleatòria.\n", 758 | "Z = np.random.randint(0,2,(SIZE, SIZE))\n", 759 | "# Simulem durant els passos indicats:\n", 760 | "for i in range(STEPS):\n", 761 | " Z = iterate(Z)\n", 762 | "# Mostrem el tauler en el pas final:\n", 763 | "print(Z)" 764 | ] 765 | } 766 | ], 767 | "metadata": { 768 | "kernelspec": { 769 | "display_name": "Python 3", 770 | "language": "python", 771 | "name": "python3" 772 | }, 773 | "language_info": { 774 | "codemirror_mode": { 775 | "name": "ipython", 776 | "version": 3 777 | }, 778 | "file_extension": ".py", 779 | "mimetype": "text/x-python", 780 | "name": "python", 781 | "nbconvert_exporter": "python", 782 | "pygments_lexer": "ipython3", 783 | "version": "3.6.8" 784 | } 785 | }, 786 | "nbformat": 4, 787 | "nbformat_minor": 1 788 | } 789 | -------------------------------------------------------------------------------- /python_1/unit_4/IB-prog_datasci_4_numpy.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Programación para *Data Science*" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "Unidad 4: Librerías científicas en Python - NumPy\n", 15 | "-------------------------------------------------\n", 16 | "\n", 17 | "### Instrucciones de uso\n", 18 | "A continuación se presentarán explicaciones y ejemplos de uso de la librería NumPy. Recordad que podéis ir ejecutando los ejemplos para obtener sus resultados." 19 | ] 20 | }, 21 | { 22 | "cell_type": "markdown", 23 | "metadata": {}, 24 | "source": [ 25 | "### Primeros pasos\n", 26 | "Vamos a importar la librería:" 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": 1, 32 | "metadata": {}, 33 | "outputs": [], 34 | "source": [ 35 | "# En la siguiente línea, importamos NumPy y le damos un nombre más corto \n", 36 | "# para que nos sea más cómodo hacer las llamadas.\n", 37 | "import numpy as np" 38 | ] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "metadata": {}, 43 | "source": [ 44 | "En NumPy, el objeto básico se trata de una lista multidimensional de números (normalmente) del mismo tipo." 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": 2, 50 | "metadata": {}, 51 | "outputs": [], 52 | "source": [ 53 | "# Ejemplo básico, un punto en el espacio:\n", 54 | "p = np.array([1, 2, 3])" 55 | ] 56 | }, 57 | { 58 | "cell_type": "markdown", 59 | "metadata": {}, 60 | "source": [ 61 | "En NumPy, a las dimensiones se les conoce con el nombre de ejes (*axes*) y al número de ejes, rango (*rank*). *array* es un alias para referirse al tipo de objeto *numpy.ndarray*.\n", 62 | "\n", 63 | "Algunas propiedades importantes de los _arrays_ son las siguientes:\n", 64 | "* **ndarray.ndim**: el número de ejes del objeto _array_ (matriz)\n", 65 | "* **ndarray.shape**: una tupla de números enteros indicando la longitud de las dimensiones de la matriz\n", 66 | "* **ndarray.size**: el número total de elementos de la matriz" 67 | ] 68 | }, 69 | { 70 | "cell_type": "code", 71 | "execution_count": 3, 72 | "metadata": {}, 73 | "outputs": [ 74 | { 75 | "name": "stdout", 76 | "output_type": "stream", 77 | "text": [ 78 | "Array unidimensional:\n", 79 | "[0 1 2 3 4 5]\n", 80 | "Matriz 3x2:\n", 81 | "[[0 1]\n", 82 | " [2 3]\n", 83 | " [4 5]]\n" 84 | ] 85 | } 86 | ], 87 | "source": [ 88 | "# Vamos a crear una matriz bidimensional 3x2 (tres filas, dos columnas).\n", 89 | "a = np.arange(3*2) # Creamos un array unidimensional de 6 elementos.\n", 90 | "print('Array unidimensional:')\n", 91 | "print(a)\n", 92 | "a = a.reshape(3,2) # Le damos \"forma\" de matriz 3x2.\n", 93 | "print('Matriz 3x2:')\n", 94 | "print(a)" 95 | ] 96 | }, 97 | { 98 | "cell_type": "code", 99 | "execution_count": 4, 100 | "metadata": {}, 101 | "outputs": [ 102 | { 103 | "data": { 104 | "text/plain": [ 105 | "2" 106 | ] 107 | }, 108 | "execution_count": 4, 109 | "metadata": {}, 110 | "output_type": "execute_result" 111 | } 112 | ], 113 | "source": [ 114 | "# La dimensión es 2.\n", 115 | "a.ndim" 116 | ] 117 | }, 118 | { 119 | "cell_type": "code", 120 | "execution_count": 5, 121 | "metadata": {}, 122 | "outputs": [ 123 | { 124 | "data": { 125 | "text/plain": [ 126 | "(3, 2)" 127 | ] 128 | }, 129 | "execution_count": 5, 130 | "metadata": {}, 131 | "output_type": "execute_result" 132 | } 133 | ], 134 | "source": [ 135 | "# Longitud de las dimensiones\n", 136 | "a.shape" 137 | ] 138 | }, 139 | { 140 | "cell_type": "code", 141 | "execution_count": 6, 142 | "metadata": {}, 143 | "outputs": [ 144 | { 145 | "data": { 146 | "text/plain": [ 147 | "6" 148 | ] 149 | }, 150 | "execution_count": 6, 151 | "metadata": {}, 152 | "output_type": "execute_result" 153 | } 154 | ], 155 | "source": [ 156 | "# El número total de elementos\n", 157 | "a.size" 158 | ] 159 | }, 160 | { 161 | "cell_type": "markdown", 162 | "metadata": {}, 163 | "source": [ 164 | "A la hora de crear arrays, tenemos diferentes opciones:" 165 | ] 166 | }, 167 | { 168 | "cell_type": "code", 169 | "execution_count": 7, 170 | "metadata": {}, 171 | "outputs": [ 172 | { 173 | "name": "stdout", 174 | "output_type": "stream", 175 | "text": [ 176 | "[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n" 177 | ] 178 | } 179 | ], 180 | "source": [ 181 | "# Creamos un array (vector) de diez elementos:\n", 182 | "z = np.zeros(10)\n", 183 | "print(z)" 184 | ] 185 | }, 186 | { 187 | "cell_type": "code", 188 | "execution_count": 8, 189 | "metadata": {}, 190 | "outputs": [ 191 | { 192 | "name": "stdout", 193 | "output_type": "stream", 194 | "text": [ 195 | "[0. 0. 0. 0. 5. 0. 0. 0. 0. 0.1]\n" 196 | ] 197 | } 198 | ], 199 | "source": [ 200 | "# Podemos cambiar cualquiera de los valores de este vector accediendo a su posición:\n", 201 | "z[4] = 5.0\n", 202 | "z[-1] = 0.1\n", 203 | "print(z)" 204 | ] 205 | }, 206 | { 207 | "cell_type": "code", 208 | "execution_count": 9, 209 | "metadata": {}, 210 | "outputs": [ 211 | { 212 | "name": "stdout", 213 | "output_type": "stream", 214 | "text": [ 215 | "[10 11 12 13 14 15 16 17 18 19]\n" 216 | ] 217 | } 218 | ], 219 | "source": [ 220 | "# La función arange nos permite definir diferentes opciones, como el punto de inicio y el de fin:\n", 221 | "a = np.arange(10,20)\n", 222 | "print(a)" 223 | ] 224 | }, 225 | { 226 | "cell_type": "code", 227 | "execution_count": 10, 228 | "metadata": {}, 229 | "outputs": [ 230 | { 231 | "name": "stdout", 232 | "output_type": "stream", 233 | "text": [ 234 | "[10 12 14 16 18]\n" 235 | ] 236 | } 237 | ], 238 | "source": [ 239 | "# El último argumento nos permite utilizar un paso de 2:\n", 240 | "a = np.arange(10,20,2)\n", 241 | "print(a)" 242 | ] 243 | }, 244 | { 245 | "cell_type": "code", 246 | "execution_count": 11, 247 | "metadata": {}, 248 | "outputs": [ 249 | { 250 | "name": "stdout", 251 | "output_type": "stream", 252 | "text": [ 253 | "[[1 2 3]\n", 254 | " [4 5 6]]\n" 255 | ] 256 | } 257 | ], 258 | "source": [ 259 | "# Podemos crear arrays desde listas de Python de varias dimensiones:\n", 260 | "a = np.array([[1, 2, 3], [4, 5, 6]])\n", 261 | "print(a)" 262 | ] 263 | }, 264 | { 265 | "cell_type": "markdown", 266 | "metadata": {}, 267 | "source": [ 268 | "### Operaciones con matrices\n", 269 | "NumPy implementa todas las operaciones habituales con matrices." 270 | ] 271 | }, 272 | { 273 | "cell_type": "code", 274 | "execution_count": 12, 275 | "metadata": {}, 276 | "outputs": [], 277 | "source": [ 278 | "A = np.array([[1,0], [0,1]])\n", 279 | "B = np.array([[1,2], [3,4]])" 280 | ] 281 | }, 282 | { 283 | "cell_type": "code", 284 | "execution_count": 13, 285 | "metadata": {}, 286 | "outputs": [ 287 | { 288 | "name": "stdout", 289 | "output_type": "stream", 290 | "text": [ 291 | "[[2 2]\n", 292 | " [3 5]]\n" 293 | ] 294 | } 295 | ], 296 | "source": [ 297 | "# Suma de matrices\n", 298 | "print(A+B)" 299 | ] 300 | }, 301 | { 302 | "cell_type": "code", 303 | "execution_count": 14, 304 | "metadata": {}, 305 | "outputs": [ 306 | { 307 | "name": "stdout", 308 | "output_type": "stream", 309 | "text": [ 310 | "[[ 0 -2]\n", 311 | " [-3 -3]]\n" 312 | ] 313 | } 314 | ], 315 | "source": [ 316 | "# Resta de matrices\n", 317 | "print(A-B)" 318 | ] 319 | }, 320 | { 321 | "cell_type": "code", 322 | "execution_count": 15, 323 | "metadata": {}, 324 | "outputs": [ 325 | { 326 | "name": "stdout", 327 | "output_type": "stream", 328 | "text": [ 329 | "[[1 0]\n", 330 | " [0 4]]\n" 331 | ] 332 | } 333 | ], 334 | "source": [ 335 | "# Multiplicación elemento por elemento\n", 336 | "print(A*B)" 337 | ] 338 | }, 339 | { 340 | "cell_type": "code", 341 | "execution_count": 16, 342 | "metadata": {}, 343 | "outputs": [ 344 | { 345 | "name": "stdout", 346 | "output_type": "stream", 347 | "text": [ 348 | "[[1 2]\n", 349 | " [3 4]]\n" 350 | ] 351 | } 352 | ], 353 | "source": [ 354 | "# Multiplicación de matrices\n", 355 | "print(A.dot(B))" 356 | ] 357 | }, 358 | { 359 | "cell_type": "code", 360 | "execution_count": 17, 361 | "metadata": {}, 362 | "outputs": [ 363 | { 364 | "name": "stdout", 365 | "output_type": "stream", 366 | "text": [ 367 | "[[ 1 4]\n", 368 | " [ 9 16]]\n" 369 | ] 370 | } 371 | ], 372 | "source": [ 373 | "# Potencia\n", 374 | "print(B**2)" 375 | ] 376 | }, 377 | { 378 | "cell_type": "markdown", 379 | "metadata": {}, 380 | "source": [ 381 | "### *Slicing* e iteración\n", 382 | "Los _arrays_ en NumPy soportan la técnica de *slicing* de Python:\n" 383 | ] 384 | }, 385 | { 386 | "cell_type": "code", 387 | "execution_count": 18, 388 | "metadata": {}, 389 | "outputs": [ 390 | { 391 | "name": "stdout", 392 | "output_type": "stream", 393 | "text": [ 394 | "[2 3 4]\n" 395 | ] 396 | } 397 | ], 398 | "source": [ 399 | "# Definimos un array de 0 a 9.\n", 400 | "a = np.arange(10)\n", 401 | "# Obtenemos los 5-2 elementos desde la posición 3 del array (los índices empiezan en 0).\n", 402 | "print(a[2:5])" 403 | ] 404 | }, 405 | { 406 | "cell_type": "code", 407 | "execution_count": 19, 408 | "metadata": {}, 409 | "outputs": [ 410 | { 411 | "data": { 412 | "text/plain": [ 413 | "array([2, 3, 4, 5, 6, 7, 8, 9])" 414 | ] 415 | }, 416 | "execution_count": 19, 417 | "metadata": {}, 418 | "output_type": "execute_result" 419 | } 420 | ], 421 | "source": [ 422 | "# Todos los elementos a partir de la tercera posición\n", 423 | "a[2:]" 424 | ] 425 | }, 426 | { 427 | "cell_type": "code", 428 | "execution_count": 20, 429 | "metadata": {}, 430 | "outputs": [ 431 | { 432 | "name": "stdout", 433 | "output_type": "stream", 434 | "text": [ 435 | "0\n", 436 | "1\n", 437 | "2\n", 438 | "3\n", 439 | "4\n", 440 | "5\n", 441 | "6\n", 442 | "7\n", 443 | "8\n", 444 | "9\n" 445 | ] 446 | } 447 | ], 448 | "source": [ 449 | "# Podemos iterar por cada elemento del array:\n", 450 | "for i in a:\n", 451 | " print(i)" 452 | ] 453 | }, 454 | { 455 | "cell_type": "code", 456 | "execution_count": 21, 457 | "metadata": {}, 458 | "outputs": [ 459 | { 460 | "name": "stdout", 461 | "output_type": "stream", 462 | "text": [ 463 | "[[ 0 1 2]\n", 464 | " [ 3 4 5]\n", 465 | " [ 6 7 8]\n", 466 | " [ 9 10 11]\n", 467 | " [12 13 14]\n", 468 | " [15 16 17]]\n" 469 | ] 470 | } 471 | ], 472 | "source": [ 473 | "# Definamos ahora un array multidimensional.\n", 474 | "A = np.arange(18).reshape(6,3)\n", 475 | "print(A)" 476 | ] 477 | }, 478 | { 479 | "cell_type": "code", 480 | "execution_count": 22, 481 | "metadata": {}, 482 | "outputs": [ 483 | { 484 | "name": "stdout", 485 | "output_type": "stream", 486 | "text": [ 487 | "[[ 0 1 2]\n", 488 | " [ 3 4 5]\n", 489 | " [ 6 7 8]\n", 490 | " [ 9 10 11]\n", 491 | " [12 13 14]]\n" 492 | ] 493 | } 494 | ], 495 | "source": [ 496 | "# Obtenemos hasta la quinta fila\n", 497 | "print(A[:5])" 498 | ] 499 | }, 500 | { 501 | "cell_type": "code", 502 | "execution_count": 23, 503 | "metadata": {}, 504 | "outputs": [ 505 | { 506 | "name": "stdout", 507 | "output_type": "stream", 508 | "text": [ 509 | "[[0 0 0]\n", 510 | " [0 0 0]\n", 511 | " [0 0 0]\n", 512 | " [0 0 0]\n", 513 | " [0 0 0]\n", 514 | " [0 0 0]]\n" 515 | ] 516 | } 517 | ], 518 | "source": [ 519 | "# Igualamos todos los elementos a 0 (el operador ... añade todos los : necesarios).\n", 520 | "A[...] = 0\n", 521 | "print(A)" 522 | ] 523 | }, 524 | { 525 | "cell_type": "markdown", 526 | "metadata": {}, 527 | "source": [ 528 | "### Ejemplo: El juego de la vida de Conway\n", 529 | "El juego de la vida es un ejemplo clásico de autómata celular creado en 1970 por el famoso matemático John H. Conway. \n", 530 | "En el problema clásico, se representan en una matriz bidimensional células que vivirán o morirán dependiendo del número de vecinos en un determinado paso de la simulación. Cada célula tiene 8 vecinos (las casillas adyacentes en un tablero bidimensional) y puede estar viva (1) o muerta (0). Las reglas clásicas entre transición vida/muerte son las siguientes:\n", 531 | "\n", 532 | "* Una célula muerta con exactamente 3 células vecinas vivas al turno siguiente estará viva.\n", 533 | "* Una célula viva con 2 o 3 células vecinas vivas sigue viva. Si no es el caso, muere o permanece muerta (soledad en caso de un número menor a 2, superpoblación si es mayor a 3).\n", 534 | "\n", 535 | "Este problema (o juego) tiene muchas variantes dependiendo de las condiciones iniciales, si el tablero (o mundo) tiene bordes o no, o si bien las reglas de vida o muerte son alteradas.\n", 536 | "\n", 537 | "A continuación tenéis un ejemplo del juego clásico implementado en NumPy:" 538 | ] 539 | }, 540 | { 541 | "cell_type": "code", 542 | "execution_count": 24, 543 | "metadata": {}, 544 | "outputs": [ 545 | { 546 | "name": "stdout", 547 | "output_type": "stream", 548 | "text": [ 549 | "[[0 0 0 0 0 0 0 0 0 0]\n", 550 | " [0 0 0 0 0 0 0 0 0 0]\n", 551 | " [0 0 0 0 0 0 0 0 0 0]\n", 552 | " [0 0 0 0 0 0 0 0 0 0]\n", 553 | " [0 0 0 0 0 0 0 0 0 0]\n", 554 | " [0 0 0 0 0 0 0 0 0 0]\n", 555 | " [0 0 0 0 0 0 0 0 0 0]\n", 556 | " [0 0 0 0 0 0 0 0 0 0]\n", 557 | " [0 0 0 0 0 0 0 0 0 0]\n", 558 | " [0 0 0 0 0 0 0 0 0 0]]\n" 559 | ] 560 | } 561 | ], 562 | "source": [ 563 | "# Autor: Nicolas Rougier\n", 564 | "# Fuente: http://www.labri.fr/perso/nrougier/teaching/numpy.100/\n", 565 | "\n", 566 | "SIZE = 10\n", 567 | "STEPS = 10\n", 568 | "\n", 569 | "def iterate(Z):\n", 570 | " # Count neighbours\n", 571 | " N = (Z[0:-2,0:-2] + Z[0:-2,1:-1] + Z[0:-2,2:] +\n", 572 | " Z[1:-1,0:-2] + Z[1:-1,2:] +\n", 573 | " Z[2: ,0:-2] + Z[2: ,1:-1] + Z[2: ,2:])\n", 574 | "\n", 575 | " # Apply rules\n", 576 | " birth = (N==3) & (Z[1:-1,1:-1]==0)\n", 577 | " survive = ((N==2) | (N==3)) & (Z[1:-1,1:-1]==1)\n", 578 | " Z[...] = 0\n", 579 | " Z[1:-1,1:-1][birth | survive] = 1\n", 580 | " return Z\n", 581 | "\n", 582 | "# Creamos un tablero con células vivas o muertas de forma aleatoria.\n", 583 | "Z = np.random.randint(0,2,(SIZE, SIZE))\n", 584 | "# Simulamos durante los pasos indicados.\n", 585 | "for i in range(STEPS):\n", 586 | " Z = iterate(Z)\n", 587 | "# Mostramos el tablero en el paso final.\n", 588 | "print(Z)" 589 | ] 590 | } 591 | ], 592 | "metadata": { 593 | "kernelspec": { 594 | "display_name": "Python 3", 595 | "language": "python", 596 | "name": "python3" 597 | }, 598 | "language_info": { 599 | "codemirror_mode": { 600 | "name": "ipython", 601 | "version": 3 602 | }, 603 | "file_extension": ".py", 604 | "mimetype": "text/x-python", 605 | "name": "python", 606 | "nbconvert_exporter": "python", 607 | "pygments_lexer": "ipython3", 608 | "version": "3.6.8" 609 | } 610 | }, 611 | "nbformat": 4, 612 | "nbformat_minor": 1 613 | } 614 | -------------------------------------------------------------------------------- /python_1/unit_4/README.md: -------------------------------------------------------------------------------- 1 | # Unit 4 - Scientific libraries 2 | 3 | This is the repository of the content for unit 4 (Llibreries científiques en Python / Librerías científicas en Python) of the course: 4 | * 22.401 - Fonaments de Programació 5 | * 22.501 - Fundamentos de Programación 6 | 7 | 8 | -------------------------------------------------------------------------------- /python_1/unit_4/data/README.md: -------------------------------------------------------------------------------- 1 | La font original d'aquestes dades és [FiveThirtyEight](https://fivethirtyeight.com/), un web que realitza articles basats en dades sobre esports i notícies, i que posa a disposició pública els [conjunts de dades](https://github.com/fivethirtyeight/data) que recull per als seus articles. 2 | -------------------------------------------------------------------------------- /python_1/unit_4/data/got.csv: -------------------------------------------------------------------------------- 1 | name,year,battle_number,attacker_king,defender_king,attacker_1,attacker_2,attacker_3,attacker_4,defender_1,defender_2,defender_3,defender_4,attacker_outcome,battle_type,major_death,major_capture,attacker_size,defender_size,attacker_commander,defender_commander,summer,location,region,note 2 | Battle of the Golden Tooth,298,1,Joffrey/Tommen Baratheon,Robb Stark,Lannister,,,,Tully,,,,win,pitched battle,1,0,15000,4000,Jaime Lannister,"Clement Piper, Vance",1,Golden Tooth,The Westerlands, 3 | Battle at the Mummer's Ford,298,2,Joffrey/Tommen Baratheon,Robb Stark,Lannister,,,,Baratheon,,,,win,ambush,1,0,,120,Gregor Clegane,Beric Dondarrion,1,Mummer's Ford,The Riverlands, 4 | Battle of Riverrun,298,3,Joffrey/Tommen Baratheon,Robb Stark,Lannister,,,,Tully,,,,win,pitched battle,0,1,15000,10000,"Jaime Lannister, Andros Brax","Edmure Tully, Tytos Blackwood",1,Riverrun,The Riverlands, 5 | Battle of the Green Fork,298,4,Robb Stark,Joffrey/Tommen Baratheon,Stark,,,,Lannister,,,,loss,pitched battle,1,1,18000,20000,"Roose Bolton, Wylis Manderly, Medger Cerwyn, Harrion Karstark, Halys Hornwood","Tywin Lannister, Gregor Clegane, Kevan Lannister, Addam Marbrand",1,Green Fork,The Riverlands, 6 | Battle of the Whispering Wood,298,5,Robb Stark,Joffrey/Tommen Baratheon,Stark,Tully,,,Lannister,,,,win,ambush,1,1,1875,6000,"Robb Stark, Brynden Tully",Jaime Lannister,1,Whispering Wood,The Riverlands, 7 | Battle of the Camps,298,6,Robb Stark,Joffrey/Tommen Baratheon,Stark,Tully,,,Lannister,,,,win,ambush,0,0,6000,12625,"Robb Stark, Tytos Blackwood, Brynden Tully","Lord Andros Brax, Forley Prester",1,Riverrun,The Riverlands, 8 | Sack of Darry,298,7,Joffrey/Tommen Baratheon,Robb Stark,Lannister,,,,Darry,,,,win,pitched battle,0,0,,,Gregor Clegane,Lyman Darry,1,Darry,The Riverlands, 9 | Battle of Moat Cailin,299,8,Balon/Euron Greyjoy,Robb Stark,Greyjoy,,,,Stark,,,,win,pitched battle,0,0,,,Victarion Greyjoy,,1,Moat Cailin,The North, 10 | Battle of Deepwood Motte,299,9,Balon/Euron Greyjoy,Robb Stark,Greyjoy,,,,Stark,,,,win,siege,0,0,1000,,Asha Greyjoy,,1,Deepwood Motte,The North, 11 | Battle of the Stony Shore,299,10,Balon/Euron Greyjoy,Robb Stark,Greyjoy,,,,Stark,,,,win,ambush,0,0,264,,Theon Greyjoy,,1,Stony Shore,The North,"Greyjoy's troop number based on the Battle of Deepwood Motte, in which Asha had 1000 soldier on 30 longships. That comes out to ~33 per longship. In the Battle of the Stony Shore, Theon has 8 longships, and just we can estimate that he has 8*33 =265 troops." 12 | Battle of Torrhen's Square,299,11,Robb Stark,Balon/Euron Greyjoy,Stark,,,,Greyjoy,,,,win,pitched battle,0,0,244,900,"Rodrik Cassel, Cley Cerwyn",Dagmer Cleftjaw,1,Torrhen's Square,The North,Greyjoy's troop number comes from the 264 estimate to have arrived on the stony shore minus the 20 Theon takes to attack Winterfell. Thus 264-20=244 13 | Battle of Winterfell,299,12,Balon/Euron Greyjoy,Robb Stark,Greyjoy,,,,Stark,,,,win,ambush,0,1,20,,Theon Greyjoy,Bran Stark,1,Winterfell,The North,"It isn't mentioned how many Stark men are left in Winterfell, other than ""very few""." 14 | Sack of Torrhen's Square,299,13,Balon/Euron Greyjoy,Balon/Euron Greyjoy,Greyjoy,,,,Stark,,,,win,siege,0,1,,,Dagmer Cleftjaw,,1,Torrhen's Square,The North, 15 | Sack of Winterfell,299,14,Joffrey/Tommen Baratheon,Robb Stark,Bolton,Greyjoy,,,Stark,,,,win,ambush,1,0,618,2000,"Ramsay Snow, Theon Greyjoy ","Rodrik Cassel, Cley Cerwyn, Leobald Tallhart",1,Winterfell,The North,"Since House Bolton betrays the Starks for House Lannister, we code this battle as between these two houses. Greyjoy men, numbering only 20, don't play a major part in the fighting and end up dying anyway." 16 | Battle of Oxcross,299,15,Robb Stark,Joffrey/Tommen Baratheon,Stark,Tully,,,Lannister,,,,win,ambush,1,1,6000,10000,"Robb Stark, Brynden Tully","Stafford Lannister, Roland Crakehall, Antario Jast",1,Oxcross,The Westerlands, 17 | Siege of Storm's End,299,16,Stannis Baratheon,Renly Baratheon,Baratheon,,,,Baratheon,,,,win,siege,1,0,5000,20000,"Stannis Baratheon, Davos Seaworth","Renly Baratheon, Cortnay Penrose, Loras Tyrell, Randyll Tarly, Mathis Rowan",1,Storm's End,The Stormlands, 18 | Battle of the Fords,299,17,Joffrey/Tommen Baratheon,Robb Stark,Lannister,,,,Tully,,,,loss,pitched battle,0,0,20000,10000,"Tywin Lannister, Flement Brax, Gregor Clegane, Addam Marbrand, Lyle Crakehall, Leo Lefford","Edmure Tully, Jason Mallister, Karyl Vance",1,Red Fork,The Riverlands, 19 | Sack of Harrenhal,299,18,Robb Stark,Joffrey/Tommen Baratheon,Stark,,,,Lannister,,,,win,ambush,1,0,100,100,"Roose Bolton, Vargo Hoat, Robett Glover",Amory Lorch,1,Harrenhal,The Riverlands, 20 | Battle of the Crag,299,19,Robb Stark,Joffrey/Tommen Baratheon,Stark,,,,Lannister,,,,win,ambush,0,0,6000,,"Robb Stark, Smalljon Umber, Black Walder Frey",Rolph Spicer,1,Crag,The Westerlands, 21 | Battle of the Blackwater,299,20,Stannis Baratheon,Joffrey/Tommen Baratheon,Baratheon,,,,Lannister,,,,loss,pitched battle,1,1,21000,7250,"Stannis Baratheon, Imry Florent, Guyard Morrigen, Rolland Storm, Salladhor Saan, Davos Seaworth","Tyrion Lannister, Jacelyn Bywater, Sandor Clegane, Tywin Lannister, Garlan Tyrell, Mace Tyrell, Randyll Tarly",1,King's Landing,The Crownlands, 22 | Siege of Darry,299,21,Robb Stark,Joffrey/Tommen Baratheon,Darry,,,,Lannister,,,,win,siege,0,0,,,Helman Tallhart,,1,Darry,The Riverlands, 23 | Battle of Duskendale,299,22,Robb Stark,Joffrey/Tommen Baratheon,Stark,,,,Lannister,,,,loss,pitched battle,1,0,3000,,"Robertt Glover, Helman Tallhart","Randyll Tarly, Gregor Clegane",1,Duskendale,The Crownlands, 24 | Battle of the Burning Septry,299,23,,,Brotherhood without Banners,,,,Brave Companions,,,,win,pitched battle,0,0,,,,,1,,The Riverlands, 25 | Battle of the Ruby Ford,299,24,Joffrey/Tommen Baratheon,Robb Stark,Lannister,,,,Stark,,,,win,pitched battle,0,0,,6000,Gregor Clegane,"Roose Bolton, Wylis Manderly",,Ruby Ford,The Riverlands, 26 | Retaking of Harrenhal,299,25,Joffrey/Tommen Baratheon,,Lannister,,,,Brave Companions,,,,win,pitched battle,1,0,,,Gregor Clegane,Vargo Hoat,1,Harrenhal,The Riverlands, 27 | The Red Wedding,299,26,Joffrey/Tommen Baratheon,Robb Stark,Frey,Bolton,,,Stark,,,,win,ambush,1,1,3500,3500,"Walder Frey, Roose Bolton, Walder Rivers",Robb Stark,1,The Twins,The Riverlands,"This observation refers to the battle against the Stark men, not the attack on the wedding" 28 | Siege of Seagard,299,27,Robb Stark,Joffrey/Tommen Baratheon,Frey,,,,Mallister,,,,win,siege,0,1,,,Walder Frey,Jason Mallister,1,Seagard,The Riverlands, 29 | Battle of Castle Black,300,28,Stannis Baratheon,Mance Rayder,Free folk,Thenns,Giants,,Night's Watch,Baratheon,,,loss,siege,1,1,100000,1240,"Mance Rayder, Tormund Giantsbane, Harma Dogshead, Magnar Styr, Varamyr","Stannis Baratheon, Jon Snow, Donal Noye, Cotter Pyke",0,Castle Black,Beyond the Wall, 30 | Fall of Moat Cailin,300,29,Joffrey/Tommen Baratheon,Balon/Euron Greyjoy,Bolton,,,,Greyjoy,,,,win,siege,0,0,,,Ramsey Bolton,,0,Moat Cailin,The North, 31 | Sack of Saltpans,300,30,,,Brave Companions,,,,,,,,win,razing,0,0,,,Rorge,,0,Saltpans,The Riverlands, 32 | Retaking of Deepwood Motte,300,31,Stannis Baratheon,Balon/Euron Greyjoy,Baratheon,Karstark,Mormont,Glover,Greyjoy,,,,win,pitched battle,0,0,4500,200,"Stannis Baratheon, Alysane Mormot",Asha Greyjoy,0,Deepwood Motte,The North, 33 | Battle of the Shield Islands,300,32,Balon/Euron Greyjoy,Joffrey/Tommen Baratheon,Greyjoy,,,,Tyrell,,,,win,pitched battle,0,0,,,"Euron Greyjoy, Victarion Greyjoy",,0,Shield Islands,The Reach, 34 | "Invasion of Ryamsport, Vinetown, and Starfish Harbor",300,33,Balon/Euron Greyjoy,Joffrey/Tommen Baratheon,Greyjoy,,,,Tyrell,,,,win,razing,0,0,,,"Euron Greyjoy, Victarion Greyjoy",,0,"Ryamsport, Vinetown, Starfish Harbor",The Reach, 35 | Second Seige of Storm's End,300,34,Joffrey/Tommen Baratheon,Stannis Baratheon,Baratheon,,,,Baratheon,,,,win,siege,0,0,,200,"Mace Tyrell, Mathis Rowan",Gilbert Farring,0,Storm's End,The Stormlands, 36 | Siege of Dragonstone,300,35,Joffrey/Tommen Baratheon,Stannis Baratheon,Baratheon,,,,Baratheon,,,,win,siege,0,0,2000,,"Loras Tyrell, Raxter Redwyne",Rolland Storm,0,Dragonstone,The Stormlands, 37 | Siege of Riverrun,300,36,Joffrey/Tommen Baratheon,Robb Stark,Lannister,Frey,,,Tully,,,,win,siege,0,0,3000,,"Daven Lannister, Ryman Fey, Jaime Lannister",Brynden Tully,0,Riverrun,The Riverlands, 38 | Siege of Raventree,300,37,Joffrey/Tommen Baratheon,Robb Stark,Bracken,Lannister,,,Blackwood,,,,win,siege,0,1,1500,,"Jonos Bracken, Jaime Lannister",Tytos Blackwood,0,Raventree,The Riverlands, 39 | Siege of Winterfell,300,38,Stannis Baratheon,Joffrey/Tommen Baratheon,Baratheon,Karstark,Mormont,Glover,Bolton,Frey,,,,,,,5000,8000,Stannis Baratheon,Roose Bolton,0,Winterfell,The North, -------------------------------------------------------------------------------- /python_1/unit_4/media/Cryoem_groel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_1/unit_4/media/Cryoem_groel.png -------------------------------------------------------------------------------- /python_1/unit_4/media/sagan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_1/unit_4/media/sagan.png -------------------------------------------------------------------------------- /python_1/unit_4/pdf/CAT-prog_datasci_4_matplotlib.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_1/unit_4/pdf/CAT-prog_datasci_4_matplotlib.pdf -------------------------------------------------------------------------------- /python_1/unit_4/pdf/CAT-prog_datasci_4_numpy.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_1/unit_4/pdf/CAT-prog_datasci_4_numpy.pdf -------------------------------------------------------------------------------- /python_1/unit_4/pdf/CAT-prog_datasci_4_pandas.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_1/unit_4/pdf/CAT-prog_datasci_4_pandas.pdf -------------------------------------------------------------------------------- /python_1/unit_4/pdf/CAT-prog_datasci_4_scipy.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_1/unit_4/pdf/CAT-prog_datasci_4_scipy.pdf -------------------------------------------------------------------------------- /python_1/unit_4/pdf/IB-prog_datasci_4_matplotlib.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_1/unit_4/pdf/IB-prog_datasci_4_matplotlib.pdf -------------------------------------------------------------------------------- /python_1/unit_4/pdf/IB-prog_datasci_4_numpy.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_1/unit_4/pdf/IB-prog_datasci_4_numpy.pdf -------------------------------------------------------------------------------- /python_1/unit_4/pdf/IB-prog_datasci_4_pandas.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_1/unit_4/pdf/IB-prog_datasci_4_pandas.pdf -------------------------------------------------------------------------------- /python_1/unit_4/pdf/IB-prog_datasci_4_scipy.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_1/unit_4/pdf/IB-prog_datasci_4_scipy.pdf -------------------------------------------------------------------------------- /python_1/unit_5/.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # IPython Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # dotenv 79 | .env 80 | 81 | # virtualenv 82 | venv/ 83 | ENV/ 84 | 85 | # Spyder project settings 86 | .spyderproject 87 | 88 | # Rope project settings 89 | .ropeproject 90 | .DS_Store 91 | -------------------------------------------------------------------------------- /python_1/unit_5/README.md: -------------------------------------------------------------------------------- 1 | # Unit 5 - Data collection 2 | 3 | This is the repository of the content for unit 5 (Captura de dades en Python / Captura de datos en Python) of the course: 4 | * 22.401 - Fonaments de Programació 5 | * 22.501 - Fundamentos de Programación 6 | 7 | 8 | -------------------------------------------------------------------------------- /python_1/unit_5/pdf/CAT-prog_datasci_5_api.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_1/unit_5/pdf/CAT-prog_datasci_5_api.pdf -------------------------------------------------------------------------------- /python_1/unit_5/pdf/IB-prog_datasci_5_api.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_1/unit_5/pdf/IB-prog_datasci_5_api.pdf -------------------------------------------------------------------------------- /python_1/unit_6/.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # IPython Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # dotenv 79 | .env 80 | 81 | # virtualenv 82 | venv/ 83 | ENV/ 84 | 85 | # Spyder project settings 86 | .spyderproject 87 | 88 | # Rope project settings 89 | .ropeproject 90 | .DS_Store 91 | -------------------------------------------------------------------------------- /python_1/unit_6/README.md: -------------------------------------------------------------------------------- 1 | # Unit 6 - Data preprocessing 2 | 3 | This is the repository of the content for unit 6 (Preprocessament de dades en Python / Preprocesamiento de datos en Python) of the course: 4 | * 22.401 - Fonaments de Programació 5 | * 22.501 - Fundamentos de Programación 6 | 7 | 8 | -------------------------------------------------------------------------------- /python_1/unit_6/data/README.md: -------------------------------------------------------------------------------- 1 | El dataset original en el qual es basen `Baseball.csv`i `Salarios.csv` són repositori de dades del Departament d'Estadística i Investigació operativa de la Universitat Politècnica de Catalunya](http://www-eio.upc.edu/~pau/cms/rdata/datasets.html) 2 | 3 | El dataset original en el qual es basa el conjunt de dades `bank-edited.csv` és [Bank Marketing](http://archive.ics.uci.edu/ml/datasets/Bank+Marketing). 4 | -------------------------------------------------------------------------------- /python_1/unit_6/data/Salarios.csv: -------------------------------------------------------------------------------- 1 | "","type","discipline","yrs.since.phd","yrs.service","sex","salary" 2 | "1","Prof","B",19,18,"Male",139750 3 | "2","Prof","B",20,16,"Male",173200 4 | "3","AsstProf","B",4,3,"Male",79750 5 | "4","Prof","B",45,39,"Male",115000 6 | "5","Prof","B",40,41,"Male",141500 7 | "6","AssocProf","B",6,6,"Male",97000 8 | "7","Prof","B",30,23,"Male",175000 9 | "8","Prof","B",45,45,"Male",147765 10 | "9","Prof","B",21,20,"Male",119250 11 | "10","Prof","B",18,18,"Female",129000 12 | "11","AssocProf","B",12,8,"Male",119800 13 | "12","AsstProf","B",7,2,"Male",79800 14 | "13","AsstProf","B",1,1,"Male",77700 15 | "14","AsstProf","B",2,0,"Male",NaN 16 | "15","Prof","B",20,18,"Male",104800 17 | "16","Prof","B",12,3,"Male",117150 18 | "17","Prof","B",19,20,"Male",101000 19 | "18","Prof","A",38,34,"Male",103450 20 | "19","Prof","A",37,23,"Male",124750 21 | "20","Prof","A",39,36,"Female",137000 22 | "21","Prof","A",31,26,"Male",89565 23 | "22","Prof","A",36,31,"Male",102580 24 | "23","Prof","A",34,30,"Male",93904 25 | "24","Prof","A",24,19,"Male",113068 26 | "25","AssocProf","A",13,8,"Female",74830 27 | "26","Prof","A",21,8,"Male",106294 28 | "27","Prof","A",35,23,"Male",134885 29 | "28","AsstProf","B",5,3,"Male",82379 30 | "29","AsstProf","B",11,0,"Male",77000 31 | "30","Prof","B",12,8,"Male",118223 32 | "31","Prof","B",20,4,"Male",132261 33 | "32","AsstProf","B",7,2,"Male",79916 34 | "33","Prof","B",13,9,"Male",NaN 35 | "34","AsstProf","B",4,2,"Male",80225 36 | "35","AsstProf","B",4,2,"Female",80225 37 | "36","AsstProf","B",5,0,"Female",77000 38 | "37","Prof","B",22,21,"Male",155750 39 | "38","AsstProf","B",7,4,"Male",86373 40 | "39","Prof","B",41,31,"Male",125196 41 | "40","AssocProf","B",9,9,"Male",100938 42 | "41","Prof","B",23,2,"Male",146500 43 | "42","AssocProf","B",23,23,"Male",93418 44 | "43","Prof","B",40,27,"Male",101299 45 | "44","Prof","B",38,38,"Male",231545 46 | "45","Prof","B",19,19,"Male",94384 47 | "46","Prof","B",25,15,"Male",114778 48 | "47","Prof","B",40,28,"Male",98193 49 | "48","Prof","B",23,19,"Female",151768 50 | "49","Prof","B",25,25,"Female",140096 51 | "50","AsstProf","B",1,1,"Male",70768 52 | "51","Prof","B",28,28,"Male",126621 53 | "52","Prof","B",12,11,"Male",108875 54 | "53","AsstProf","B",11,3,"Female",74692 55 | "54","Prof","B",16,9,"Male",106639 56 | "55","AssocProf","B",12,11,"Male",103760 57 | "56","AssocProf","B",14,5,"Male",83900 58 | "57","Prof","B",23,21,"Male",NaN 59 | "58","AssocProf","B",9,8,"Male",90215 60 | "59","AssocProf","B",10,9,"Male",100135 61 | "60","AsstProf","B",8,3,"Male",75044 62 | "61","AssocProf","B",9,8,"Male",90304 63 | "62","AsstProf","B",3,2,"Male",75243 64 | "63","Prof","B",33,31,"Male",109785 65 | "64","AssocProf","B",11,11,"Female",103613 66 | "65","AsstProf","B",4,3,"Male",68404 67 | "66","AssocProf","B",9,8,"Male",NaN 68 | "67","Prof","B",22,12,"Male",101000 69 | "68","Prof","B",35,31,"Male",99418 70 | "69","Prof","B",17,17,"Female",111512 71 | "70","Prof","B",28,36,"Male",91412 72 | "71","Prof","B",17,2,"Male",126320 73 | "72","Prof","B",45,45,"Male",146856 74 | "73","Prof","B",29,19,"Male",100131 75 | "74","Prof","B",35,34,"Male",92391 76 | "75","Prof","B",28,23,"Male",113398 77 | "76","AsstProf","B",8,3,"Male",73266 78 | "77","Prof","B",17,3,"Male",150480 79 | "78","Prof","B",26,19,"Male",193000 80 | "79","AsstProf","B",3,1,"Male",86100 81 | "80","AsstProf","B",6,2,"Male",84240 82 | "81","Prof","B",43,28,"Male",150743 83 | "82","Prof","B",17,16,"Male",135585 84 | "83","Prof","B",22,20,"Male",144640 85 | "84","AsstProf","B",6,2,"Male",88825 86 | "85","Prof","B",17,18,"Female",122960 87 | "86","Prof","B",15,14,"Male",132825 88 | "87","Prof","B",37,37,"Male",152708 89 | "88","AsstProf","B",2,2,"Male",88400 90 | "89","Prof","B",25,25,"Male",172272 91 | "90","AssocProf","B",9,7,"Male",107008 92 | "91","AsstProf","B",10,5,"Female",97032 93 | "92","AssocProf","B",10,7,"Male",105128 94 | "93","AssocProf","B",10,7,"Male",105631 95 | "94","Prof","B",38,38,"Male",166024 96 | "95","Prof","B",21,20,"Male",123683 97 | "96","AsstProf","B",4,0,"Male",84000 98 | "97","AssocProf","B",17,12,"Male",95611 99 | "98","Prof","B",13,7,"Male",129676 100 | "99","Prof","B",30,14,"Male",102235 101 | "100","Prof","B",41,26,"Male",106689 102 | "101","Prof","B",42,25,"Male",133217 103 | "102","Prof","B",28,23,"Male",126933 104 | "103","Prof","B",16,5,"Male",153303 105 | "104","Prof","B",20,14,"Female",127512 106 | "105","AssocProf","A",18,10,"Male",83850 107 | "106","Prof","A",31,28,"Male",113543 108 | "107","AssocProf","A",11,8,"Male",82099 109 | "108","AssocProf","A",10,8,"Male",82600 110 | "109","AssocProf","A",15,8,"Male",81500 111 | "110","Prof","A",40,31,"Male",131205 112 | "111","Prof","A",20,16,"Male",112429 113 | "112","AssocProf","A",19,16,"Male",82100 114 | "113","AsstProf","A",3,1,"Male",72500 115 | "114","Prof","A",37,37,"Male",104279 116 | "115","Prof","A",12,0,"Female",105000 117 | "116","Prof","A",21,9,"Male",120806 118 | "117","Prof","A",30,29,"Male",148500 119 | "118","Prof","A",39,36,"Male",117515 120 | "119","AsstProf","A",4,1,"Male",72500 121 | "120","AsstProf","A",5,3,"Female",73500 122 | "121","Prof","A",14,14,"Male",115313 123 | "122","Prof","A",32,32,"Male",124309 124 | "123","Prof","A",24,22,"Male",97262 125 | "124","AssocProf","A",25,22,"Female",62884 126 | "125","Prof","A",24,22,"Male",96614 127 | "126","Prof","A",54,49,"Male",NaN 128 | "127","Prof","A",28,26,"Male",155500 129 | "128","AsstProf","A",2,0,"Female",72500 130 | "129","Prof","A",32,30,"Male",113278 131 | "130","AsstProf","A",4,2,"Male",73000 132 | "131","AssocProf","A",11,9,"Male",83001 133 | "132","Prof","A",56,57,"Male",76840 134 | "133","AssocProf","A",10,8,"Female",77500 135 | "134","AsstProf","A",3,1,"Female",72500 136 | "135","Prof","A",35,25,"Male",168635 137 | "136","Prof","A",20,18,"Male",136000 138 | "137","Prof","A",16,14,"Male",108262 139 | "138","Prof","A",17,14,"Male",105668 140 | "139","AssocProf","A",10,7,"Male",73877 141 | "140","Prof","A",21,18,"Male",152664 142 | "141","AssocProf","A",14,8,"Male",100102 143 | "142","AssocProf","A",15,10,"Male",81500 144 | "143","Prof","A",19,11,"Male",106608 145 | "144","AsstProf","B",3,3,"Male",89942 146 | "145","Prof","B",27,27,"Male",112696 147 | "146","Prof","B",28,28,"Male",119015 148 | "147","AsstProf","B",4,4,"Male",92000 149 | "148","Prof","B",27,27,"Male",156938 150 | "149","Prof","B",36,26,"Female",144651 151 | "150","AsstProf","B",4,3,"Male",95079 152 | "151","Prof","B",14,12,"Male",128148 153 | "152","AsstProf","B",4,4,"Male",92000 154 | "153","Prof","B",21,9,"Male",111168 155 | "154","AssocProf","B",12,10,"Female",103994 156 | "155","AsstProf","B",4,0,"Male",92000 157 | "156","Prof","B",21,21,"Male",118971 158 | "157","AssocProf","B",12,18,"Male",113341 159 | "158","AsstProf","B",1,0,"Male",88000 160 | "159","AssocProf","B",6,6,"Male",95408 161 | "160","Prof","B",15,16,"Male",137167 162 | "161","AsstProf","B",2,2,"Male",89516 163 | "162","Prof","B",26,19,"Male",176500 164 | "163","AssocProf","B",22,7,"Male",98510 165 | "164","AsstProf","B",3,3,"Male",89942 166 | "165","AsstProf","B",1,0,"Male",88795 167 | "166","Prof","B",21,8,"Male",105890 168 | "167","Prof","B",16,16,"Male",167284 169 | "168","Prof","B",18,19,"Male",130664 170 | "169","AssocProf","B",8,6,"Male",101210 171 | "170","Prof","B",25,18,"Male",181257 172 | "171","AsstProf","B",5,5,"Male",91227 173 | "172","Prof","B",19,19,"Male",151575 174 | "173","Prof","B",37,24,"Male",93164 175 | "174","Prof","B",20,20,"Male",134185 176 | "175","AssocProf","B",17,6,"Male",105000 177 | "176","Prof","B",28,25,"Male",111751 178 | "177","AssocProf","B",10,7,"Male",95436 179 | "178","AssocProf","B",13,9,"Male",100944 180 | "179","Prof","B",27,14,"Male",147349 181 | "180","AsstProf","B",3,3,"Female",92000 182 | "181","Prof","B",11,11,"Male",142467 183 | "182","Prof","B",18,5,"Male",141136 184 | "183","AssocProf","B",8,8,"Male",100000 185 | "184","Prof","B",26,22,"Male",150000 186 | "185","Prof","B",23,23,"Male",101000 187 | "186","Prof","B",33,30,"Male",134000 188 | "187","AssocProf","B",13,10,"Female",103750 189 | "188","Prof","B",18,10,"Male",107500 190 | "189","AssocProf","B",28,28,"Male",106300 191 | "190","Prof","B",25,19,"Male",153750 192 | "191","Prof","B",22,9,"Male",180000 193 | "192","Prof","B",43,22,"Male",133700 194 | "193","Prof","B",19,18,"Male",122100 195 | "194","AssocProf","B",19,19,"Male",86250 196 | "195","AssocProf","B",48,53,"Male",90000 197 | "196","AssocProf","B",9,7,"Male",113600 198 | "197","AsstProf","B",4,4,"Male",92700 199 | "198","AsstProf","B",4,4,"Male",92000 200 | "199","Prof","B",34,33,"Male",189409 201 | "200","Prof","B",38,22,"Male",114500 202 | "201","AsstProf","B",4,4,"Male",92700 203 | "202","Prof","B",40,40,"Male",119700 204 | "203","Prof","B",28,17,"Male",160400 205 | "204","Prof","B",17,17,"Male",152500 206 | "205","Prof","B",19,5,"Male",165000 207 | "206","Prof","B",21,2,"Male",96545 208 | "207","Prof","B",35,33,"Male",162200 209 | "208","Prof","B",18,18,"Male",120000 210 | "209","AsstProf","B",7,2,"Male",NaN 211 | "210","Prof","B",20,20,"Male",163200 212 | "211","AsstProf","B",4,3,"Male",91000 213 | "212","Prof","B",39,39,"Male",111350 214 | "213","Prof","B",15,7,"Male",128400 215 | "214","Prof","B",26,19,"Male",126200 216 | "215","AssocProf","B",11,1,"Male",118700 217 | "216","Prof","B",16,11,"Male",145350 218 | "217","Prof","B",15,11,"Male",146000 219 | "218","AssocProf","B",29,22,"Male",105350 220 | "219","AssocProf","B",14,7,"Female",109650 221 | "220","Prof","B",13,11,"Male",119500 222 | "221","Prof","B",21,21,"Male",170000 223 | "222","Prof","B",23,10,"Male",145200 224 | "223","AssocProf","B",13,6,"Male",107150 225 | "224","Prof","B",34,20,"Male",129600 226 | "225","Prof","A",38,35,"Male",87800 227 | "226","Prof","A",20,20,"Male",122400 228 | "227","AsstProf","A",3,1,"Male",63900 229 | "228","AssocProf","A",9,7,"Male",70000 230 | "229","Prof","A",16,11,"Male",88175 231 | "230","Prof","A",39,38,"Male",133900 232 | "231","Prof","A",29,27,"Female",91000 233 | "232","AssocProf","A",26,24,"Female",73300 234 | "233","Prof","A",38,19,"Male",148750 235 | "234","Prof","A",36,19,"Female",117555 236 | "235","AsstProf","A",8,3,"Male",69700 237 | "236","Prof","A",28,17,"Male",81700 238 | "237","Prof","A",25,25,"Male",114000 239 | "238","AsstProf","A",7,6,"Female",63100 240 | "239","Prof","A",46,40,"Male",77202 241 | "240","Prof","A",19,6,"Male",96200 242 | "241","AsstProf","A",5,3,"Male",69200 243 | "242","Prof","A",31,30,"Male",122875 244 | "243","Prof","A",38,37,"Male",102600 245 | "244","Prof","A",23,23,"Male",108200 246 | "245","Prof","A",19,23,"Male",84273 247 | "246","Prof","A",17,11,"Female",90450 248 | "247","Prof","A",30,23,"Male",91100 249 | "248","Prof","A",21,18,"Male",101100 250 | "249","Prof","A",28,23,"Male",NaN 251 | "250","Prof","A",29,7,"Male",204000 252 | "251","Prof","A",39,39,"Male",109000 253 | "252","Prof","A",20,8,"Male",102000 254 | "253","Prof","A",31,12,"Male",132000 255 | "254","AsstProf","A",4,2,"Female",77500 256 | "255","Prof","A",28,7,"Female",116450 257 | "256","AssocProf","A",12,8,"Male",83000 258 | "257","Prof","A",22,22,"Male",140300 259 | "258","AssocProf","A",30,23,"Male",74000 260 | "259","AsstProf","A",9,3,"Male",73800 261 | "260","Prof","A",32,30,"Male",92550 262 | "261","AssocProf","A",41,33,"Male",88600 263 | "262","Prof","A",45,45,"Male",107550 264 | "263","Prof","A",31,26,"Male",121200 265 | "264","Prof","A",31,31,"Male",126000 266 | "265","Prof","A",37,35,"Male",99000 267 | "266","Prof","A",36,30,"Male",134800 268 | "267","Prof","A",43,43,"Male",143940 269 | "268","Prof","A",14,10,"Male",104350 270 | "269","Prof","A",47,44,"Male",89650 271 | "270","Prof","A",13,7,"Male",103700 272 | "271","Prof","A",42,40,"Male",143250 273 | "272","Prof","A",42,18,"Male",194800 274 | "273","AsstProf","A",4,1,"Male",73000 275 | "274","AsstProf","A",8,4,"Male",74000 276 | "275","AsstProf","A",8,3,"Female",78500 277 | "276","Prof","A",12,6,"Male",93000 278 | "277","Prof","A",52,48,"Male",107200 279 | "278","Prof","A",31,27,"Male",163200 280 | "279","Prof","A",24,18,"Male",107100 281 | "280","Prof","A",46,46,"Male",100600 282 | "281","Prof","A",39,38,"Male",136500 283 | "282","Prof","A",37,27,"Male",NaN 284 | "283","Prof","A",51,51,"Male",57800 285 | "284","Prof","A",45,43,"Male",155865 286 | "285","AssocProf","A",8,6,"Male",88650 287 | "286","AssocProf","A",49,49,"Male",81800 288 | "287","Prof","A",28,27,"Male",115800 289 | "288","AsstProf","A",2,0,"Male",85000 290 | "289","Prof","A",29,27,"Male",150500 291 | "290","AsstProf","A",8,5,"Male",74000 292 | "291","Prof","A",33,7,"Male",174500 293 | "292","Prof","A",32,28,"Male",168500 294 | "293","Prof","A",39,9,"Male",183800 295 | "294","AssocProf","A",11,1,"Male",104800 296 | "295","Prof","A",19,7,"Male",107300 297 | "296","Prof","A",40,36,"Male",97150 298 | "297","Prof","A",18,18,"Male",126300 299 | "298","Prof","A",17,11,"Male",148800 300 | "299","Prof","A",49,43,"Male",72300 301 | "300","AssocProf","A",45,39,"Male",70700 302 | "301","Prof","A",39,36,"Male",88600 303 | "302","Prof","A",27,16,"Male",127100 304 | "303","Prof","A",28,13,"Male",170500 305 | "304","Prof","A",14,4,"Male",105260 306 | "305","Prof","A",46,44,"Male",144050 307 | "306","Prof","A",33,31,"Male",NaN 308 | "307","AsstProf","A",7,4,"Male",74500 309 | "308","Prof","A",31,28,"Male",122500 310 | "309","AsstProf","A",5,0,"Male",74000 311 | "310","Prof","A",22,15,"Male",166800 312 | "311","Prof","A",20,7,"Male",92050 313 | "312","Prof","A",14,9,"Male",108100 314 | "313","Prof","A",29,19,"Male",94350 315 | "314","Prof","A",35,35,"Male",100351 316 | "315","Prof","A",22,6,"Male",146800 317 | "316","AsstProf","B",6,3,"Male",84716 318 | "317","AssocProf","B",12,9,"Female",71065 319 | "318","Prof","B",46,45,"Male",67559 320 | "319","Prof","B",16,16,"Male",134550 321 | "320","Prof","B",16,15,"Male",135027 322 | "321","Prof","B",24,23,"Male",104428 323 | "322","AssocProf","B",9,9,"Male",95642 324 | "323","AssocProf","B",13,11,"Male",126431 325 | "324","Prof","B",24,15,"Female",NaN 326 | "325","Prof","B",30,31,"Male",162221 327 | "326","AsstProf","B",8,4,"Male",84500 328 | "327","Prof","B",23,15,"Male",124714 329 | "328","Prof","B",37,37,"Male",151650 330 | "329","AssocProf","B",10,10,"Male",99247 331 | "330","Prof","B",23,23,"Male",134778 332 | "331","Prof","B",49,60,"Male",192253 333 | "332","Prof","B",20,9,"Male",116518 334 | "333","Prof","B",18,10,"Female",105450 335 | "334","Prof","B",33,19,"Male",145098 336 | "335","AssocProf","B",19,6,"Female",104542 337 | "336","Prof","B",36,38,"Male",151445 338 | "337","Prof","B",35,23,"Male",98053 339 | "338","Prof","B",13,12,"Male",145000 340 | "339","Prof","B",32,25,"Male",128464 341 | "340","Prof","B",37,15,"Male",137317 342 | "341","Prof","B",13,11,"Male",106231 343 | "342","Prof","B",17,17,"Female",124312 344 | "343","Prof","B",38,38,"Male",114596 345 | "344","Prof","B",31,31,"Male",162150 346 | "345","Prof","B",32,35,"Male",150376 347 | "346","Prof","B",15,10,"Male",107986 348 | "347","Prof","B",41,27,"Male",142023 349 | "348","Prof","B",39,33,"Male",128250 350 | "349","AsstProf","B",4,3,"Male",80139 351 | "350","Prof","B",27,28,"Male",144309 352 | "351","Prof","B",56,49,"Male",186960 353 | "352","Prof","B",38,38,"Male",93519 354 | "353","Prof","B",26,27,"Male",142500 355 | "354","Prof","B",22,20,"Male",138000 356 | "355","AsstProf","B",8,1,"Male",83600 357 | "356","Prof","B",25,21,"Male",145028 358 | "357","Prof","A",49,40,"Male",88709 359 | "358","Prof","A",39,35,"Male",107309 360 | "359","Prof","A",28,14,"Female",NaN 361 | "360","AsstProf","A",11,4,"Male",78785 362 | "361","Prof","A",14,11,"Male",121946 363 | "362","Prof","A",23,15,"Female",109646 364 | "363","Prof","A",30,30,"Male",138771 365 | "364","AssocProf","A",20,17,"Male",81285 366 | "365","Prof","A",43,43,"Male",205500 367 | "366","Prof","A",43,40,"Male",101036 368 | "367","Prof","A",15,10,"Male",115435 369 | "368","AssocProf","A",10,1,"Male",108413 370 | "369","Prof","A",35,30,"Male",131950 371 | "370","Prof","A",33,31,"Male",134690 372 | "371","AssocProf","A",13,8,"Male",78182 373 | "372","Prof","A",23,20,"Male",110515 374 | "373","Prof","A",12,7,"Male",109707 375 | "374","Prof","A",30,26,"Male",136660 376 | "375","Prof","A",27,19,"Male",103275 377 | "376","Prof","A",28,26,"Male",103649 378 | "377","AsstProf","A",4,1,"Male",NaN 379 | "378","AsstProf","A",6,3,"Male",77081 380 | "379","Prof","A",38,38,"Male",150680 381 | "380","AssocProf","A",11,8,"Male",104121 382 | "381","AsstProf","A",8,3,"Male",75996 383 | "382","Prof","A",27,23,"Male",172505 384 | "383","AssocProf","A",8,5,"Male",86895 385 | "384","Prof","A",44,44,"Male",105000 386 | "385","Prof","A",27,21,"Male",NaN 387 | "386","Prof","A",15,9,"Male",114330 388 | "387","Prof","A",29,27,"Male",139219 389 | "388","Prof","A",29,15,"Male",109305 390 | "389","Prof","A",38,36,"Male",119450 391 | "390","Prof","A",33,18,"Male",186023 392 | "391","Prof","A",40,19,"Male",166605 393 | "392","Prof","A",30,19,"Male",151292 394 | "393","Prof","A",33,30,"Male",NaN 395 | "394","Prof","A",31,19,"Male",150564 396 | "395","Prof","A",42,25,"Male",101738 397 | "396","Prof","A",25,15,"Male",95329 398 | "397","AsstProf","A",8,4,"Male",81035 399 | -------------------------------------------------------------------------------- /python_1/unit_6/pdf/CAT-prog_datasci_6_preproc.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_1/unit_6/pdf/CAT-prog_datasci_6_preproc.pdf -------------------------------------------------------------------------------- /python_1/unit_6/pdf/IB-prog_datasci_6_preproc.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_1/unit_6/pdf/IB-prog_datasci_6_preproc.pdf -------------------------------------------------------------------------------- /python_1/unit_7/.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # IPython Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # dotenv 79 | .env 80 | 81 | # virtualenv 82 | venv/ 83 | ENV/ 84 | 85 | # Spyder project settings 86 | .spyderproject 87 | 88 | # Rope project settings 89 | .ropeproject 90 | .DS_Store 91 | -------------------------------------------------------------------------------- /python_1/unit_7/README.md: -------------------------------------------------------------------------------- 1 | # Unit 7 - Data preprocessing 2 | 3 | This is the repository of the content for unit 7 (Introducció a l'anàlisi de dades en Python / Introducción al análisis de datos en Python) of the course: 4 | * 22.401 - Fonaments de Programació 5 | * 22.501 - Fundamentos de Programación 6 | 7 | 8 | -------------------------------------------------------------------------------- /python_1/unit_7/pdf/CAT-prog_datasci_7_analisis.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_1/unit_7/pdf/CAT-prog_datasci_7_analisis.pdf -------------------------------------------------------------------------------- /python_1/unit_7/pdf/IB-prog_datasci_7_analisis.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_1/unit_7/pdf/IB-prog_datasci_7_analisis.pdf -------------------------------------------------------------------------------- /python_1/unit_8/.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # IPython Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # dotenv 79 | .env 80 | 81 | # virtualenv 82 | venv/ 83 | ENV/ 84 | 85 | # Spyder project settings 86 | .spyderproject 87 | 88 | # Rope project settings 89 | .ropeproject 90 | .DS_Store 91 | -------------------------------------------------------------------------------- /python_1/unit_8/README.md: -------------------------------------------------------------------------------- 1 | # Unit 8 - Data visualization 2 | 3 | This is the repository of the content for unit 8 (Visualització de dades en Python / Visualización de datos en Python) of the course: 4 | * 22.401 - Fonaments de Programació 5 | * 22.501 - Fundamentos de Programación 6 | 7 | 8 | -------------------------------------------------------------------------------- /python_1/unit_8/data/README.md: -------------------------------------------------------------------------------- 1 | Els conjunts de dades `bus.csv`,` flights.csv`, `gz_2010_us_050_00_20m.json` i `unemployment.json` pertanyen als exemples de la llibreria [geoplotlib](https://github.com/andrea-cuttone/ geoplotlib). 2 | 3 | El conjunt de dades `pulitzer-circulation-data.csv` és de [FiveThirtyEight](https://fivethirtyeight.com/), un web que realitza articles basats en dades sobre esports i notícies, i que posa a disposició pública els [conjunts de dades](https://github.com/fivethirtyeight/data) que recull per als seus articles. 4 | -------------------------------------------------------------------------------- /python_1/unit_8/data/elecciones.csv: -------------------------------------------------------------------------------- 1 | Candidaturas,Votos,%**,Escaños,% 2 | Partido Popular (PP),7.372.172,"31,27",126,36 3 | Partido Socialista Obrero Español (PSOE),4.663.505,"19,53",75,"21,42" 4 | Unidos Podemos (PODEMOS-IU-ECUO-CLIAS),3.227.123,"13,51",45,"12,8" 5 | Ciudadanos - Partido de la Ciudadania (C´s),3.141.570,"13,15",32,"9,14" 6 | En Comú Podem - Guanyem El Camvi (ECP),853.102,"3,57",12,"3,42" 7 | Compromís-Podemos-EUPV: A la Valenciana (PODEMOS - COMPROMÍS - EUPV),659.771,"2,76",9,"2,57" 8 | Esquerra Republicana / Catalunya Sí (ERC - CATSÍ),632.234,"2,64",9,"2,57" 9 | Partìt dels Socialistes de Catalunya (PSC - PSOE),559.870,"2,34",7,2 10 | Convergència Democrática de Catalunya (CDC),483.488,"2,02",8,"2,28" 11 | En Marea (PODEMOS - EN MAREA - ANOVA - EU),347.542,"1,4",5,"1,42" 12 | Euzko Alberdi Jeltzalea - Partido Nacionalista -Vasco (EAJ - PNV),287.014,"1,2",5,"1,42" 13 | Partido Popular en coalición con el partido Aragonés (PP - PAR),252.456,1,6,"1,71" 14 | Partido Socialista Obrero Español - Nueva Canarias (PSOE - NCa),220.471,"0,92",3,"0,85" 15 | Partido Popular - Foro (PP - FORO),209.632,"0,87",3,"0,85" 16 | Euskal Herria - Bildu (EH - BILDU),184.713,"0,77",2,"0,57" 17 | Unión del Pueblo Navarro en coalición con el Partido Popular (UPN - PP),106.976,"0,44",2,"0,57" 18 | Coalición Canaria (CCa),78.253,"0,32",1,"0,28" 19 | -------------------------------------------------------------------------------- /python_1/unit_8/data/pulitzer-circulation-data.csv: -------------------------------------------------------------------------------- 1 | Newspaper,Daily Circulation 2004,Daily Circulation 2013,Change in Daily Circulation 2004-2013,Pulitzer Prize Winners and Finalists 1990-2003,Pulitzer Prize Winners and Finalists 2004-2014,Pulitzer Prize Winners and Finalists 1990-2014 2 | USA Today,2192098,1674306,-24%,1,1,2 3 | Wall Street Journal,2101017,2378827,+13%,30,20,50 4 | New York Times,1119027,1865318,+67%,55,62,117 5 | Los Angeles Times,983727,653868,-34%,44,41,85 6 | Washington Post,760034,474767,-38%,52,48,100 7 | New York Daily News,712671,516165,-28%,4,2,6 8 | New York Post,642844,500521,-22%,0,0,0 9 | Chicago Tribune,603315,414930,-31%,23,15,38 10 | San Jose Mercury News,558874,583998,+4%,4,2,6 11 | Newsday,553117,377744,-32%,12,6,18 12 | Houston Chronicle,549300,360251,-34%,2,3,5 13 | Dallas Morning News,528379,409265,-23%,11,6,17 14 | San Francisco Chronicle,499008,218987,-56%,7,2,9 15 | Arizona Republic,466926,293640,-37%,5,2,7 16 | Chicago Sun-Times,453757,470548,+4%,1,1,2 17 | Boston Globe,446241,245572,-45%,25,16,41 18 | Atlanta Journal Constitution,409873,231094,-44%,1,5,6 19 | Newark Star Ledger,395000,340778,-14%,2,6,8 20 | Detroit Free Press,379304,209652,-45%,7,5,12 21 | Minneapolis Star Tribune,377058,301345,-20%,4,4,8 22 | Philadelphia Inquirer,376454,306831,-18%,24,8,32 23 | Cleveland Plain Dealer,367528,311605,-15%,4,7,11 24 | San Diego Union-Tribune,355771,250678,-30%,0,2,2 25 | Tampa Bay Times,348502,340260,-2%,10,11,21 26 | Denver Post,340168,416676,+22%,1,8,9 27 | Rocky Mountain News,340007,0,-100%,4,1,5 28 | Oregonian,339169,228909,-33%,9,8,17 29 | Miami Herald,325032,147130,-55%,17,7,24 30 | Orange County Register,310001,356165,+15%,3,2,5 31 | Sacramento Bee,303841,200802,-34%,4,4,8 32 | St. Louis Post-Dispatch,281198,167199,-41%,4,3,7 33 | Baltimore Sun,277947,177054,-36%,11,2,13 34 | Kansas City Star,275747,189283,-31%,2,0,2 35 | Detroit News,271465,115643,-57%,4,0,4 36 | Orlando Sentinel,269269,161070,-40%,5,2,7 37 | South Florida Sun-Sentinel,268297,163728,-39%,0,1,1 38 | New Orleans Times-Picayune,262008,0,-100%,5,3,8 39 | Columbus Dispatch,259127,137148,-47%,1,0,1 40 | Indianapolis Star,253778,156850,-38%,1,0,1 41 | San Antonio Express-News,246057,139005,-44%,0,0,0 42 | Pittsburgh Post-Gazette,242514,180433,-26%,3,0,3 43 | Milwaukee Journal Sentinel,241605,198469,-18%,2,8,10 44 | Tampa Tribune,238877,191477,-20%,0,0,0 45 | Fort Woth Star-Telegram,237318,188593,-21%,1,0,1 46 | Boston Herald,236899,95929,-60%,0,0,0 47 | Seattle Times,233497,229764,-2%,11,5,16 48 | Charlotte Observer,231369,137829,-40%,1,3,4 49 | Daily Oklahoman,223403,124667,-44%,0,0,0 50 | Louisville Courier-Journal,216934,131208,-40%,0,3,3 51 | Investor's Buisiness Daily,215735,157161,-27%,0,1,1 52 | -------------------------------------------------------------------------------- /python_1/unit_8/pdf/CAT-prog_datasci_8_vis.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_1/unit_8/pdf/CAT-prog_datasci_8_vis.pdf -------------------------------------------------------------------------------- /python_1/unit_8/pdf/IB-prog_datasci_8_vis.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_1/unit_8/pdf/IB-prog_datasci_8_vis.pdf -------------------------------------------------------------------------------- /python_2/unit_0/.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # IPython Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # dotenv 79 | .env 80 | 81 | # virtualenv 82 | venv/ 83 | ENV/ 84 | 85 | # Spyder project settings 86 | .spyderproject 87 | 88 | # Rope project settings 89 | .ropeproject 90 | .DS_Store 91 | -------------------------------------------------------------------------------- /python_2/unit_0/README.md: -------------------------------------------------------------------------------- 1 | # Unit 0 - Reviewing concepts 2 | 3 | This is the repository of the content for unit 0 (Refermant conceptes / Afianzando conceptos) of the course: 4 | * 22.403 - Programació per a la Ciència de Dades 5 | * 22.503 - Programación para la Ciencia de Datos 6 | 7 | 8 | -------------------------------------------------------------------------------- /python_2/unit_0/pdf/0-CAT-Refermant_conceptes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_2/unit_0/pdf/0-CAT-Refermant_conceptes.pdf -------------------------------------------------------------------------------- /python_2/unit_0/pdf/0-ES-Afianzando_conceptos.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_2/unit_0/pdf/0-ES-Afianzando_conceptos.pdf -------------------------------------------------------------------------------- /python_2/unit_1/.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # IPython Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # dotenv 79 | .env 80 | 81 | # virtualenv 82 | venv/ 83 | ENV/ 84 | 85 | # Spyder project settings 86 | .spyderproject 87 | 88 | # Rope project settings 89 | .ropeproject 90 | .DS_Store 91 | -------------------------------------------------------------------------------- /python_2/unit_1/README.md: -------------------------------------------------------------------------------- 1 | # Unit 1 - Advanced data structures 2 | 3 | This is the repository of the content for unit 1 (Estructures de dades avançades / Estructuras de datos avanzadas) of the course: 4 | * 22.403 - Programació per a la Ciència de Dades 5 | * 22.503 - Programación para la Ciencia de Datos 6 | 7 | 8 | -------------------------------------------------------------------------------- /python_2/unit_1/data/flight714.csv: -------------------------------------------------------------------------------- 1 | client_id,client_class,has_children,has_reduced_mobility 2 | 1,p,0,0 3 | 2,p,0,0 4 | 3,p,0,0 5 | 4,b,0,0 6 | 5,b,0,0 7 | 6,b,0,0 8 | 7,b,0,0 9 | 8,b,0,0 10 | 9,b,0,0 11 | 10,b,0,0 12 | 11,b,0,0 13 | 12,b,0,0 14 | 13,b,0,0 15 | 14,t,0,0 16 | 15,t,1,0 17 | 16,t,0,0 18 | 17,t,1,0 19 | 18,t,0,0 20 | 19,t,0,0 21 | 20,t,0,0 22 | 21,t,0,0 23 | 22,t,0,0 24 | 23,t,0,0 25 | 24,t,0,0 26 | 25,t,0,0 27 | 26,t,0,0 28 | 27,t,0,0 29 | 28,t,0,0 30 | 29,t,0,0 31 | 30,t,0,0 32 | 31,t,1,0 33 | 32,t,0,0 34 | 33,t,0,0 35 | 34,t,0,0 36 | 35,t,0,0 37 | 36,t,0,1 38 | 37,t,0,0 39 | 38,t,0,0 40 | 39,t,0,0 41 | 40,t,0,1 42 | 41,t,0,0 43 | 42,t,0,0 44 | 43,t,0,0 45 | 44,t,0,0 46 | 45,t,0,0 47 | 46,t,0,0 48 | 47,t,1,1 49 | 48,t,0,0 50 | 49,t,0,0 51 | 50,t,0,0 -------------------------------------------------------------------------------- /python_2/unit_1/pdf/1-CAT-Estructures_dades_avançades.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_2/unit_1/pdf/1-CAT-Estructures_dades_avançades.pdf -------------------------------------------------------------------------------- /python_2/unit_1/pdf/1-ES-Estructuras_de_datos_avanzadas.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_2/unit_1/pdf/1-ES-Estructuras_de_datos_avanzadas.pdf -------------------------------------------------------------------------------- /python_2/unit_2/.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # IPython Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # dotenv 79 | .env 80 | 81 | # virtualenv 82 | venv/ 83 | ENV/ 84 | 85 | # Spyder project settings 86 | .spyderproject 87 | 88 | # Rope project settings 89 | .ropeproject 90 | .DS_Store 91 | -------------------------------------------------------------------------------- /python_2/unit_2/README.md: -------------------------------------------------------------------------------- 1 | # Unit 2 - Advanced use of functions 2 | 3 | This is the repository of the content for unit 2 (Ús avançat de funcions / Uso avanzado de funciones) of the course: 4 | * 22.403 - Programació per a la Ciència de Dades 5 | * 22.503 - Programación para la Ciencia de Datos 6 | 7 | 8 | -------------------------------------------------------------------------------- /python_2/unit_2/pdf/2-CAT-Ús avançat de funcions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_2/unit_2/pdf/2-CAT-Ús avançat de funcions.pdf -------------------------------------------------------------------------------- /python_2/unit_2/pdf/2-IB-Uso_avanzado_de_funciones.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_2/unit_2/pdf/2-IB-Uso_avanzado_de_funciones.pdf -------------------------------------------------------------------------------- /python_2/unit_3/.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # IPython Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # dotenv 79 | .env 80 | 81 | # virtualenv 82 | venv/ 83 | ENV/ 84 | 85 | # Spyder project settings 86 | .spyderproject 87 | 88 | # Rope project settings 89 | .ropeproject 90 | .DS_Store 91 | -------------------------------------------------------------------------------- /python_2/unit_3/README.md: -------------------------------------------------------------------------------- 1 | # Unit 3 - Files and OS interaction 2 | 3 | This is the repository of the content for unit 3 (Fitxers i interacció amb el sistema / Ficheros e interacción con el sistema) of the course: 4 | * 22.403 - Programació per a la Ciència de Dades 5 | * 22.503 - Programación para la Ciencia de Datos 6 | 7 | 8 | -------------------------------------------------------------------------------- /python_2/unit_3/data/marvel-wikia-data.csv: -------------------------------------------------------------------------------- 1 | page_id,name,urlslug,ID,ALIGN,EYE,HAIR,SEX,GSM,ALIVE,APPEARANCES,FIRST APPEARANCE,Year 2 | 1678,Spider-Man (Peter Parker),\/Spider-Man_(Peter_Parker),Secret Identity,Good Characters,Hazel Eyes,Brown Hair,Male Characters,dontknow,Living Characters,4043,Aug-62,1.962 3 | 7139,Captain America (Steven Rogers),\/Captain_America_(Steven_Rogers),Public Identity,Good Characters,Blue Eyes,White Hair,Male Characters,,Living Characters,3360,Mar-41,1.941 4 | 64786,"Wolverine (James \""Logan\"" Howlett)",\/Wolverine_(James_%22Logan%22_Howlett),Public Identity,Neutral Characters,Blue Eyes,Black Hair,Male Characters,dontknow,Living Characters,3061,Oct-74,1.974 5 | 1868,"Iron Man (Anthony \""Tony\"" Stark)",\/Iron_Man_(Anthony_%22Tony%22_Stark),Public Identity,Good Characters,Blue Eyes,Black Hair,Male Characters,,Living Characters,2961,Mar-63,1.963 6 | 2460,Thor (Thor Odinson),\/Thor_(Thor_Odinson),No Dual Identity,Good Characters,Blue Eyes,Blond Hair,Male Characters,,Living Characters,2258,Nov-50,1.950 7 | 2458,Benjamin Grimm (Earth-616),\/Benjamin_Grimm_(Earth-616),Public Identity,Good Characters,Blue Eyes,No Hair,Male Characters,,Living Characters,2255,Nov-61,1.961 8 | 2166,Reed Richards (Earth-616),\/Reed_Richards_(Earth-616),Public Identity,Good Characters,Brown Eyes,Brown Hair,Male Characters,dontknow,Living Characters,2072,Nov-61,1.961 9 | 1833,Hulk (Robert Bruce Banner),\/Hulk_(Robert_Bruce_Banner),Public Identity,Good Characters,Brown Eyes,Brown Hair,Male Characters,,Living Characters,2017,May-62,1.962 10 | 29481,Scott Summers (Earth-616),\/Scott_Summers_(Earth-616),Public Identity,Neutral Characters,Brown Eyes,Brown Hair,Male Characters,,Living Characters,1955,Sep-63,1.963 11 | 1837,Jonathan Storm (Earth-616),\/Jonathan_Storm_(Earth-616),Public Identity,Good Characters,Blue Eyes,Blond Hair,Male Characters,,Living Characters,1934,Nov-61,1.961 12 | 15725,Henry McCoy (Earth-616),\/Henry_McCoy_(Earth-616),Public Identity,Good Characters,Blue Eyes,Blue Hair,Male Characters,,Living Characters,1825,Sep-63,1.963 13 | 1863,Susan Storm (Earth-616),\/Susan_Storm_(Earth-616),Public Identity,Good Characters,Blue Eyes,Blond Hair,Female Characters,,Living Characters,1713,Nov-61,1.961 14 | 7823,Namor McKenzie (Earth-616),\/Namor_McKenzie_(Earth-616),No Dual Identity,Neutral Characters,Green Eyes,Black Hair,Male Characters,,Living Characters,,Nov-61,1.528 15 | 2614,Ororo Munroe (Earth-616),\/Ororo_Munroe_(Earth-616),Public Identity,Good Characters,Blue Eyes,White Hair,Female Characters,,Living Characters,1512,May-75,1.975 16 | 1803,Clinton Barton (Earth-616),\/Clinton_Barton_(Earth-616),Public Identity,Good Characters,Blue Eyes,Blond Hair,Male Characters,,Living Characters,1394,Sep-64,1.964 17 | 1396,Matthew Murdock (Earth-616),\/Matthew_Murdock_(Earth-616),Public Identity,Good Characters,Blue Eyes,Red Hair,Male Characters,,Living Characters,1338,Apr-64,1.964 18 | 55534,Stephen Strange (Earth-616),\/Stephen_Strange_(Earth-616),Public Identity,Good Characters,Grey Eyes,Black Hair,Male Characters,,Living Characters,1307,Jul-63,1.963 19 | 1978,Mary Jane Watson (Earth-616),\/Mary_Jane_Watson_(Earth-616),No Dual Identity,Good Characters,Green Eyes,Red Hair,Female Characters,,Living Characters,1304,Jun-65,1.965 20 | 1872,John Jonah Jameson (Earth-616),\/John_Jonah_Jameson_(Earth-616),No Dual Identity,Neutral Characters,Blue Eyes,Black Hair,Male Characters,,Living Characters,1266,Mar-63,1.963 21 | 35350,Robert Drake (Earth-616),\/Robert_Drake_(Earth-616),Secret Identity,Good Characters,Brown Eyes,Brown Hair,Male Characters,,Living Characters,1265,Sep-63,1.963 22 | 1557,Henry Pym (Earth-616),\/Henry_Pym_(Earth-616),Public Identity,Good Characters,Blue Eyes,Blond Hair,Male Characters,,Living Characters,1237,Jan-62,1.962 23 | 65255,Charles Xavier (Earth-616),\/Charles_Xavier_(Earth-616),Public Identity,Good Characters,Blue Eyes,Bald,Male Characters,,Deceased Characters,1233,Sep-63,1.963 24 | 1073,Warren Worthington III (Earth-616),\/Warren_Worthington_III_(Earth-616),Public Identity,Good Characters,Blue Eyes,Blond Hair,Male Characters,,Living Characters,1230,Sep-63,1.963 25 | 1346,Piotr Rasputin (Earth-616),\/Piotr_Rasputin_(Earth-616),Secret Identity,Good Characters,Blue Eyes,Black Hair,Male Characters,,Living Characters,1162,May-75,1.975 26 | 2512,Wanda Maximoff (Earth-616),\/Wanda_Maximoff_(Earth-616),Public Identity,Good Characters,Green Eyes,Brown Hair,Female Characters,,Living Characters,1161,Mar-64,1.964 27 | 1671,Nicholas Fury (Earth-616),\/Nicholas_Fury_(Earth-616),No Dual Identity,Neutral Characters,Brown Eyes,Brown Hair,Male Characters,,Living Characters,1137,May-63,1.963 28 | 1976,Janet van Dyne (Earth-616),\/Janet_van_Dyne_(Earth-616),Public Identity,Good Characters,Blue Eyes,Auburn Hair,Female Characters,,Living Characters,1120,Jun-63,1.963 29 | 65219,Jean Grey (Earth-616),\/Jean_Grey_(Earth-616),Public Identity,Good Characters,Green Eyes,Red Hair,Female Characters,,Deceased Characters,1107,Sep-63,1.963 30 | 6545,Natalia Romanova (Earth-616),\/Natalia_Romanova_(Earth-616),Public Identity,Good Characters,Green Eyes,Red Hair,Female Characters,Bisexual Characters,Living Characters,1050,Apr-64,1.964 31 | 2223,Kurt Wagner (Earth-616),\/Kurt_Wagner_(Earth-616),Secret Identity,Good Characters,Yellow Eyes,Blue Hair,Male Characters,,Living Characters,1047,May-75,1.975 32 | 9999,-,-,-,-,-,-,-,,-,0,-0,0 33 | -------------------------------------------------------------------------------- /python_2/unit_3/files_folder.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_2/unit_3/files_folder.zip -------------------------------------------------------------------------------- /python_2/unit_3/files_folder/a_folder_in_a_zip/file_3.txt: -------------------------------------------------------------------------------- 1 | Python was born in 1990 2 | -------------------------------------------------------------------------------- /python_2/unit_3/files_folder/a_number.txt: -------------------------------------------------------------------------------- 1 | 42 2 | -------------------------------------------------------------------------------- /python_2/unit_3/files_folder/echo_read_script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Enter a number" 4 | read number 5 | echo "Your number was $number" 6 | -------------------------------------------------------------------------------- /python_2/unit_3/files_folder/echo_script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Script executed!" 4 | -------------------------------------------------------------------------------- /python_2/unit_3/files_folder/endless_script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | while true 4 | do 5 | sleep 1 6 | done 7 | -------------------------------------------------------------------------------- /python_2/unit_3/files_folder/file_1.txt: -------------------------------------------------------------------------------- 1 | Beautiful is better than ugly. 2 | Explicit is better than implicit. 3 | Simple is better than complex. 4 | Complex is better than complicated. 5 | Flat is better than nested. 6 | Sparse is better than dense. 7 | Readability counts. 8 | Special cases aren't special enough to break the rules. 9 | Although practicality beats purity. 10 | Errors should never pass silently. 11 | Unless explicitly silenced. 12 | In the face of ambiguity, refuse the temptation to guess. 13 | There should be one-- and preferably only one --obvious way to do it. 14 | Although that way may not be obvious at first unless you're Dutch. 15 | Now is better than never. 16 | Although never is often better than *right* now. 17 | If the implementation is hard to explain, it's a bad idea. 18 | If the implementation is easy to explain, it may be a good idea. 19 | Namespaces are one honking great idea -- let's do more of those! 20 | -------------------------------------------------------------------------------- /python_2/unit_3/files_folder/file_2.txt: -------------------------------------------------------------------------------- 1 | Guido van Rossum 2 | -------------------------------------------------------------------------------- /python_2/unit_3/files_folder/original_file.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_2/unit_3/files_folder/original_file.txt -------------------------------------------------------------------------------- /python_2/unit_3/files_folder/zip_with_multiple_files.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_2/unit_3/files_folder/zip_with_multiple_files.zip -------------------------------------------------------------------------------- /python_2/unit_3/pdf/3-CAT-Fitxers_i_interacció_amb_el_sistema.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_2/unit_3/pdf/3-CAT-Fitxers_i_interacció_amb_el_sistema.pdf -------------------------------------------------------------------------------- /python_2/unit_3/pdf/3-ES-Ficheros_e_interacción_con_el_sistema.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_2/unit_3/pdf/3-ES-Ficheros_e_interacción_con_el_sistema.pdf -------------------------------------------------------------------------------- /python_2/unit_4/.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # IPython Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # dotenv 79 | .env 80 | 81 | # virtualenv 82 | venv/ 83 | ENV/ 84 | 85 | # Spyder project settings 86 | .spyderproject 87 | 88 | # Rope project settings 89 | .ropeproject 90 | .DS_Store 91 | -------------------------------------------------------------------------------- /python_2/unit_4/README.md: -------------------------------------------------------------------------------- 1 | # Unit 4 - Optimization: complexity and profiling 2 | 3 | This is the repository of the content for unit 4 (Optimització: Complexitat i profiling / Optimización: Complejidad y profiling) of the course: 4 | * 22.403 - Programació per a la Ciència de Dades 5 | * 22.503 - Programación para la Ciencia de Datos 6 | 7 | 8 | -------------------------------------------------------------------------------- /python_2/unit_4/pdf/4-CAT-Optimització_complexitat_i_profiling.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_2/unit_4/pdf/4-CAT-Optimització_complexitat_i_profiling.pdf -------------------------------------------------------------------------------- /python_2/unit_4/pdf/4-ES-Optimización_complejidad_y_profiling.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_2/unit_4/pdf/4-ES-Optimización_complejidad_y_profiling.pdf -------------------------------------------------------------------------------- /python_2/unit_5/.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # IPython Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # dotenv 79 | .env 80 | 81 | # virtualenv 82 | venv/ 83 | ENV/ 84 | 85 | # Spyder project settings 86 | .spyderproject 87 | 88 | # Rope project settings 89 | .ropeproject 90 | .DS_Store 91 | -------------------------------------------------------------------------------- /python_2/unit_5/README.md: -------------------------------------------------------------------------------- 1 | # Unit 5 - Optimization: concurrency and parallelism 2 | 3 | This is the repository of the content for unit 5 (Optimització: Concurrència i paral·lelisme / Optimización: Concurrencia y paralelismo) of the course: 4 | * 22.403 - Programació per a la Ciència de Dades 5 | * 22.503 - Programación para la Ciencia de Datos 6 | 7 | 8 | -------------------------------------------------------------------------------- /python_2/unit_5/img/concurrencia_cat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_2/unit_5/img/concurrencia_cat.png -------------------------------------------------------------------------------- /python_2/unit_5/img/concurrencia_ib.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_2/unit_5/img/concurrencia_ib.png -------------------------------------------------------------------------------- /python_2/unit_5/pdf/5-CAT-Optimització_paral·lelisme_i_concurrencia.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_2/unit_5/pdf/5-CAT-Optimització_paral·lelisme_i_concurrencia.pdf -------------------------------------------------------------------------------- /python_2/unit_5/pdf/5-ES-Optimización_paralelismo_y_concurrencia.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_2/unit_5/pdf/5-ES-Optimización_paralelismo_y_concurrencia.pdf -------------------------------------------------------------------------------- /python_2/unit_6/README.md: -------------------------------------------------------------------------------- 1 | # Unit 6 - Testing, deployment and maintenance 2 | 3 | This is the repository of the content for unit 6 (Testing, manteniment i desplegament d'aplicacions Python / Testing, mantenimiento y despliegue de aplicaciones Python) of the course: 4 | * 22.403 - Programació per a la Ciència de Dades 5 | * 22.503 - Programación para la Ciencia de Datos 6 | 7 | 8 | -------------------------------------------------------------------------------- /python_2/unit_6/img/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_2/unit_6/img/1.png -------------------------------------------------------------------------------- /python_2/unit_6/img/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_2/unit_6/img/10.png -------------------------------------------------------------------------------- /python_2/unit_6/img/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_2/unit_6/img/11.png -------------------------------------------------------------------------------- /python_2/unit_6/img/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_2/unit_6/img/2.png -------------------------------------------------------------------------------- /python_2/unit_6/img/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_2/unit_6/img/3.png -------------------------------------------------------------------------------- /python_2/unit_6/img/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_2/unit_6/img/4.png -------------------------------------------------------------------------------- /python_2/unit_6/img/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_2/unit_6/img/5.png -------------------------------------------------------------------------------- /python_2/unit_6/img/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_2/unit_6/img/6.png -------------------------------------------------------------------------------- /python_2/unit_6/img/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_2/unit_6/img/7.png -------------------------------------------------------------------------------- /python_2/unit_6/img/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_2/unit_6/img/8.png -------------------------------------------------------------------------------- /python_2/unit_6/img/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_2/unit_6/img/9.png -------------------------------------------------------------------------------- /python_2/unit_6/img/arquitectura_cat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_2/unit_6/img/arquitectura_cat.png -------------------------------------------------------------------------------- /python_2/unit_6/img/arquitectura_ib.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_2/unit_6/img/arquitectura_ib.png -------------------------------------------------------------------------------- /python_2/unit_6/img/py_cat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_2/unit_6/img/py_cat.png -------------------------------------------------------------------------------- /python_2/unit_6/img/py_ib.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_2/unit_6/img/py_ib.png -------------------------------------------------------------------------------- /python_2/unit_6/pdf/6-CAT-Testing_manteniment_desplegament.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_2/unit_6/pdf/6-CAT-Testing_manteniment_desplegament.pdf -------------------------------------------------------------------------------- /python_2/unit_6/pdf/6-IB-Testing_matenimiento_y_despliegue.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cpsola/python_datascience/5d5545d1774d9617e74274a63a2667ea7fdb631f/python_2/unit_6/pdf/6-IB-Testing_matenimiento_y_despliegue.pdf -------------------------------------------------------------------------------- /python_2/unit_6/pycharm/covid/basic_analysis.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | from utils import get_unique_values, get_max_cases, get_max_deaths 3 | 4 | if __name__ == "__main__": 5 | 6 | # Load dataset 7 | df = pd.read_csv("data/COVID-19.csv") 8 | 9 | # Print number of unique values for some columns 10 | print("Year:\t\t\t{}".format(get_unique_values(df, "year"))) 11 | print("Countries:\t\t{}".format(get_unique_values(df, "countriesAndTerritories"))) 12 | print("GeoId:\t\t\t{}".format(get_unique_values(df, "geoId"))) 13 | print("Continents:\t\t{}".format(get_unique_values(df, "continentExp"))) 14 | 15 | # Print max cases and deaths per country 16 | c, m = get_max_cases(df) 17 | print("Max. cases:\t\t{} ({})".format(m, c)) 18 | c, m = get_max_deaths(df) 19 | print("Max. deaths:\t{} ({})".format(m, c)) 20 | -------------------------------------------------------------------------------- /python_2/unit_6/pycharm/covid/requirements.txt: -------------------------------------------------------------------------------- 1 | pandas~=1.0.3 -------------------------------------------------------------------------------- /python_2/unit_6/pycharm/covid/tests/test.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import pandas as pd 3 | from utils import get_unique_values, get_max_cases, get_max_deaths 4 | 5 | 6 | class TestDataExpl(unittest.TestCase): 7 | 8 | @classmethod 9 | def setUpClass(cls): 10 | print("Loading dataset") 11 | cls._df = pd.read_csv("../data/COVID-19.csv") 12 | 13 | def test_unique_counts(self): 14 | print("Starting test_unique_counts") 15 | self.assertEqual(get_unique_values(self._df, "year"), 2) 16 | self.assertEqual(get_unique_values(self._df, "countriesAndTerritories"), 209) 17 | self.assertEqual(get_unique_values(self._df, "geoId"), 209) 18 | self.assertEqual(get_unique_values(self._df, "continentExp"), 6) 19 | 20 | def test_max_cases(self): 21 | print("Starting test_max_cases") 22 | c, m = get_max_cases(self._df) 23 | self.assertEqual(c, 'United_States_of_America') 24 | self.assertEqual(m, 1158041) 25 | 26 | def test_max_deaths(self): 27 | print("Starting test_max_deaths") 28 | c, m = get_max_deaths(self._df) 29 | self.assertEqual(c, 'United_States_of_America') 30 | self.assertEqual(m, 67682) 31 | 32 | 33 | suite = unittest.TestSuite() 34 | suite.addTest(unittest.makeSuite(TestDataExpl)) 35 | unittest.TextTestRunner(verbosity=2).run(suite) -------------------------------------------------------------------------------- /python_2/unit_6/pycharm/covid/utils.py: -------------------------------------------------------------------------------- 1 | def get_unique_values(df, col): 2 | """ 3 | Return the number of unique values in the column `col` 4 | for the dataframe `df`. 5 | """ 6 | return len(df[col].unique()) 7 | 8 | 9 | def get_max_cases(df): 10 | """ 11 | Return the country with the maximum number of cases 12 | detected overall period. 13 | """ 14 | sum_of_cases = df.groupby("countriesAndTerritories").sum()["cases"] 15 | m = sum_of_cases.max() 16 | c = sum_of_cases[sum_of_cases == m].index[0] 17 | return c, m 18 | 19 | 20 | def get_max_deaths(df): 21 | """ 22 | Return the country with the maximum number of cases 23 | detected overall period. 24 | """ 25 | sum_of_deaths = df.groupby("countriesAndTerritories").sum()["deaths"] 26 | m = sum_of_deaths.max() 27 | c = sum_of_deaths[sum_of_deaths == m].index[0] 28 | return c, m 29 | 30 | -------------------------------------------------------------------------------- /python_2/unit_6/python_code/hello_world.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ python 2 | # -*- coding: utf-8 -*- 3 | 4 | 5 | def to_upper(x): 6 | return x.upper() 7 | 8 | 9 | if __name__ == "__main__": 10 | print(to_upper("Hello world!")) 11 | 12 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | jupyter==1.0.0 2 | matplotlib==3.1.1 3 | scipy==1.3.0 4 | pandas==0.25.0 5 | numpy==1.17.0 6 | Scrapy==1.7.3 7 | googlemaps==3.0.2 8 | tweepy==3.8.0 9 | sklearn==0.0 10 | sympy==1.5.1 11 | seaborn==0.9.0 12 | networkx==2.3 13 | python-louvain==0.13 14 | pyglet==1.4.1 15 | line_profiler 16 | flake8 17 | pycodestyle_magic 18 | --------------------------------------------------------------------------------