Jupyter Notebook es un modo muy fácil de empezar con data science y programar en Python, te permite correr código en diferentes órdenes y combinarlo con texto, gráficas e incluso algunos elementos web que pueden ser muy prácticos para presentar datos. De ahí que sea notebook.

Instalando Jupyter Notebook

No me voy a concentrar en cómo instalar Jupyter. Puedes instalarlo pendiante pip si ya tienes instalado Python o puedes utilizar Anaconda. Si necesitas instalar Python y estas en macOS puedes instalarlo utilizando brew. Recuerda instalar Python 3

Pandas y Jupyter estan incluidos con Anaconda. Anaconda es un paquete de varias herramietas de data science por lo cual para la mayoría de los usuarios va a ser la forma más fácil de instalar todo.

¿Qué podemos hacer con Jupyter y Pandas?

Hacer este artículo!

Si! Además de aquí en el blog, este artículo lo cree utilizando Jupyter Notebook. Puedes ver una versión de ella en NBviwer o GitHub (más sobre esas dos cosas adelante).

El resto del artículo esta escrito como si estuvieras leyendo esto en una libreta de Jupyter

Ser el backbone de Five Thirty Eight

Five Thirty Eight es el sitio de periodismo de datos, para algunos de los ejemplos este artículo tomé datos de su Github que utilizaron aquí.

Importar Datos

Para empezar pandas puede adquirir datos de básicamente cualquier lado. Se pueden introducir datos a mano, importar CSVs, leer datos estilo excel que hayas copiado, JSONs, HTMLs, hacer queries de SQL, o conectarse a Google BigQuery y más.

Vamos a empezar importando un CSV sencillo e imprimiendolo cómo tabla.

In [1]:
from IPython.display import display, GeoJSON
In [2]:
import pandas as pd # Por convención lo importamos como pd, porque escribir pandas cada dos lineas es demasiado

