Commit d3fcd807 authored by cbanchoff's avatar cbanchoff
Browse files

Agregué las teroías

parent 91dc1ca0
...@@ -6,6 +6,7 @@ ser las prácticas, guías, explicaciones o algunos ejemplos. ...@@ -6,6 +6,7 @@ ser las prácticas, guías, explicaciones o algunos ejemplos.
## Índice ## Índice
- [Prácticas](./practicas) - [Prácticas](./practicas)
- [Teorías](./teorias)
- [Guías](./guias) - [Guías](./guias)
- [Instalación de Python](./guias/instalacion_python.ipynb) - [Instalación de Python](./guias/instalacion_python.ipynb)
- [Git](./guias/guia_git.ipynb) - [Git](./guias/guia_git.ipynb)
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
{
"cells": [
{
"cell_type": "markdown",
"id": "younger-ready",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Seminario de Lenguajes - Python\n",
"## Cursada 2021\n",
"### Clase 5"
]
},
{
"cell_type": "markdown",
"id": "first-satisfaction",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"## Comentamos el ejemplo que dejé en el video: ¿algo está mal?"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "extensive-printing",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"def leo_caracteres():\n",
" f = open(\"imagine.txt\",\"r\")\n",
" for x in f.read():\n",
" print(x)\n",
" f.close()"
]
},
{
"cell_type": "markdown",
"id": "gorgeous-force",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# CSV: ¿más formatos?\n",
"\n",
"\n",
"- CSV (Comma Separated Values).\n",
"- Es un formato muy común para importar/exportar desde/hacia hojas de cálculo y bases de datos.\n",
"- Ejemplo:\n",
"\n",
"```\n",
"nombre,ciudad,ref\n",
"William Campbell,La Plata,www.instagram.com/williamcampbellok\n",
"Buendia,La Plata,https://buendia.bandcamp.com/\n",
"Lúmine,La Plata,https://www.instagram.com/luminelp/\n",
"```\n",
"- +Info: https://docs.python.org/3/library/csv.html\n",
"- [PEP 305](https://www.python.org/dev/peps/pep-0305/)"
]
},
{
"cell_type": "markdown",
"id": "advanced-offering",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"# Datasets\n",
"\n",
"- Hay muchos datasets disponibles de muchas temáticas:\n",
"- En nuestro país:\n",
" - Datos de [Argentina](https://datos.gob.ar/dataset)\n",
" - Datos de [CABA](https://data.buenosaires.gob.ar/)\n",
" - Datos de [La Plata](https://catalogodatos.laplata.gob.ar/dataset)\n",
"- Otros:\n",
" - https://data.world/\n",
" - https://www.kaggle.com/\n",
" - https://www.imdb.com/interfaces/\n",
" - Y muchos más..."
]
},
{
"cell_type": "markdown",
"id": "southwest-minister",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
" ## Muchos son datos abiertos, pero otros... no tanto...\n",
" \n",
" ### ¡PRESTAR ATENCIÓN a la licencias y requisitos para su uso!\n"
]
},
{
"cell_type": "markdown",
"id": "returning-pioneer",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"# ¿Qué vemos en netflix? \n",
"\n",
"Vamos a trabajar con el archivo: [netflix_titles.csv](https://www.kaggle.com/shivamb/netflix-shows)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "robust-reynolds",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"import csv\n",
"\n",
"archivo = open(\"ejemplos/clase5/netflix_titles.csv\", \"r\")\n",
"csvreader = csv.reader(archivo, delimiter=',')\n",
"\n",
"#encabezado = csvreader.__next__()\n",
"encabezado = next(csvreader)\n",
"\n",
"print(encabezado)\n",
"print(\"Titulo\"+\" \"*35+\"Director\")\n",
"for linea in csvreader:\n",
" if linea[1] == \"TV Show\" and linea[5] == \"Argentina\": \n",
" print(f\"{linea[2]:<40} {linea[3]}\")\n",
"\n",
"archivo.close()"
]
},
{
"cell_type": "markdown",
"id": "existing-dating",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"# El módulo cvs\n",
"\n",
"- Hay que importarlo.\n",
"- **csv.reader**: cea un objeto \"iterador\" que nos permite recorrer las líneas del archivo.\n",
"- ¿De qué tipo es línea?\n",
"- ¿Por qué incluimos el paŕametro **delimiter**? ¿Dialectos?"
]
},
{
"cell_type": "markdown",
"id": "palestinian-batch",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"# Otra solución ..."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "pending-jamaica",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"import csv\n",
"archivo = open(\"ejemplos/clase5/netflix_titles.csv\", \"r\")\n",
"csvreader = csv.reader(archivo, delimiter=',')\n",
"\n",
"shows_ar = filter(lambda x: x[5] == \"Argentina\" and x[1] == \"TV Show\", csvreader)\n",
"for elem in shows_ar:\n",
" print(f\"{elem[2]:<40} {elem[3]}\")\n",
" \n",
"#print(shows_ar)\n",
"archivo.close()"
]
},
{
"cell_type": "markdown",
"id": "stunning-morgan",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"# Creamos nuestro archivo csv de bandas de música"
]
},
{
"cell_type": "markdown",
"id": "sustained-assist",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"- **csv.writer:** retorna un objeto que convierte los datos con los que trabajamos en el prorgrama en cadenas con el formato delimitadas con el separador correspondiente. "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "flexible-threshold",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"import csv\n",
"import json\n",
"\n",
"archivo = open(\"bandas.txt\")\n",
"archivo_csv = open(\"bandas.csv\", \"w\")\n",
"\n",
"bandas = json.load(archivo)\n",
"datos_a_mostrar = json.dumps(bandas, indent=4)\n",
"print(datos_a_mostrar)\n",
"\n",
"writer = csv.writer(archivo_csv)\n",
"writer.writerow([\"Nombre\", \"Ciudad de procedencia\", \"Refencias\"])\n",
"for banda in bandas:\n",
" writer.writerow([banda[\"nombre\"], banda[\"ciudad\"], banda[\"ref\"]])\n",
"\n",
"archivo.close()\n",
"archivo_csv.close()"
]
},
{
"cell_type": "markdown",
"id": "removed-praise",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"# Lo leemos"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "different-format",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"archivo_cvs = open(\"bandas.csv\", \"r\")\n",
"csvreader = csv.reader(archivo_cvs, delimiter=',')\n",
"\n",
"for linea in csvreader:\n",
" print(linea)\n",
"\n",
"archivo_csv.close()"
]
},
{
"cell_type": "markdown",
"id": "pregnant-europe",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Primer desafío \n",
"\n",
"- Dado el conjunto de datos con series y películas de Netflix, queremos:\n",
"\n",
" 1- guardar en otro archivo las peliculas agregadas en el año 2020.\n",
"\n",
" 2- los cinco (5) países con más producciones en Netflix.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "military-draft",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"# Solución....."
]
},
{
"cell_type": "markdown",
"id": "incorrect-apparatus",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"## Los que quieran, compartir solución con @clauBanchoff\n",
"\n",
"- Recuerden mandarme mensaje para revisar."
]
},
{
"cell_type": "markdown",
"id": "apparent-asset",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# ¿Saben qué son las GUI?"
]
},
{
"cell_type": "markdown",
"id": "advance-direction",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"## GUI: Graphical User Interface"
]
},
{
"cell_type": "markdown",
"id": "further-chase",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"<img src=\"imagenes/SimpleGUI_todo.png\" alt=\"nos vemos el martes\" style=\"width:550px;\"/>"
]
},
{
"cell_type": "markdown",
"id": "changed-toner",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"\n",
"# GUI en Python\n",
"\n",
"- Vamos a usar [PySimpleGUI](https://pysimplegui.readthedocs.io/en/latest/)\n",
"\n",
"- Es un **framework** bastante simple para desarrollar interfaces gráficas en Python.\n",
"- Es software libre: https://github.com/PySimpleGUI/PySimpleGUI\n",
"- Se instala con pip: **pip install pysimplegui**\n",
"\n",
"- Vamos a ir de a poco...\n",
"- Más info en: https://pysimplegui.readthedocs.io/en/latest/cookbook/\n",
"- También en https://realpython.com/pysimplegui-python/\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"id": "spoken-fiction",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"# ¿Con qué elementos podemos trabajar?\n",
"\n",
"<img src=\"imagenes/SimpleGUI_todoElementos.png\" alt=\"nos vemos el martes\" style=\"width:1050px;\"/>"
]
},
{
"cell_type": "markdown",
"id": "scenic-paintball",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"# Popups: las ventanas más sencillas"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "sound-desire",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"import PySimpleGUI as sg \n",
"sg.Popup('Mi primera ventanita')"
]
},
{
"cell_type": "markdown",
"id": "combined-sapphire",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"- **import PySimpleGUI as sg**, permite acceder a los recursos por el nombre **sg**."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "lucky-resort",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"import PySimpleGUI as sg \n",
"\n",
"sg.Popup('Mi primera ventanita', button_color=('black', 'red'))\n",
"\n",
"sg.PopupYesNo('Mi primera ventanita', button_color=('black', 'green'))\n",
"\n",
"sg.PopupOKCancel('Mi primera ventanita', button_color=('black', 'grey'))\n",
"\n",
"texto = sg.PopupGetText('Titulo', 'Ingresá algo') \n",
"sg.Popup('Resultados', 'Ingresaste el siguiente texto: ', texto)"
]
},
{
"cell_type": "markdown",
"id": "informational-hamburg",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"# Creamos una ventana en PySimpleGUI"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "concrete-console",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"import PySimpleGUI as sg\n",
"\n",
"sg.Window(title=\"Hola Mundo!\", layout=[[]], margins=(100, 50)).read()"
]
},
{
"cell_type": "markdown",
"id": "descending-kidney",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"- **margins**: tamaño de la ventana en pixeles.\n",
"- **read()**: devuelve los eventos que se produzca al activar la ventana."
]
},
{
"cell_type": "markdown",
"id": "rolled-fisher",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"# Sobre los eventos"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "naval-violence",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"import PySimpleGUI as sg \n",
"\n",
"layout = [[sg.Text(\"Hola Mundo!\")], [sg.Button(\"OK\")]]\n",
"\n",
"window = sg.Window(\"Primer Demo\", layout, margins=(200, 150))\n",
"\n",
"while True:\n",
" event, values = window.read()\n",
"\n",
" if event == \"OK\" or event == sg.WIN_CLOSED:\n",
" break\n",
"\n",
"window.close()"
]
},
{
"cell_type": "markdown",
"id": "compact-bandwidth",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"# ¿Cómo recuperamos los valores ingresados desde la UI?"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "demanding-account",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"import PySimpleGUI as sg\n",
"\n",
"layout = [ [sg.Text('Ingresá primer valor'), sg.InputText()],\n",
" [sg.Text('Ingresá segundo valor'), sg.InputText()],\n",
" [sg.Button('Ok'), sg.Button('Cancel')] ]\n",
"\n",
"window = sg.Window(\"Segundo Demo\", layout, margins=(200, 150))\n",
"\n",
"while True:\n",
" event, values = window.read()\n",
"\n",
" if event == \"Cancel\" or event == sg.WIN_CLOSED:\n",
" break\n",
" print('Datos ingresados: ', values)\n",
"\n",
"window.close()"
]
},
{
"cell_type": "markdown",
"id": "occupied-calculation",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"# Layout: ¿cómo organizamos la UI?\n",
"\n",
"\n",
"Representa al esquema o diseño de nuestra UI: **cómo se distribuyen los elementos en la UI**.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "committed-penetration",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [],
"source": [
"layout = [ [sg.Text('Ingresá primer valor'), sg.InputText()],\n",
" [sg.Text('Ingresá segundo valor'), sg.InputText()],\n",
" [sg.Button('Ok'), sg.Button('Cancel')] ]"
]
},
{
"cell_type": "markdown",
"id": "bulgarian-doctor",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"- ¿De qué tipo es la variable layout?\n",
"- ¿Qué elementos estamos incluyendo?"
]
},
{
"cell_type": "markdown",