introducción a jupyter (antes i python notebook)

39
INTRODUCCIÓN A JUPYTER (ANTES CONOCIDO COMO IPYTHON NOTEBOOK) POR JUAN IGNACIO RODRÍGUEZ DE LEÓN (@JILEON EN TWITTER, @EURIBATES EN TELEGRAM) Fuentes en https://github.com/euribates/Jupyter-Intro

Upload: juan-rodriguez

Post on 07-Apr-2017

134 views

Category:

Science


3 download

TRANSCRIPT

Page 1: Introducción a jupyter (antes i python notebook)

INTRODUCCIÓN A

JUPYTER(ANTES CONOCIDO COMO IPYTHON NOTEBOOK)

POR JUAN IGNACIO RODRÍGUEZ DE LEÓN (@JILEON EN TWITTER, @EURIBATES ENTELEGRAM)

Fuentes en https://github.com/euribates/Jupyter-Intro

Page 2: Introducción a jupyter (antes i python notebook)

SOBRE LA INSTALACIÓNNormalmente, se usa Jupyter junto a varias librerías:Numpy, Pandas, Scipy, Matplotlib, etc...

Si ya usas Python, puedes usar pip para instalarJupyter. El resto de librerías puede ser máscomplicadoSi eres nuevo, te recomiendo usar Anaconda:Instala Jupyter y un montón de librerías yacompiladas, super sencillo y válido paraMac/Windows/Linux

keywords: Install Anaconda

Page 3: Introducción a jupyter (antes i python notebook)

EVOLUCIÓN HISTÓRICAiPythoniPython notebookJupyter notebook (Language agnostic)

Page 4: Introducción a jupyter (antes i python notebook)

ARQUITECTURA DE IJUPYTERMUUUY SIMPLIFICADA

WebNotebook

iPythonTerminal

iPython Kernel 

ZeroMQ

Page 5: Introducción a jupyter (antes i python notebook)

JUPYTER SE DESVINCULA DE IPYTHONSe de�ne claramente la interfaz entre el notebook yel nucleoAhora podemos reemplazar el nucleo de iPython porotro, siempre que cumpla la misma interfaziPython sigue siendo el kernel por defecto, peropueden añadirse otros

Page 7: Introducción a jupyter (antes i python notebook)

Y MÁS...

... muchos más: , , , , ...Lista completa en

Keywords: Jupyter kernel [Tu lenguajefavorito aquí]

RubyHaskellNode.js

Go Scala Octave Bash Rust

https://github.com/jupyter/jupyter/wiki/Jupyter-kernels

Page 8: Introducción a jupyter (antes i python notebook)

¿QUÉ ES IPYTHON?

Page 9: Introducción a jupyter (antes i python notebook)

IPYTHON ES PYTHON CON SUPERPODERES

Page 10: Introducción a jupyter (antes i python notebook)

UN INTERPRETE DE PYTHON AMPLIADOPuede hacer todo lo que un interprete normal, y más:

Comandos "mágicos"Coloreado de sintaxisAutocompletado de códigoIntrospecciónMejores ayudas, documentación, debugging, etc...

Page 11: Introducción a jupyter (antes i python notebook)

¿CÓMO LO HACE?while True: orden = espera_orden() if orden.es_especial: procesa_orden_interna(orden) else: salida = ejecuta_en_python(orden) print(salida)

Page 12: Introducción a jupyter (antes i python notebook)

EJEMPLO DE LAS CAPACIDADES DE IPYTHON ⚙Desde la consola, escribimos: ipython

Page 13: Introducción a jupyter (antes i python notebook)

COMANDOS MÁGICOSSon ordenes propias de iPythonSiempre empiezan por % o %%

% para ordenes que afecta una sola línea%% para ordenes que afectan a toda una celda

Page 14: Introducción a jupyter (antes i python notebook)

(ALGUNOS) COMANDOS MÁGICOS ⚙%who y %whos muestran variables de�nidas en elespacio actual%lsmagic es una orden mágica que lista todas lasordenes mágicas disponibles%timeit y %%timeit realizan un informe deltiempo de ejecución de una línea o un fragmento decódigo

Keywords: iPython magic commands

Page 15: Introducción a jupyter (antes i python notebook)

AYUDAS Y COMPLETADO DE SINTAXIS ⚙Pulsando TABOjo, realiza introspección de lo que tenga enmemoria.Lo que no está cargado, lo desconocePodemos pedir ayuda de cualquier comando, mágicoo de python, con ? , antes o despues

Page 16: Introducción a jupyter (antes i python notebook)

¿QUÉ ES UN NOTEBOOK?

Page 17: Introducción a jupyter (antes i python notebook)

UNA DEFINICIÓNCOMO CUALQUIER OTRA

Una aplicación web, que permite ejecutar código a lavez que representar texto con formato, incluyendoimágenes, diagramas y ecuaciones matemáticas de

forma integrada

Page 18: Introducción a jupyter (antes i python notebook)

¿PARA QUÉ SIRVE?Consola Python en webRealización de análisis y estudiosInformes en vivoPanel de mandoPublicaciones interactivas

Page 19: Introducción a jupyter (antes i python notebook)