t = pd.read_csv('StarWars.csv')
t
Out[2]:
RespondentID Have you seen any of the 6 films in the Star Wars franchise? Do you consider yourself to be a fan of the Star Wars film franchise? Which of the following Star Wars films have you seen? Please select all that apply. Unnamed: 4 Unnamed: 5 Unnamed: 6 Unnamed: 7 Unnamed: 8 Please rank the Star Wars films in order of preference with 1 being your favorite film in the franchise and 6 being your least favorite film. ... Unnamed: 28 Which character shot first? Are you familiar with the Expanded Universe? Do you consider yourself to be a fan of the Expanded Universe?�� Do you consider yourself to be a fan of the Star Trek franchise? Gender Age Household Income Education Location (Census Region)
0 NaN Response Response Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi Star Wars: Episode I The Phantom Menace ... Yoda Response Response Response Response Response Response Response Response Response
1 3.292880e+09 Yes Yes Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 3 ... Very favorably I don't understand this question Yes No No Male 18-29 NaN High school degree South Atlantic
2 3.292880e+09 No NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN Yes Male 18-29 $0 - $24,999 Bachelor degree West South Central
3 3.292765e+09 Yes No Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith NaN NaN NaN 1 ... Unfamiliar (N/A) I don't understand this question No NaN No Male 18-29 $0 - $24,999 High school degree West North Central
4 3.292763e+09 Yes Yes Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 5 ... Very favorably I don't understand this question No NaN Yes Male 18-29 $100,000 - $149,999 Some college or Associate degree West North Central
5 3.292731e+09 Yes Yes Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 5 ... Somewhat favorably Greedo Yes No No Male 18-29 $100,000 - $149,999 Some college or Associate degree West North Central
6 3.292719e+09 Yes Yes Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 1 ... Very favorably Han Yes No Yes Male 18-29 $25,000 - $49,999 Bachelor degree Middle Atlantic
7 3.292685e+09 Yes Yes Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 6 ... Very favorably Han Yes No No Male 18-29 NaN High school degree East North Central
8 3.292664e+09 Yes Yes Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 4 ... Very favorably Han No NaN Yes Male 18-29 NaN High school degree South Atlantic
9 3.292654e+09 Yes Yes Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 5 ... Somewhat favorably Han No NaN No Male 18-29 $0 - $24,999 Some college or Associate degree South Atlantic
10 3.292640e+09 Yes No NaN Star Wars: Episode II Attack of the Clones NaN NaN NaN NaN 1 ... Very favorably I don't understand this question No NaN No Male 18-29 $25,000 - $49,999 Some college or Associate degree Pacific
11 3.292638e+09 Yes NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
12 3.292635e+09 No NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
13 3.292609e+09 Yes No Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 3 ... Very favorably Greedo No NaN No Male 18-29 $25,000 - $49,999 Bachelor degree South Atlantic
14 3.292597e+09 Yes Yes Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 4 ... Very favorably I don't understand this question No NaN No Male 30-44 $50,000 - $99,999 Graduate degree Mountain
15 3.292587e+09 Yes Yes Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 4 ... Very favorably Han No NaN No Male 18-29 NaN High school degree East North Central
16 3.292583e+09 Yes Yes Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 4 ... Somewhat favorably Han Yes Yes Yes Male 18-29 $0 - $24,999 Some college or Associate degree West South Central
17 3.292581e+09 Yes Yes NaN NaN NaN Star Wars: Episode IV A New Hope NaN NaN 4 ... Very unfavorably Han Yes Yes No Male 18-29 $50,000 - $99,999 Bachelor degree New England
18 3.292573e+09 Yes Yes Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith NaN NaN Star Wars: Episode VI Return of the Jedi 1 ... Very favorably Greedo No NaN No Male 18-29 NaN Some college or Associate degree Middle Atlantic
19 3.292565e+09 Yes Yes Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 6 ... Very favorably Han No NaN No Male 18-29 NaN High school degree South Atlantic
20 3.292562e+09 Yes Yes Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 6 ... Very favorably Greedo No NaN Yes Male 18-29 $50,000 - $99,999 Some college or Associate degree West North Central
21 3.292522e+09 Yes Yes Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 6 ... Very favorably Han No NaN No Male 18-29 NaN Some college or Associate degree Pacific
22 3.292521e+09 Yes No Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back NaN 3 ... Neither favorably nor unfavorably (neutral) I don't understand this question No NaN No Male 18-29 NaN Bachelor degree Pacific
23 3.292512e+09 Yes Yes Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 6 ... Very favorably Greedo Yes Yes Yes Male 18-29 $50,000 - $99,999 Bachelor degree South Atlantic
24 3.292483e+09 Yes Yes Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 6 ... Very favorably Han No NaN No Male 18-29 $0 - $24,999 Bachelor degree Pacific
25 3.292465e+09 Yes Yes Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 1 ... Very favorably Han No NaN No Male 18-29 NaN NaN East North Central
26 3.292448e+09 No NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN Yes Male 18-29 $0 - $24,999 High school degree East South Central
27 3.292420e+09 Yes Yes Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 4 ... Very favorably Greedo Yes No No Male 18-29 $100,000 - $149,999 Some college or Associate degree South Atlantic
28 3.292384e+09 Yes Yes Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 6 ... Very favorably Greedo No NaN No Male 18-29 NaN Some college or Associate degree Middle Atlantic
29 3.292380e+09 Yes Yes Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 6 ... Very favorably Han Yes No No Male 18-29 NaN Some college or Associate degree Middle Atlantic
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
1157 3.288426e+09 Yes No Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 3 ... Very favorably I don't understand this question No NaN No Female 30-44 $50,000 - $99,999 Graduate degree Middle Atlantic
1158 3.288423e+09 No NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN No Male 45-60 $100,000 - $149,999 Graduate degree Middle Atlantic
1159 3.288423e+09 Yes No NaN NaN NaN NaN Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 2 ... Very favorably I don't understand this question No NaN No Female 45-60 $0 - $24,999 Bachelor degree Pacific
1160 3.288422e+09 No NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN No Female > 60 $0 - $24,999 Some college or Associate degree West South Central
1161 3.288421e+09 Yes No Star Wars: Episode I The Phantom Menace NaN Star Wars: Episode III Revenge of the Sith NaN NaN Star Wars: Episode VI Return of the Jedi 3 ... Very favorably I don't understand this question No NaN No Female 18-29 $25,000 - $49,999 Some college or Associate degree Pacific
1162 3.288418e+09 Yes No Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith NaN Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 3 ... Neither favorably nor unfavorably (neutral) Greedo No NaN No NaN NaN NaN NaN NaN
1163 3.288418e+09 Yes Yes Star Wars: Episode I The Phantom Menace NaN NaN Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 4 ... Very favorably I don't understand this question No NaN No Female 18-29 $25,000 - $49,999 Graduate degree South Atlantic
1164 3.288417e+09 Yes No NaN NaN NaN Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 5 ... Very favorably Han Yes No No Female > 60 NaN Bachelor degree New England
1165 3.288415e+09 Yes No Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith NaN Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 5 ... Neither favorably nor unfavorably (neutral) Han No NaN No Male 45-60 $100,000 - $149,999 Graduate degree Middle Atlantic
1166 3.288414e+09 Yes Yes Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 5 ... Very favorably Greedo No NaN Yes Female 30-44 $50,000 - $99,999 Bachelor degree Mountain
1167 3.288413e+09 Yes Yes Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 6 ... Very favorably I don't understand this question No NaN No Female 18-29 $150,000+ Some college or Associate degree South Atlantic
1168 3.288410e+09 Yes No Star Wars: Episode I The Phantom Menace NaN NaN NaN Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 3 ... Very favorably Greedo Yes No No Female 30-44 NaN Graduate degree East North Central
1169 3.288410e+09 No NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN No Female 30-44 $150,000+ Graduate degree East North Central
1170 3.288409e+09 Yes Yes Star Wars: Episode I The Phantom Menace NaN NaN Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 4 ... Very favorably Han No NaN Yes Male 45-60 $25,000 - $49,999 Bachelor degree South Atlantic
1171 3.288403e+09 No NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN No Female 45-60 NaN Graduate degree East North Central
1172 3.288403e+09 Yes Yes Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 6 ... Somewhat unfavorably Han Yes Yes Yes Female > 60 $25,000 - $49,999 Bachelor degree Mountain
1173 3.288403e+09 Yes Yes NaN NaN NaN Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 2 ... Somewhat favorably Greedo Yes No Yes Female > 60 NaN High school degree Pacific
1174 3.288403e+09 Yes Yes Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 5 ... Very favorably Han No NaN Yes Female 30-44 NaN Bachelor degree Middle Atlantic
1175 3.288402e+09 Yes No Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith NaN NaN NaN 1 ... Very favorably I don't understand this question No NaN Yes Female > 60 NaN Some college or Associate degree West North Central
1176 3.288401e+09 Yes Yes Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 1 ... Somewhat favorably Han Yes No Yes Female 45-60 $50,000 - $99,999 Graduate degree West South Central
1177 3.288398e+09 Yes No Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones NaN NaN NaN NaN 2 ... Neither favorably nor unfavorably (neutral) I don't understand this question No NaN No Female 45-60 $0 - $24,999 High school degree Middle Atlantic
1178 3.288396e+09 Yes No Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith NaN Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 1 ... Very favorably I don't understand this question No NaN Yes Male > 60 $50,000 - $99,999 Some college or Associate degree Pacific
1179 3.288395e+09 No NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN No Female 18-29 NaN Less than high school degree West North Central
1180 3.288392e+09 Yes Yes NaN NaN NaN NaN Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 3 ... Very favorably Han No NaN Yes Female 45-60 $0 - $24,999 Some college or Associate degree West North Central
1181 3.288390e+09 Yes Yes Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 3 ... Very favorably Han No NaN No Female 45-60 $0 - $24,999 Some college or Associate degree Pacific
1182 3.288389e+09 Yes Yes Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 5 ... Very favorably Han No NaN Yes Female 18-29 $0 - $24,999 Some college or Associate degree East North Central
1183 3.288379e+09 Yes Yes Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 4 ... Very favorably I don't understand this question No NaN Yes Female 30-44 $50,000 - $99,999 Bachelor degree Mountain
1184 3.288375e+09 No NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN No Female 30-44 $50,000 - $99,999 Bachelor degree Middle Atlantic
1185 3.288373e+09 Yes Yes Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones Star Wars: Episode III Revenge of the Sith Star Wars: Episode IV A New Hope Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 4 ... Very favorably Han No NaN Yes Female 45-60 $100,000 - $149,999 Some college or Associate degree East North Central
1186 3.288373e+09 Yes No Star Wars: Episode I The Phantom Menace Star Wars: Episode II Attack of the Clones NaN NaN Star Wars: Episode V The Empire Strikes Back Star Wars: Episode VI Return of the Jedi 6 ... Very unfavorably I don't understand this question No NaN No Female > 60 $50,000 - $99,999 Graduate degree Pacific

