informatica:programacion:python:modulos:pandas
Diferencias
Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anteriorRevisión previaPróxima revisión | Revisión previa | ||
| informatica:programacion:python:modulos:pandas [2021/11/05 14:42] – [Métodos] tempwin | informatica:programacion:python:modulos:pandas [2021/11/08 16:11] (actual) – [Filtrar registros Excel] tempwin | ||
|---|---|---|---|
| Línea 110: | Línea 110: | ||
| * '' | * '' | ||
| * '' | * '' | ||
| - | * '' | + | * '' |
| * '' | * '' | ||
| * '' | * '' | ||
| Línea 1229: | Línea 1229: | ||
| output.to_excel(" | output.to_excel(" | ||
| </ | </ | ||
| + | |||
| + | ==== Titanic ==== | ||
| + | |||
| + | Partiendo de un CSV con información sobre pasajeros: | ||
| + | |||
| + | <code python> | ||
| + | import pandas as pd | ||
| + | |||
| + | fname = ' | ||
| + | |||
| + | data = pd.read_csv(fname) | ||
| + | </ | ||
| + | |||
| + | Ver si hay campos vacíos: | ||
| + | |||
| + | <code python> | ||
| + | data.count() | ||
| + | </ | ||
| + | |||
| + | Valores mínimos y máximos de edad: | ||
| + | |||
| + | <code python> | ||
| + | data[' | ||
| + | </ | ||
| + | |||
| + | Distribución de valores de supervivientes: | ||
| + | |||
| + | <code python> | ||
| + | data[' | ||
| + | </ | ||
| + | |||
| + | En términos porcentuales: | ||
| + | |||
| + | <code python> | ||
| + | data[' | ||
| + | </ | ||
| + | |||
| + | Distribución por sexo: | ||
| + | |||
| + | <code python> | ||
| + | data[' | ||
| + | </ | ||
| + | |||
| + | Distribución por tipo de pasajero: | ||
| + | |||
| + | <code python> | ||
| + | data[' | ||
| + | </ | ||
| + | |||
| + | Representación gráfica (en notebook de Jupyter): | ||
| + | |||
| + | <code python> | ||
| + | %matplotlib inline | ||
| + | |||
| + | alpha_color = 0.5 | ||
| + | |||
| + | # Distribución se supervivientes | ||
| + | data[' | ||
| + | </ | ||
| + | |||
| + | Distribución gráfica por sexo: | ||
| + | |||
| + | <code python> | ||
| + | data[' | ||
| + | color=[' | ||
| + | alpha=alpha_color) | ||
| + | </ | ||
| + | |||
| + | Distribución gráfica por clase de pasajeros: | ||
| + | |||
| + | <code python> | ||
| + | data[' | ||
| + | alpha=alpha_color) | ||
| + | </ | ||
| + | |||
| + | Comparando gráficamente supervivientes con edades: | ||
| + | |||
| + | <code python> | ||
| + | data.plot(kind=' | ||
| + | </ | ||
| + | |||
| + | Comparando gráficamente supervivientes con tramos de edades: | ||
| + | |||
| + | <code python> | ||
| + | bins = [0, 10, 20, 30, 40, 50, 60, 70, 80] | ||
| + | |||
| + | data[' | ||
| + | |||
| + | data[data[' | ||
| + | </ | ||
| + | |||
| + | Gráficamente los que no sobrevivieron: | ||
| + | |||
| + | <code python> | ||
| + | data[data[' | ||
| + | </ | ||
| + | |||
| + | <code python> | ||
| + | data[' | ||
| + | </ | ||
| + | |||
| + | Pasajeros de primera clase que sobrevivieron: | ||
| + | |||
| + | <code python> | ||
| + | data[data[' | ||
| + | </ | ||
| + | |||
| + | Pasajeros de tercera clase que sobrevivieron: | ||
| + | |||
| + | <code python> | ||
| + | data[data[' | ||
| + | </ | ||
| + | |||
| + | Pasajeros de género masculino que sobrevivieron: | ||
| + | |||
| + | <code python> | ||
| + | data[data[' | ||
| + | </ | ||
| + | |||
| + | Pasajeros de género femenino que sobrevivieron: | ||
| + | |||
| + | <code python> | ||
| + | data[data[' | ||
| + | </ | ||
| + | |||
| + | Pasajeros de género masculino y primera clase que sobrevivieron: | ||
| + | |||
| + | <code python> | ||
| + | data[(data[' | ||
| + | </ | ||
| + | |||
| + | Pasajeros de género masculino y tercera clase que sobrevivieron: | ||
| + | |||
| + | <code python> | ||
| + | data[(data[' | ||
| + | </ | ||
| + | |||
| + | Pasajeros de género femenino y primera clase que sobrevivieron: | ||
| + | |||
| + | <code python> | ||
| + | data[(data[' | ||
| + | </ | ||
| + | |||
| + | Pasajeros de género femenino y tercera clase que sobrevivieron: | ||
| + | |||
| + | <code python> | ||
| + | data[(data[' | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== Recursos ===== | ||
| + | |||
| + | * https:// | ||
informatica/programacion/python/modulos/pandas.1636119738.txt.gz · Última modificación: por tempwin