CARACTERÍSTICAS DE LOS NOTEBOOKSFáciles de compartirAutocontenidosRepetiblesVeri�cablesModi�cables

Page 20: Introducción a jupyter (antes i python notebook)

ARRANQUEMOS JUPYTER ⚙Desde la consola, ejecutar jupyter notebook

Page 21: Introducción a jupyter (antes i python notebook)

CREAR UN NUEVO NOTEBOOK ⚙A la Derecha, elegimos New → Python 3

Page 22: Introducción a jupyter (antes i python notebook)

ALGUNOS EJERCICIOS ⚙Cambiar el título del notebookVer que el cambio del nombre se re�eja en eldashboardAñadir un �chero al directorio desde el quearrancamos Jupyter, por ejemplo, en línea decomando: touch notas.mdVer que el dashboard re�eja el cambio, sin necesidadde refrescar

Page 23: Introducción a jupyter (antes i python notebook)

ANATOMIA DE UN NOTEBOOK

Page 24: Introducción a jupyter (antes i python notebook)

UN NOTEBOOK SE DIVIDE EN CELDASNOTEBOOK = LISTA DE CELDAS + METADATOS

Page 25: Introducción a jupyter (antes i python notebook)

HAY VARIOS TIPOS DE CELDAS

Celda de textoCelda de códigoCelda de resultados

Page 26: Introducción a jupyter (antes i python notebook)

CELDA DE TEXTO

Aceptan markdown, y Html, con lo que podemosdarle formato a los textos muy facilmentePodemos incluir fórmulas matemáticas usando elformato de

Keywords: Latex Markdown MathJax Jupyter

LaTex

Page 27: Introducción a jupyter (antes i python notebook)

EJEMPLO DE CELDA DE TEXTO ⚙

Insertar texto en Markdown: negritas, itálicas, unalista...Insertar texto en Html: un párrafo, una imagen...Insertar una formula matemática

Page 28: Introducción a jupyter (antes i python notebook)

CELDA DE CÓDIGO ⚙

Imprimir los pares hasta el 20Cargar y mostrar una imagenCrear un thumbnail de la imagen anterior y mostrarloRecortar una parte de la imagen y mostrarla

Keywords: Pillow Python Image Library

Page 29: Introducción a jupyter (antes i python notebook)

CELDA DE RESULTADOSLo que hemos visto en los resultados anteriorJupyter reconoce tipos de datos diferentes y lospuede representarIncluir HTML es superpotente

Page 30: Introducción a jupyter (antes i python notebook)

INCUIR UN VIDEO DE YOUTUBE ⚙Usa el comando mágico %%HTMLBusca en compartir vídeo en YouTube, luego embebGuardianes de la galaxia Vol 2 va a ser la caña

Page 31: Introducción a jupyter (antes i python notebook)

COSAS QUE NO TENEMOS TIEMPO DE VERPERO QUE RESULTAN INTERESANTES

Page 32: Introducción a jupyter (antes i python notebook)

TODAS LAS FANTÁSTICAS LIBRERÍAS CIENTÍFICAS YMATEMÁTICAS: NUMPY, PANDAS, MATPLOTLIB, SCIPY...

... pero no te pierdas el siguiente taller, te gustará

Page 33: Introducción a jupyter (antes i python notebook)

COMPARTIR Y CONVERTIR A OTROS FORMATOSEl formato ipynb es el formato estandar paracompartir. Es JSON sencillo. Su estructura esmetadatos más lista de celdas. Puedes enviarlo porcorreo, hacer control de versiones, ponerlo en laweb...Convertir a Html estáticoConvertir a PDF vía LatexConvertir a Restructured TextConvertir a Python / Markdown

Keywords: nbconvert

Page 34: Introducción a jupyter (antes i python notebook)

USO DE OTROS KERNELS (LENGUAJES)Hay para elegir

Page 35: Introducción a jupyter (antes i python notebook)

PROCESAMIENTO EN PARALELOPodemos controlar ejecución en parelelo desde un

notebook sobre multiples maquindas. Muy interesantepara todo lo que sea BigData

Keywords: pyparellel

Page 36: Introducción a jupyter (antes i python notebook)

ESCRIBIR NUESTROS PROPIOS KERNELSHAY DOS OPCIONES

Implementar el protocolo de comunicaciones conZeroMQ desde el lenguaje que queremos añadir

Más complicado, pero es tu lenguaje favorito. Tucomunidad puede apoyarte.

Usar un wrapper en pythonLas interfaces de comunicaciones ya estáncreadas, por lo que es más simple.Pero puede quetu lenguaje no se deje wrappear facilmente

Page 37: Introducción a jupyter (antes i python notebook)

COMPARTIR NOTEBOOKSExiste soluciones para compartir el misno notebooksentre diferentes personas, cada uno ejecuta su propiaversion, mientras que el original se mantiene intacto

Keywords: JupyterHub

Page 38: Introducción a jupyter (antes i python notebook)

SEGURIDADNo hemos visto nada, pero existe

Page 39: Introducción a jupyter (antes i python notebook)

¡GRACIAS A TODOS PORASISTIR!¿PREGUNTAS?