1187 rows × 38 columns

Para empezar la tabla quedó formateada automáticamente. Podemos hacer algunas estadisticas sencillas como

In [3]:
# De las 1187 personas encuestadas ¿Cuantas han visto alguna película de Star Wars?

t['Have you seen any of the 6 films in the Star Wars franchise?'].value_counts()
Out[3]:
Yes         936
No          250
Response      1
Name: Have you seen any of the 6 films in the Star Wars franchise?, dtype: int64

O podemos saber muy fácilmente cual, segun nuestros datos, es la pelicula más vista de Star Wars es Empire Strikes Back

In [4]:
watched = t.iloc[:, 3:9].describe().transpose()
watched
Out[4]:
count unique top freq
Which of the following Star Wars films have you seen? Please select all that apply. 674 1 Star Wars: Episode I The Phantom Menace 674
Unnamed: 4 572 1 Star Wars: Episode II Attack of the Clones 572
Unnamed: 5 551 1 Star Wars: Episode III Revenge of the Sith 551
Unnamed: 6 608 1 Star Wars: Episode IV A New Hope 608
Unnamed: 7 759 1 Star Wars: Episode V The Empire Strikes Back 759
Unnamed: 8 739 1 Star Wars: Episode VI Return of the Jedi 739

Hacer Gráficas

In [5]:
from bokeh.plotting import figure, output_notebook, show
from bokeh.models import ColumnDataSource,LabelSet
output_notebook()


source = ColumnDataSource(data=dict(y=watched["top"],
                                    right=watched["freq"],
                                    freq=watched["freq"]))

labels = LabelSet(x='right', y='y', text='freq', level='glyph',
              x_offset=2, y_offset=5, source=source, render_mode='canvas')

p = figure(plot_width=850, y_range=watched['top'])

p.hbar(y="y", right="right", height=0.5, source=source)
p.add_layout(labels)
show(p)
Loading BokehJS ...

Mostrar mapas

Solo tienes que activar este complemento de Jupyter.

jupyter labextension install @jupyterlab/geojson-extension

Después de agregarlo solo tienes que importar el display de GeoJSON y tus mapas se mostrarán automáticamente

In [6]:
from IPython.display import GeoJSON
GeoJSON({"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[-98.20627212524414,19.048082808795396]}},{"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[-98.20215225219725,19.054978803148376]}},{"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[-98.21605682373047,19.061793386528766]}},{"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[-98.22275161743164,19.05359962720829]}},{"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[-98.23159217834473,19.0492997698019]}},{"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[-98.23433876037598,19.046703575532554]}},{"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[-98.21288108825684,19.03639952912028]}},{"type":"Feature","properties":{"stroke":"#00fcff","stroke-width":2,"stroke-opacity":1,"fill":"#00fcff","fill-opacity":0.5},"geometry":{"type":"Polygon","coordinates":[[[-98.23416709899902,19.04662244380717],[-98.21296691894531,19.03672407576917],[-98.20635795593262,19.048407332603105],[-98.20206642150879,19.055141058387473],[-98.21648597717285,19.062523503853996],[-98.22223663330077,19.053761883796376],[-98.23142051696776,19.0492997698019],[-98.23416709899902,19.04662244380717]]]}}]})
<IPython.display.GeoJSON object>

Escribir con Latex dentro de Jupyter Notebook

O más bien escribir equaciones empleando la notación de Latex. Esto es muy útil para data science, pues porque matemáticas, puedes ver un ejemplo en el artículo de Arkham.

$$ \int_y^x f(t) dt = x f(x) - y f(y) - \int_y^x t f'(t) dt $$

Presentaciones con Jupyter

Puedes hasta hacer tus presentaciones con Jupyter y si se trata de código hacerlas con Jupyter tiene mucho sentido. De hecho, esta libreta también es una presentación y la puedes ver en modo de presentación aquí.

Considera las ventajas de hacer las cosas solo una vez y tener inmediatamente una presentación de tu trabajo. Sobre todo si estas haciendo data science, dónde la parte gráfica es muy importante, hacer esto es un ahorro impresionante de tiempo y energía.

Compartir tus libretas en linea con NBViwer & GitHub

Esta parte es de mis favoritas, de hecho es algo que he utilizado en varios trabajos para compartir información. Al subir tu libreta a Github será rendereada automáticamente, como aquí y puedes poner ese link en nbviwer que es una interfáz más limpia y te permite ver las libretas en modo de presentación, como aquí.

Para que algunas cosas específicas se vean correctamente en linea, por ejemplo los mapas, seguramente necesitas agregar algunas lineas de Javascript. Pero no es nada complicado, en ese caso te recomiendo utilizar nbviewer porque github no siempre te va a permitir renderear algunos de esos elementos.

¡Y utilizar otros lenguajes!

Jupyter no solo soporta Python. Si estas intersado en data science posiblemente quieras utilizar R y lo puedes hacer con Jupyter. Pero también puedes utilizar Julia, Scala, Haskell, Ruby, Bash.... y muchos otros.

El artículo de Arkham también lo hice inicialmente utilizando Jupyter y estas son ejemplos delibretas utilizando Ruby y Julia.

Espero que esta introducción a Jupyter te sea útil. Y como siempre puedes dejar tus comentarios.